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.0.0-rc.17 to 3.0.0-rc.18

2

dist/index.modern.js

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

function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},e.apply(this,arguments)}var t;!function(e){e[e.Trace=0]="Trace",e[e.Debug=1]="Debug",e[e.Information=2]="Information",e[e.Warning=3]="Warning",e[e.Error=4]="Error",e[e.Critical=5]="Critical",e[e.None=6]="None"}(t||(t={}));var r={__proto__:null,get LogLevel(){return t}};class o{constructor(){this.start=void 0,this.end=void 0,this.start=Date.now()}stop(){this.end=Date.now()}get elapsed(){return(this.end||Date.now())-this.start}}class n{static convert(e){const t=JSON.stringify(e);return btoa(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}}class a{static create(){const e=[48,32,24,16,15,8,4,1].find(e=>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"}}}class i{constructor(e){this._task=void 0,this._timeout=void 0,this._task=new Promise(t=>{this._timeout=setTimeout(t,e)})}wait(){return this._task}cancel(){clearTimeout(this._timeout),this._task=Promise.reject({message:"Timer cancelled"})}static sleep(e){return new i(e)}static cancel(e){clearTimeout(e)}}class s{static createIFrame(e){const 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}static createForm(e){const 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}static createInput(e){const t=document.createElement("input");return t.id=e.name,t.name=e.name,t.type=e.type,e.parent.appendChild(t),t}}var l={__proto__:null,Base64Converter:n,Browser:a,Delay:i,HtmlElementFactory:s,Abstractions:{__proto__:null}};class c{constructor(e,t){this._options=void 0,this._logger=void 0,this._options=e,this._logger=t}execute({executeFn:e,method:r,correlationId:o}){var n=this;return new Promise(async function(a,s){var l;let c=1,h=null;do{try{let t=await e({attempt:c,maxAttempts:n._options.maxAttempts});if(t.isSuccess)return void a(t);if(!t.isTransientError)return void s(t)}catch(e){h={message:`Unhandled error calling "${r}"`,error:e,additionalData:{attempt:c,maxAttempts:n._options.maxAttempts}},n._logger.log({message:`Unhandled error calling "${r}"`,error:e,content:{attempt:c,maxAttempts:n._options.maxAttempts},method:r,correlationId:o,level:t.Warning})}c++,await i.sleep(n._options.attemptDelay).wait()}while(c<=n._options.maxAttempts);s(h),n._logger.log({message:`Unhandled error calling "${r}"`,error:null==(l=h)?void 0:l.error,content:{attempt:c,maxAttempts:n._options.maxAttempts},method:r,correlationId:o,level:t.Error})})}}class h{constructor(e,t,r=new c(e,t)){this._options=void 0,this._retryPolicy=void 0,this._logger=void 0,this._retryPolicy=r,this._logger=t,this._options=e}async send(r){var n=this;const a=this;return await this._retryPolicy.execute({executeFn:async function({attempt:i,maxAttempts:s}){const l=1e3*(a._options.timeoutInSeconds||30),c=new AbortController,h=setTimeout(()=>c.abort(),l),d=new URL(r.url);n._logger.log({message:`ExternalService - Request (${d.host})`,content:{request:r,attempt:i,maxAttempts:s},method:"send",correlationId:r.correlationId,level:t.Information});const g=new o;let m;try{m=await fetch(r.url,{headers:e({},r.headers,{"x-attempt":i.toString(),"x-max-attempts":s.toString(),accept:"application/json","content-type":"application/json",correlationId:r.correlationId}),keepalive:!0,body:JSON.stringify(r.body),method:r.method,signal:c.signal}),n._logger.log({message:`ExternalService - Response (${d.host}) in ${g.elapsed}ms`,content:{request:r,attempt:i,maxAttempts:s,response:m},method:"send",correlationId:r.correlationId,level:t.Error})}catch(e){throw n._logger.log({message:`ExternalService - Error (${d.host}) in ${g.elapsed}ms`,content:{request:r,attempt:i,maxAttempts:s,error:e},method:"send",correlationId:r.correlationId,level:t.Error}),e}return clearTimeout(h),{isSuccess:m.ok,isTransientError:n.isTransientError(m),getData:async function(){return(await m.json()).data}}},method:`[${r.method}] ${r.url}`,correlationId:r.correlationId})}isTransientError(e){return[409,424,500,503,504].includes(e.status)}}var d={__proto__:null,FetchHttpClient:h,Abstractions:{__proto__:null}};class g{flush(){return Promise.resolve()}log(t){var r;const o=e({},t,{error:null==(r=t.error)?void 0:r.toString()});console.log(o)}}class m{constructor(e,t=new g,r=new h(e,t,new c({maxAttempts:3,attemptDelay:5e3},t))){this._httpClient=void 0,this._logger=void 0,this._options=void 0,this._logs=[],this._interval=void 0,this._logger=t,this._options=e,this._httpClient=r,this._interval=setInterval(this.sendBatch.bind(this),1e3*(this._options.batchLogIntervalInSeconds||m.DEFAULT_BATCH_TIMEOUT))}log(t){var r;this._logger.log(t),this._options.restLoggerUrl&&this._logs.unshift({customMessage:t.message,message:`[Paybyrd.ThreeDSecure.JS] ${t.message}`,service:{name:"Paybyrd.ThreeDSecure.JS",version:"3.0.0"},environment:this._options.environment||"Development",executionDate:new Date,entrypoint:"Execute",method:t.method,correlationId:t.correlationId,content:e({},t.content,{error:null==(r=t.error)?void 0:r.toString()}),level:t.level})}async flush(){for(clearInterval(this._interval);this._logs.length;)await this.sendBatch();this._interval=setInterval(this.sendBatch.bind(this),1e3*(this._options.batchLogIntervalInSeconds||m.DEFAULT_BATCH_TIMEOUT))}async sendBatch(){const e=this._logs.splice(0,10);if(!e.length)return;const r=e.map(e=>e.correlationId)[0];try{await this._httpClient.send({url:this._options.restLoggerUrl,method:"POST",body:e,correlationId:r})}catch(e){this._logger.log({error:e,message:"Error sending message to elastic",method:"sendBatch",correlationId:r,level:t.Error})}}}m.DEFAULT_BATCH_TIMEOUT=5;var u,p={__proto__:null,ConsoleLogger:g,RestLogger:m,Abstractions:r};!function(e){e.width250xheight400="01",e.width390xheight400="02",e.width500xheight600="03",e.width600xheight400="04",e.fullscreen="05"}(u||(u={}));var _={__proto__:null,get ChallengeWindowSize(){return u}};class v{constructor(e,t){this._options=void 0,this._logger=void 0,this._options=e,this._logger=t}execute(e){return e.authResponse.challengeUrl?new Promise((r,a)=>{try{this._logger.log({message:"Challenge - Start",content:{authResponse:e.authResponse},method:"executeChallenge",correlationId:e.correlationId,level:t.Information}),this._options.container.innerHTML="";const a=s.createIFrame({parent:this._options.container,name:v.IFRAME_NAME,isVisible:!0,useDefaultStyle:!!this._options.onIFrameCreatedFn,onCreatedFn:this._options.onIFrameCreatedFn,onReadyFn:this._options.onIFrameReadyFn});this._logger.log({message:"Challenge - Create iFrame",method:"executeChallenge",correlationId:e.correlationId,level:t.Information});const i=s.createForm({parent:this._options.container,name:v.FORM_NAME,actionUrl:e.authResponse.challengeUrl,target:v.IFRAME_NAME,method:"post"});this._logger.log({message:"Challenge - Create form",method:"executeChallenge",correlationId:e.correlationId,level:t.Information});const l=s.createInput({parent:i,name:v.CREQ_INPUT_NAME,type:v.CREQ_INPUT_TYPE});this._logger.log({message:"Challenge - Create input",method:"executeChallenge",correlationId:e.correlationId,level:t.Information});const c={threeDSServerTransID:e.authResponse.processId,acsTransID:e.authResponse.challengeId,messageVersion:e.authResponse.challengeVersion,messageType:"CReq",challengeWindowSize:this._options.challengeWindowSize||u.width250xheight400},h=n.convert(c);l.value=h,this._logger.log({message:"Challenge - Prepare cReq",content:{cReq:c,base64CReq:h},method:"executeChallenge",correlationId:e.correlationId,level:t.Information});const d=new o,g=()=>{var r;const o=a.contentDocument||(null==(r=a.contentWindow)?void 0:r.document);"complete"!=(null==o?void 0:o.readyState)?setTimeout(g,100):this._logger.log({message:`Challenge - iFrame loaded in ${d.elapsed}ms`,content:{iFrame:o.body.innerText},method:"executeChallenge",correlationId:e.correlationId,level:t.Information})};i.submit(),setTimeout(g,100),this._logger.log({message:"Challenge - Submit form",content:{authResponse:e.authResponse,cReq:c,base64CReq:h},method:"executeChallenge",correlationId:e.correlationId,level:t.Information}),r()}catch(r){return this._logger.log({message:"Challenge - error",content:{authResponse:e.authResponse},error:r,method:"executeChallenge",correlationId:e.correlationId,level:t.Error}),a({message:r.toString()})}}):Promise.resolve()}}v.IFRAME_NAME="challengeIframe",v.FORM_NAME="challengeForm",v.CREQ_INPUT_NAME="creq",v.CREQ_INPUT_TYPE="hidden";class I{constructor(e,t){this._logger=void 0,this._options=void 0,this._logger=t,this._options=e}execute(e){return e.preAuthResponse.dsMethodUrl?new Promise((r,a)=>{try{var i;this._logger.log({message:"DirectoryServer - Start",content:{preAuthResponse:e},method:"executeDirectoryServer",correlationId:e.correlationId,level:t.Information}),this._options.container.innerHTML="";const a=s.createIFrame({parent:this._options.container,isVisible:!1,name:I.IFRAME_NAME,useDefaultStyle:!!this._options.onIFrameCreatedFn});null==(i=this._options.onIFrameCreatedFn)||i.call(this._options,a),this._logger.log({message:"DirectoryServer - Create iFrame",method:"executeDirectoryServer",correlationId:e.correlationId,level:t.Information});const l=s.createForm({parent:this._options.container,name:I.FORM_NAME,actionUrl:e.preAuthResponse.dsMethodUrl,target:I.IFRAME_NAME,method:"POST"});this._logger.log({message:"DirectoryServer - Create Form",method:"executeDirectoryServer",correlationId:e.correlationId,level:t.Information});const c=s.createInput({parent:l,name:I.FORM_INPUT_NAME,type:I.FROM_INPUT_TYPE});this._logger.log({message:"DirectoryServer - Create Input",method:"executeDirectoryServer",correlationId:e.correlationId,level:t.Information});const h={threeDSServerTransID:e.preAuthResponse.processId,threeDSMethodNotificationURL:e.preAuthResponse.notificationUrl},d=n.convert(h);c.value=d,this._logger.log({message:"DirectoryServer - Prepare threeDSMethodData",content:{threeDSMethodData:h,threeDSMethodDataBase64:d},method:"executeDirectoryServer",correlationId:e.correlationId,level:t.Information});const g=new o,m=()=>{var r;const o=a.contentDocument||(null==(r=a.contentWindow)?void 0:r.document);"complete"!=(null==o?void 0:o.readyState)?setTimeout(m,100):this._logger.log({message:`DirectoryServer - iFrame loaded in ${g.elapsed}ms`,content:{iFrame:o.body.innerText},method:"executeDirectoryServer",correlationId:e.correlationId,level:t.Information})};l.submit(),setTimeout(m,100),this._logger.log({message:"DirectoryServer - Submit form",content:{threeDSMethodData:h,threeDSMethodDataBase64:d},method:"executeDirectoryServer",correlationId:e.correlationId,level:t.Information}),r()}catch(r){return this._logger.log({message:"DirectoryServer - Error",content:{preAuthResponse:e},error:r,method:"directoryServerExecute",correlationId:e.correlationId,level:t.Error}),a({message:r.toString()})}}):Promise.resolve()}}I.IFRAME_NAME="threeDSMethodIframe",I.FORM_NAME="threeDSMethodForm",I.FORM_INPUT_NAME="threeDSMethodData",I.FROM_INPUT_TYPE="hidden";class y{constructor(e,t=new m(e),r=new h(e,t),o=new I(e,t),n=new v(e,t)){this._options=void 0,this._logger=void 0,this._client=void 0,this._directoryServer=void 0,this._challenge=void 0,this._options=e,this._logger=t,this._client=r,this._directoryServer=o,this._challenge=n}async execute(e){e.correlationId||(e.correlationId=crypto.randomUUID());let t=await this.preAuth(e);await this._directoryServer.execute({preAuthResponse:t,correlationId:e.correlationId});let r=await this.auth(e);await this._challenge.execute({authResponse:r,correlationId:e.correlationId});let o=await this.postAuth(e);return await this._logger.flush(),o}async preAuth(e){this._logger.log({message:"Executing PreAuth",content:e,method:"_preAuth",correlationId:e.correlationId,level:t.Information});const r=await this._client.send({url:`${this._options.threeDSecureUrl}/api/v2/${e.id}/preAuth`,method:"POST",body:{browser:a.create()},correlationId:e.correlationId});return await r.getData()}async auth(e){this._logger.log({message:"Executing Auth",content:e,method:"_auth",correlationId:e.correlationId,level:t.Information});const r=await this._client.send({url:`${this._options.threeDSecureUrl}/api/v1/${e.id}/auth`,method:"POST",correlationId:e.correlationId});return await r.getData()}async postAuth(e){this._logger.log({message:"Executing PostAuth",content:e,method:"_postAuth",correlationId:e.correlationId,level:t.Information});const r=await this._client.send({url:`${this._options.threeDSecureUrl}/api/v2/${e.id}/postAuth`,method:"POST",correlationId:e.correlationId});return await r.getData()}}var S={__proto__:null,IFrameDirectoryServerService:I,IFrameChallengeService:v,ThreeDSecureService:y,Abstractions:_},D={__proto__:null,Abstractions:{__proto__:null},Utils:l};export{d as HttpClients,p as Loggers,S as Services,D as Shared,y as ThreeDSecureService};
function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},e.apply(this,arguments)}var t;!function(e){e[e.Trace=0]="Trace",e[e.Debug=1]="Debug",e[e.Information=2]="Information",e[e.Warning=3]="Warning",e[e.Error=4]="Error",e[e.Critical=5]="Critical",e[e.None=6]="None"}(t||(t={}));var o={__proto__:null,get LogLevel(){return t}};class r{constructor(){this.start=void 0,this.end=void 0,this.start=Date.now()}stop(){this.end=Date.now()}get elapsed(){return(this.end||Date.now())-this.start}}class n{static convert(e){const t=JSON.stringify(e);return btoa(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}}class a{static create(){const e=[48,32,24,16,15,8,4,1].find(e=>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"}}}class i{constructor(e){this._task=void 0,this._timeout=void 0,this._task=new Promise(t=>{this._timeout=setTimeout(t,e)})}wait(){return this._task}cancel(){clearTimeout(this._timeout),this._task=Promise.reject({message:"Timer cancelled"})}static sleep(e){return new i(e)}static cancel(e){clearTimeout(e)}}class s{static createIFrame(e){const 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}static createForm(e){const 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}static createInput(e){const t=document.createElement("input");return t.id=e.name,t.name=e.name,t.type=e.type,e.parent.appendChild(t),t}}var l={__proto__:null,Base64Converter:n,Browser:a,Delay:i,HtmlElementFactory:s,Abstractions:{__proto__:null}};class c{constructor(e,t){this._options=void 0,this._logger=void 0,this._options=e,this._logger=t}execute({executeFn:e,method:o,correlationId:r}){var n=this;return new Promise(async function(a,s){var l;let c=1,h=null;do{try{let t=await e({attempt:c,maxAttempts:n._options.maxAttempts});if(t.isSuccess)return void a(t);if(!t.isTransientError)return void s(t)}catch(e){h={message:`Unhandled error calling "${o}"`,error:e,additionalData:{attempt:c,maxAttempts:n._options.maxAttempts}},n._logger.log({message:`Unhandled error calling "${o}"`,error:e,content:{attempt:c,maxAttempts:n._options.maxAttempts},method:o,correlationId:r,level:t.Warning})}c++,await i.sleep(n._options.attemptDelay).wait()}while(c<=n._options.maxAttempts);s(h),n._logger.log({message:`Unhandled error calling "${o}"`,error:null==(l=h)?void 0:l.error,content:{attempt:c,maxAttempts:n._options.maxAttempts},method:o,correlationId:r,level:t.Error})})}}class h{constructor(e,t,o=new c(e,t)){this._options=void 0,this._retryPolicy=void 0,this._logger=void 0,this._retryPolicy=o,this._logger=t,this._options=e}async send(o){var n=this;const a=this;return await this._retryPolicy.execute({executeFn:async function({attempt:i,maxAttempts:s}){const l=1e3*(a._options.timeoutInSeconds||30),c=new AbortController,h=setTimeout(()=>c.abort(),l),d=new URL(o.url);n._logger.log({message:`ExternalService - Request (${d.host})`,content:{request:o,attempt:i,maxAttempts:s},method:"send",correlationId:o.correlationId,level:t.Information});const g=new r;let m;try{m=await fetch(o.url,{headers:e({},o.headers,{"x-attempt":i.toString(),"x-max-attempts":s.toString(),accept:"application/json","content-type":"application/json",correlationId:o.correlationId}),keepalive:!0,body:JSON.stringify(o.body),method:o.method,signal:c.signal}),n._logger.log({message:`ExternalService - Response (${d.host}) in ${g.elapsed}ms`,content:{request:o,attempt:i,maxAttempts:s,response:m},method:"send",correlationId:o.correlationId,level:t.Error})}catch(e){throw n._logger.log({message:`ExternalService - Error (${d.host}) in ${g.elapsed}ms`,content:{request:o,attempt:i,maxAttempts:s,error:e},method:"send",correlationId:o.correlationId,level:t.Error}),e}return clearTimeout(h),{isSuccess:m.ok,isTransientError:n.isTransientError(m),getData:async function(){return(await m.json()).data}}},method:`[${o.method}] ${o.url}`,correlationId:o.correlationId})}isTransientError(e){return[409,424,500,503,504].includes(e.status)}}var d={__proto__:null,FetchHttpClient:h,Abstractions:{__proto__:null}};class g{flush(){return Promise.resolve()}log(t){var o;const r=e({},t,{error:null==(o=t.error)?void 0:o.toString()});console.log(r)}}class m{constructor(e,t=new g,o=new h(e,t,new c({maxAttempts:3,attemptDelay:5e3},t))){this._httpClient=void 0,this._logger=void 0,this._options=void 0,this._logs=[],this._interval=void 0,this._logger=t,this._options=e,this._httpClient=o,this._interval=setInterval(this.sendBatch.bind(this),1e3*(this._options.batchLogIntervalInSeconds||m.DEFAULT_BATCH_TIMEOUT))}log(t){var o;this._logger.log(t),this._options.restLoggerUrl&&this._logs.unshift({customMessage:t.message,message:`[Paybyrd.ThreeDSecure.JS] ${t.message}`,service:{name:"Paybyrd.ThreeDSecure.JS",version:"3.0.0"},environment:this._options.environment||"Development",executionDate:new Date,entrypoint:"Execute",method:t.method,correlationId:t.correlationId,content:e({},t.content,{error:null==(o=t.error)?void 0:o.toString()}),level:t.level})}async flush(){for(clearInterval(this._interval);this._logs.length;)await this.sendBatch();this._interval=setInterval(this.sendBatch.bind(this),1e3*(this._options.batchLogIntervalInSeconds||m.DEFAULT_BATCH_TIMEOUT))}async sendBatch(){const e=this._logs.splice(0,10);if(!e.length)return;const o=e.map(e=>e.correlationId)[0];try{await this._httpClient.send({url:this._options.restLoggerUrl,method:"POST",body:e,correlationId:o})}catch(e){this._logger.log({error:e,message:"Error sending message to elastic",method:"sendBatch",correlationId:o,level:t.Error})}}}m.DEFAULT_BATCH_TIMEOUT=5;var u,p={__proto__:null,ConsoleLogger:g,RestLogger:m,Abstractions:o};!function(e){e.width250xheight400="01",e.width390xheight400="02",e.width500xheight600="03",e.width600xheight400="04",e.fullscreen="05"}(u||(u={}));var _={__proto__:null,get ChallengeWindowSize(){return u}};class v{constructor(e,t){this._options=void 0,this._logger=void 0,this._options=e,this._logger=t}execute(e){return e.authResponse.challengeUrl?new Promise((o,a)=>{try{this._logger.log({message:"Challenge - Start",content:{authResponse:e.authResponse},method:"executeChallenge",correlationId:e.correlationId,level:t.Information}),this._options.container.innerHTML="";const a=s.createIFrame({parent:this._options.container,name:v.IFRAME_NAME,isVisible:!0,useDefaultStyle:!!this._options.onIFrameCreatedFn,onCreatedFn:this._options.onIFrameCreatedFn,onReadyFn:this._options.onIFrameReadyFn});this._logger.log({message:"Challenge - Create iFrame",method:"executeChallenge",correlationId:e.correlationId,level:t.Information});const i=s.createForm({parent:this._options.container,name:v.FORM_NAME,actionUrl:e.authResponse.challengeUrl,target:v.IFRAME_NAME,method:"post"});this._logger.log({message:"Challenge - Create form",method:"executeChallenge",correlationId:e.correlationId,level:t.Information});const l=s.createInput({parent:i,name:v.CREQ_INPUT_NAME,type:v.CREQ_INPUT_TYPE});this._logger.log({message:"Challenge - Create input",method:"executeChallenge",correlationId:e.correlationId,level:t.Information});const c={threeDSServerTransID:e.authResponse.processId,acsTransID:e.authResponse.challengeId,messageVersion:e.authResponse.challengeVersion,messageType:"CReq",challengeWindowSize:this._options.challengeWindowSize||u.width250xheight400},h=n.convert(c);l.value=h,this._logger.log({message:"Challenge - Prepare cReq",content:{cReq:c,base64CReq:h},method:"executeChallenge",correlationId:e.correlationId,level:t.Information});const d=new r,g=()=>{var o;const r=a.contentDocument||(null==(o=a.contentWindow)?void 0:o.document);"complete"!=(null==r?void 0:r.readyState)?setTimeout(g,100):this._logger.log({message:`Challenge - iFrame loaded in ${d.elapsed}ms`,content:{iFrame:r.body.innerText},method:"executeChallenge",correlationId:e.correlationId,level:t.Information})};i.submit(),setTimeout(g,100),this._logger.log({message:"Challenge - Submit form",content:{authResponse:e.authResponse,cReq:c,base64CReq:h},method:"executeChallenge",correlationId:e.correlationId,level:t.Information}),o()}catch(o){return this._logger.log({message:"Challenge - error",content:{authResponse:e.authResponse},error:o,method:"executeChallenge",correlationId:e.correlationId,level:t.Error}),a({message:o.toString()})}}):Promise.resolve()}}v.IFRAME_NAME="challengeIframe",v.FORM_NAME="challengeForm",v.CREQ_INPUT_NAME="creq",v.CREQ_INPUT_TYPE="hidden";class I{constructor(e,t){this._logger=void 0,this._options=void 0,this._logger=t,this._options=e}execute(e){return e.preAuthResponse.dsMethodUrl?new Promise((o,a)=>{try{var i;this._logger.log({message:"DirectoryServer - Start",content:{preAuthResponse:e},method:"executeDirectoryServer",correlationId:e.correlationId,level:t.Information}),this._options.container.innerHTML="";const a=s.createIFrame({parent:this._options.container,isVisible:!1,name:I.IFRAME_NAME,useDefaultStyle:!!this._options.onIFrameCreatedFn});null==(i=this._options.onIFrameCreatedFn)||i.call(this._options,a),this._logger.log({message:"DirectoryServer - Create iFrame",method:"executeDirectoryServer",correlationId:e.correlationId,level:t.Information});const l=s.createForm({parent:this._options.container,name:I.FORM_NAME,actionUrl:e.preAuthResponse.dsMethodUrl,target:I.IFRAME_NAME,method:"POST"});this._logger.log({message:"DirectoryServer - Create Form",method:"executeDirectoryServer",correlationId:e.correlationId,level:t.Information});const c=s.createInput({parent:l,name:I.FORM_INPUT_NAME,type:I.FROM_INPUT_TYPE});this._logger.log({message:"DirectoryServer - Create Input",method:"executeDirectoryServer",correlationId:e.correlationId,level:t.Information});const h={threeDSServerTransID:e.preAuthResponse.processId,threeDSMethodNotificationURL:e.preAuthResponse.notificationUrl},d=n.convert(h);c.value=d,this._logger.log({message:"DirectoryServer - Prepare threeDSMethodData",content:{threeDSMethodData:h,threeDSMethodDataBase64:d},method:"executeDirectoryServer",correlationId:e.correlationId,level:t.Information});const g=new r,m=()=>{var o;const r=a.contentDocument||(null==(o=a.contentWindow)?void 0:o.document);"complete"!=(null==r?void 0:r.readyState)?setTimeout(m,100):this._logger.log({message:`DirectoryServer - iFrame loaded in ${g.elapsed}ms`,content:{iFrame:r.body.innerText},method:"executeDirectoryServer",correlationId:e.correlationId,level:t.Information})};l.submit(),setTimeout(m,100),this._logger.log({message:"DirectoryServer - Submit form",content:{threeDSMethodData:h,threeDSMethodDataBase64:d},method:"executeDirectoryServer",correlationId:e.correlationId,level:t.Information}),o()}catch(o){return this._logger.log({message:"DirectoryServer - Error",content:{preAuthResponse:e},error:o,method:"directoryServerExecute",correlationId:e.correlationId,level:t.Error}),a({message:o.toString()})}}):Promise.resolve()}}I.IFRAME_NAME="threeDSMethodIframe",I.FORM_NAME="threeDSMethodForm",I.FORM_INPUT_NAME="threeDSMethodData",I.FROM_INPUT_TYPE="hidden";class y{constructor(e,t=new m(e),o=new h(e,t),r=new I(e,t),n=new v(e,t)){this._options=void 0,this._logger=void 0,this._client=void 0,this._directoryServer=void 0,this._challenge=void 0,this._options=e,this._logger=t,this._client=o,this._directoryServer=r,this._challenge=n}async execute(e,o=crypto.randomUUID()){e.correlationId||(e.correlationId=o,this._logger.log({message:"Obsolete request. CorrelationId is not set.",content:e,method:"execute",correlationId:e.correlationId,level:t.Information}));let r=await this.preAuth(e);await this._directoryServer.execute({preAuthResponse:r,correlationId:e.correlationId});let n=await this.auth(e);await this._challenge.execute({authResponse:n,correlationId:e.correlationId});let a=await this.postAuth(e);return await this._logger.flush(),a}async preAuth(e){this._logger.log({message:"Executing PreAuth",content:e,method:"_preAuth",correlationId:e.correlationId,level:t.Information});const o=await this._client.send({url:`${this._options.threeDSecureUrl}/api/v2/${e.id}/preAuth`,method:"POST",body:{browser:a.create()},correlationId:e.correlationId});return await o.getData()}async auth(e){this._logger.log({message:"Executing Auth",content:e,method:"_auth",correlationId:e.correlationId,level:t.Information});const o=await this._client.send({url:`${this._options.threeDSecureUrl}/api/v1/${e.id}/auth`,method:"POST",correlationId:e.correlationId});return await o.getData()}async postAuth(e){this._logger.log({message:"Executing PostAuth",content:e,method:"_postAuth",correlationId:e.correlationId,level:t.Information});const o=await this._client.send({url:`${this._options.threeDSecureUrl}/api/v2/${e.id}/postAuth`,method:"POST",correlationId:e.correlationId});return await o.getData()}}var S={__proto__:null,IFrameDirectoryServerService:I,IFrameChallengeService:v,ThreeDSecureService:y,Abstractions:_},D={__proto__:null,Abstractions:{__proto__:null},Utils:l};export{d as HttpClients,p as Loggers,S as Services,D as Shared,y as ThreeDSecureService};
//# sourceMappingURL=index.modern.js.map

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

function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},e.apply(this,arguments)}var t;!function(e){e[e.Trace=0]="Trace",e[e.Debug=1]="Debug",e[e.Information=2]="Information",e[e.Warning=3]="Warning",e[e.Error=4]="Error",e[e.Critical=5]="Critical",e[e.None=6]="None"}(t||(t={}));var r={__proto__:null,get LogLevel(){return t}},n=/*#__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}(),o=/*#__PURE__*/function(){function e(){}return e.convert=function(e){var t=JSON.stringify(e);return btoa(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")},e}(),i=/*#__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}(),a=/*#__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}(),s=/*#__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}(),l={__proto__:null,Base64Converter:o,Browser:i,Delay:a,HtmlElementFactory:s,Abstractions:{__proto__:null}};function c(e,t,r){if(!e.s){if(r instanceof u){if(!r.s)return void(r.o=c.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(c.bind(null,e,t),c.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var u=/*#__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{c(n,1,i(this.v))}catch(e){c(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?c(n,1,t?t(o):o):r?c(n,1,r(o)):c(n,2,o)}catch(e){c(n,2,e)}},n},e}();function h(e){return e instanceof u&&1&e.s}var d=/*#__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 r=this,n=e.executeFn,o=e.method,i=e.correlationId;return new Promise(function(e,s){try{var l,d=function(e){var n;if(l)return e;s(m),r._logger.log({message:'Unhandled error calling "'+o+'"',error:null==(n=m)?void 0:n.error,content:{attempt:v,maxAttempts:r._options.maxAttempts},method:o,correlationId:i,level:t.Error})},v=1,m=null,g=function(e,t){var r;do{var n=e();if(n&&n.then){if(!h(n)){r=!0;break}n=n.v}var o=t();if(h(o)&&(o=o.v),!o)return n}while(!o.then);var i=new u,a=c.bind(null,i,2);return(r?n.then(s):o.then(l)).then(void 0,a),i;function s(r){for(n=r;h(o=t())&&(o=o.v),o;){if(o.then)return void o.then(l).then(void 0,a);if((n=e())&&n.then){if(!h(n))return void n.then(s).then(void 0,a);n=n.v}}c(i,1,n)}function l(r){if(r){do{if((n=e())&&n.then){if(!h(n))return void n.then(s).then(void 0,a);n=n.v}if(h(r=t())&&(r=r.v),!r)return void c(i,1,n)}while(!r.then);r.then(l).then(void 0,a)}else c(i,1,n)}}(function(){function c(e){return l?e:(v++,Promise.resolve(a.sleep(r._options.attemptDelay).wait()).then(function(){}))}var u=function(t,o){try{var i=Promise.resolve(n({attempt:v,maxAttempts:r._options.maxAttempts})).then(function(t){if(t.isSuccess)return e(t),void(l=1);t.isTransientError||(s(t),l=1)})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){m={message:'Unhandled error calling "'+o+'"',error:e,additionalData:{attempt:v,maxAttempts:r._options.maxAttempts}},r._logger.log({message:'Unhandled error calling "'+o+'"',error:e,content:{attempt:v,maxAttempts:r._options.maxAttempts},method:o,correlationId:i,level:t.Warning})});return u&&u.then?u.then(c):c(u)},function(){return!l&&v<=r._options.maxAttempts});return Promise.resolve(g&&g.then?g.then(d):d(g))}catch(e){return Promise.reject(e)}})},e}(),v=/*#__PURE__*/function(){function r(e,t,r){void 0===r&&(r=new d(e,t)),this._options=void 0,this._retryPolicy=void 0,this._logger=void 0,this._retryPolicy=r,this._logger=t,this._options=e}var o=r.prototype;return o.send=function(r){try{var o=this,i=o;return Promise.resolve(o._retryPolicy.execute({executeFn:function(a){var s=a.attempt,l=a.maxAttempts;try{var c=function(e){return clearTimeout(d),{isSuccess:m.ok,isTransientError:o.isTransientError(m),getData:function(){try{return Promise.resolve(m.json()).then(function(e){return e.data})}catch(e){return Promise.reject(e)}}}},u=1e3*(i._options.timeoutInSeconds||30),h=new AbortController,d=setTimeout(function(){return h.abort()},u),v=new URL(r.url);o._logger.log({message:"ExternalService - Request ("+v.host+")",content:{request:r,attempt:s,maxAttempts:l},method:"send",correlationId:r.correlationId,level:t.Information});var m,g=new n,p=function(n,i){try{var a=Promise.resolve(fetch(r.url,{headers:e({},r.headers,{"x-attempt":s.toString(),"x-max-attempts":l.toString(),accept:"application/json","content-type":"application/json",correlationId:r.correlationId}),keepalive:!0,body:JSON.stringify(r.body),method:r.method,signal:h.signal})).then(function(e){o._logger.log({message:"ExternalService - Response ("+v.host+") in "+g.elapsed+"ms",content:{request:r,attempt:s,maxAttempts:l,response:m=e},method:"send",correlationId:r.correlationId,level:t.Error})})}catch(e){return i(e)}return a&&a.then?a.then(void 0,i):a}(0,function(e){throw o._logger.log({message:"ExternalService - Error ("+v.host+") in "+g.elapsed+"ms",content:{request:r,attempt:s,maxAttempts:l,error:e},method:"send",correlationId:r.correlationId,level:t.Error}),e});return Promise.resolve(p&&p.then?p.then(c):c())}catch(e){return Promise.reject(e)}},method:"["+r.method+"] "+r.url,correlationId:r.correlationId}))}catch(e){return Promise.reject(e)}},o.isTransientError=function(e){return[409,424,500,503,504].includes(e.status)},r}(),m={__proto__:null,FetchHttpClient:v,Abstractions:{__proto__:null}},g=/*#__PURE__*/function(){function t(){}var r=t.prototype;return r.flush=function(){return Promise.resolve()},r.log=function(t){var r,n=e({},t,{error:null==(r=t.error)?void 0:r.toString()});console.log(n)},t}();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;const 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 _(e){return e instanceof f&&1&e.s}var I=/*#__PURE__*/function(){function r(e,t,n){void 0===t&&(t=new g),void 0===n&&(n=new v(e,t,new d({maxAttempts:3,attemptDelay:5e3},t))),this._httpClient=void 0,this._logger=void 0,this._options=void 0,this._logs=[],this._interval=void 0,this._logger=t,this._options=e,this._httpClient=n,this._interval=setInterval(this.sendBatch.bind(this),1e3*(this._options.batchLogIntervalInSeconds||r.DEFAULT_BATCH_TIMEOUT))}var n=r.prototype;return n.log=function(t){var r;this._logger.log(t),this._options.restLoggerUrl&&this._logs.unshift({customMessage:t.message,message:"[Paybyrd.ThreeDSecure.JS] "+t.message,service:{name:"Paybyrd.ThreeDSecure.JS",version:"3.0.0"},environment:this._options.environment||"Development",executionDate:new Date,entrypoint:"Execute",method:t.method,correlationId:t.correlationId,content:e({},t.content,{error:null==(r=t.error)?void 0:r.toString()}),level:t.level})},n.flush=function(){try{var e=function(){t._interval=setInterval(t.sendBatch.bind(t),1e3*(t._options.batchLogIntervalInSeconds||r.DEFAULT_BATCH_TIMEOUT))},t=this;clearInterval(t._interval);var n=function(e,t,r){for(var n;;){var o=e();if(_(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!_(i)){n=1;break}i=i.s}if(t){var a=t();if(a&&a.then&&!_(a)){n=2;break}}}var s=new f,l=p.bind(null,s,2);return(0===n?o.then(u):1===n?i.then(c):a.then(h)).then(void 0,l),s;function c(n){i=n;do{if(t&&(a=t())&&a.then&&!_(a))return void a.then(h).then(void 0,l);if(!(o=e())||_(o)&&!o.v)return void p(s,1,i);if(o.then)return void o.then(u).then(void 0,l);_(i=r())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,l)}function u(e){e?(i=r())&&i.then?i.then(c).then(void 0,l):c(i):p(s,1,i)}function h(){(o=e())?o.then?o.then(u).then(void 0,l):u(o):p(s,1,i)}}(function(){return!!t._logs.length},void 0,function(){return Promise.resolve(t.sendBatch()).then(function(){})});return Promise.resolve(n&&n.then?n.then(e):e())}catch(e){return Promise.reject(e)}},n.sendBatch=function(){try{var e=this,r=e._logs.splice(0,10);if(!r.length)return Promise.resolve();var n=r.map(function(e){return e.correlationId})[0],o=function(t,o){try{var i=Promise.resolve(e._httpClient.send({url:e._options.restLoggerUrl,method:"POST",body:r,correlationId:n})).then(function(){})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(r){e._logger.log({error:r,message:"Error sending message to elastic",method:"sendBatch",correlationId:n,level:t.Error})});return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},r}();I.DEFAULT_BATCH_TIMEOUT=5;var y,S={__proto__:null,ConsoleLogger:g,RestLogger:I,Abstractions:r};!function(e){e.width250xheight400="01",e.width390xheight400="02",e.width500xheight600="03",e.width600xheight400="04",e.fullscreen="05"}(y||(y={}));var P={__proto__:null,get ChallengeWindowSize(){return y}},D=/*#__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(r){var i=this;return r.authResponse.challengeUrl?new Promise(function(a,l){try{i._logger.log({message:"Challenge - Start",content:{authResponse:r.authResponse},method:"executeChallenge",correlationId:r.correlationId,level:t.Information}),i._options.container.innerHTML="";var c=s.createIFrame({parent:i._options.container,name:e.IFRAME_NAME,isVisible:!0,useDefaultStyle:!!i._options.onIFrameCreatedFn,onCreatedFn:i._options.onIFrameCreatedFn,onReadyFn:i._options.onIFrameReadyFn});i._logger.log({message:"Challenge - Create iFrame",method:"executeChallenge",correlationId:r.correlationId,level:t.Information});var u=s.createForm({parent:i._options.container,name:e.FORM_NAME,actionUrl:r.authResponse.challengeUrl,target:e.IFRAME_NAME,method:"post"});i._logger.log({message:"Challenge - Create form",method:"executeChallenge",correlationId:r.correlationId,level:t.Information});var h=s.createInput({parent:u,name:e.CREQ_INPUT_NAME,type:e.CREQ_INPUT_TYPE});i._logger.log({message:"Challenge - Create input",method:"executeChallenge",correlationId:r.correlationId,level:t.Information});var d={threeDSServerTransID:r.authResponse.processId,acsTransID:r.authResponse.challengeId,messageVersion:r.authResponse.challengeVersion,messageType:"CReq",challengeWindowSize:i._options.challengeWindowSize||y.width250xheight400},v=o.convert(d);h.value=v,i._logger.log({message:"Challenge - Prepare cReq",content:{cReq:d,base64CReq:v},method:"executeChallenge",correlationId:r.correlationId,level:t.Information});var m=new n;u.submit(),setTimeout(function e(){var n,o=c.contentDocument||(null==(n=c.contentWindow)?void 0:n.document);"complete"!=(null==o?void 0:o.readyState)?setTimeout(e,100):i._logger.log({message:"Challenge - iFrame loaded in "+m.elapsed+"ms",content:{iFrame:o.body.innerText},method:"executeChallenge",correlationId:r.correlationId,level:t.Information})},100),i._logger.log({message:"Challenge - Submit form",content:{authResponse:r.authResponse,cReq:d,base64CReq:v},method:"executeChallenge",correlationId:r.correlationId,level:t.Information}),a()}catch(e){return i._logger.log({message:"Challenge - error",content:{authResponse:r.authResponse},error:e,method:"executeChallenge",correlationId:r.correlationId,level:t.Error}),l({message:e.toString()})}}):Promise.resolve()},e}();D.IFRAME_NAME="challengeIframe",D.FORM_NAME="challengeForm",D.CREQ_INPUT_NAME="creq",D.CREQ_INPUT_TYPE="hidden";var A=/*#__PURE__*/function(){function e(e,t){this._logger=void 0,this._options=void 0,this._logger=t,this._options=e}return e.prototype.execute=function(r){var i=this;return r.preAuthResponse.dsMethodUrl?new Promise(function(a,l){try{var c;i._logger.log({message:"DirectoryServer - Start",content:{preAuthResponse:r},method:"executeDirectoryServer",correlationId:r.correlationId,level:t.Information}),i._options.container.innerHTML="";var u=s.createIFrame({parent:i._options.container,isVisible:!1,name:e.IFRAME_NAME,useDefaultStyle:!!i._options.onIFrameCreatedFn});null==(c=i._options.onIFrameCreatedFn)||c.call(i._options,u),i._logger.log({message:"DirectoryServer - Create iFrame",method:"executeDirectoryServer",correlationId:r.correlationId,level:t.Information});var h=s.createForm({parent:i._options.container,name:e.FORM_NAME,actionUrl:r.preAuthResponse.dsMethodUrl,target:e.IFRAME_NAME,method:"POST"});i._logger.log({message:"DirectoryServer - Create Form",method:"executeDirectoryServer",correlationId:r.correlationId,level:t.Information});var d=s.createInput({parent:h,name:e.FORM_INPUT_NAME,type:e.FROM_INPUT_TYPE});i._logger.log({message:"DirectoryServer - Create Input",method:"executeDirectoryServer",correlationId:r.correlationId,level:t.Information});var v={threeDSServerTransID:r.preAuthResponse.processId,threeDSMethodNotificationURL:r.preAuthResponse.notificationUrl},m=o.convert(v);d.value=m,i._logger.log({message:"DirectoryServer - Prepare threeDSMethodData",content:{threeDSMethodData:v,threeDSMethodDataBase64:m},method:"executeDirectoryServer",correlationId:r.correlationId,level:t.Information});var g=new n;h.submit(),setTimeout(function e(){var n,o=u.contentDocument||(null==(n=u.contentWindow)?void 0:n.document);"complete"!=(null==o?void 0:o.readyState)?setTimeout(e,100):i._logger.log({message:"DirectoryServer - iFrame loaded in "+g.elapsed+"ms",content:{iFrame:o.body.innerText},method:"executeDirectoryServer",correlationId:r.correlationId,level:t.Information})},100),i._logger.log({message:"DirectoryServer - Submit form",content:{threeDSMethodData:v,threeDSMethodDataBase64:m},method:"executeDirectoryServer",correlationId:r.correlationId,level:t.Information}),a()}catch(e){return i._logger.log({message:"DirectoryServer - Error",content:{preAuthResponse:r},error:e,method:"directoryServerExecute",correlationId:r.correlationId,level:t.Error}),l({message:e.toString()})}}):Promise.resolve()},e}();A.IFRAME_NAME="threeDSMethodIframe",A.FORM_NAME="threeDSMethodForm",A.FORM_INPUT_NAME="threeDSMethodData",A.FROM_INPUT_TYPE="hidden";var b=/*#__PURE__*/function(){function e(e,t,r,n,o){void 0===t&&(t=new I(e)),void 0===r&&(r=new v(e,t)),void 0===n&&(n=new A(e,t)),void 0===o&&(o=new D(e,t)),this._options=void 0,this._logger=void 0,this._client=void 0,this._directoryServer=void 0,this._challenge=void 0,this._options=e,this._logger=t,this._client=r,this._directoryServer=n,this._challenge=o}var r=e.prototype;return r.execute=function(e){try{var t=this;return e.correlationId||(e.correlationId=crypto.randomUUID()),Promise.resolve(t.preAuth(e)).then(function(r){return Promise.resolve(t._directoryServer.execute({preAuthResponse:r,correlationId:e.correlationId})).then(function(){return Promise.resolve(t.auth(e)).then(function(r){return Promise.resolve(t._challenge.execute({authResponse:r,correlationId:e.correlationId})).then(function(){return Promise.resolve(t.postAuth(e)).then(function(e){return Promise.resolve(t._logger.flush()).then(function(){return e})})})})})})}catch(e){return Promise.reject(e)}},r.preAuth=function(e){try{var r=this;return r._logger.log({message:"Executing PreAuth",content:e,method:"_preAuth",correlationId:e.correlationId,level:t.Information}),Promise.resolve(r._client.send({url:r._options.threeDSecureUrl+"/api/v2/"+e.id+"/preAuth",method:"POST",body:{browser:i.create()},correlationId:e.correlationId})).then(function(e){return Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},r.auth=function(e){try{var r=this;return r._logger.log({message:"Executing Auth",content:e,method:"_auth",correlationId:e.correlationId,level:t.Information}),Promise.resolve(r._client.send({url:r._options.threeDSecureUrl+"/api/v1/"+e.id+"/auth",method:"POST",correlationId:e.correlationId})).then(function(e){return Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},r.postAuth=function(e){try{var r=this;return r._logger.log({message:"Executing PostAuth",content:e,method:"_postAuth",correlationId:e.correlationId,level:t.Information}),Promise.resolve(r._client.send({url:r._options.threeDSecureUrl+"/api/v2/"+e.id+"/postAuth",method:"POST",correlationId:e.correlationId})).then(function(e){return Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},e}(),E={__proto__:null,IFrameDirectoryServerService:A,IFrameChallengeService:D,ThreeDSecureService:b,Abstractions:P},x={__proto__:null,Abstractions:{__proto__:null},Utils:l};export{m as HttpClients,S as Loggers,E as Services,x as Shared,b as ThreeDSecureService};
function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},e.apply(this,arguments)}var t;!function(e){e[e.Trace=0]="Trace",e[e.Debug=1]="Debug",e[e.Information=2]="Information",e[e.Warning=3]="Warning",e[e.Error=4]="Error",e[e.Critical=5]="Critical",e[e.None=6]="None"}(t||(t={}));var r={__proto__:null,get LogLevel(){return t}},n=/*#__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}(),o=/*#__PURE__*/function(){function e(){}return e.convert=function(e){var t=JSON.stringify(e);return btoa(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")},e}(),i=/*#__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}(),a=/*#__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}(),s=/*#__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}(),l={__proto__:null,Base64Converter:o,Browser:i,Delay:a,HtmlElementFactory:s,Abstractions:{__proto__:null}};function c(e,t,r){if(!e.s){if(r instanceof u){if(!r.s)return void(r.o=c.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(c.bind(null,e,t),c.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var u=/*#__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{c(n,1,i(this.v))}catch(e){c(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?c(n,1,t?t(o):o):r?c(n,1,r(o)):c(n,2,o)}catch(e){c(n,2,e)}},n},e}();function h(e){return e instanceof u&&1&e.s}var d=/*#__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 r=this,n=e.executeFn,o=e.method,i=e.correlationId;return new Promise(function(e,s){try{var l,d=function(e){var n;if(l)return e;s(m),r._logger.log({message:'Unhandled error calling "'+o+'"',error:null==(n=m)?void 0:n.error,content:{attempt:v,maxAttempts:r._options.maxAttempts},method:o,correlationId:i,level:t.Error})},v=1,m=null,g=function(e,t){var r;do{var n=e();if(n&&n.then){if(!h(n)){r=!0;break}n=n.v}var o=t();if(h(o)&&(o=o.v),!o)return n}while(!o.then);var i=new u,a=c.bind(null,i,2);return(r?n.then(s):o.then(l)).then(void 0,a),i;function s(r){for(n=r;h(o=t())&&(o=o.v),o;){if(o.then)return void o.then(l).then(void 0,a);if((n=e())&&n.then){if(!h(n))return void n.then(s).then(void 0,a);n=n.v}}c(i,1,n)}function l(r){if(r){do{if((n=e())&&n.then){if(!h(n))return void n.then(s).then(void 0,a);n=n.v}if(h(r=t())&&(r=r.v),!r)return void c(i,1,n)}while(!r.then);r.then(l).then(void 0,a)}else c(i,1,n)}}(function(){function c(e){return l?e:(v++,Promise.resolve(a.sleep(r._options.attemptDelay).wait()).then(function(){}))}var u=function(t,o){try{var i=Promise.resolve(n({attempt:v,maxAttempts:r._options.maxAttempts})).then(function(t){if(t.isSuccess)return e(t),void(l=1);t.isTransientError||(s(t),l=1)})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){m={message:'Unhandled error calling "'+o+'"',error:e,additionalData:{attempt:v,maxAttempts:r._options.maxAttempts}},r._logger.log({message:'Unhandled error calling "'+o+'"',error:e,content:{attempt:v,maxAttempts:r._options.maxAttempts},method:o,correlationId:i,level:t.Warning})});return u&&u.then?u.then(c):c(u)},function(){return!l&&v<=r._options.maxAttempts});return Promise.resolve(g&&g.then?g.then(d):d(g))}catch(e){return Promise.reject(e)}})},e}(),v=/*#__PURE__*/function(){function r(e,t,r){void 0===r&&(r=new d(e,t)),this._options=void 0,this._retryPolicy=void 0,this._logger=void 0,this._retryPolicy=r,this._logger=t,this._options=e}var o=r.prototype;return o.send=function(r){try{var o=this,i=o;return Promise.resolve(o._retryPolicy.execute({executeFn:function(a){var s=a.attempt,l=a.maxAttempts;try{var c=function(e){return clearTimeout(d),{isSuccess:m.ok,isTransientError:o.isTransientError(m),getData:function(){try{return Promise.resolve(m.json()).then(function(e){return e.data})}catch(e){return Promise.reject(e)}}}},u=1e3*(i._options.timeoutInSeconds||30),h=new AbortController,d=setTimeout(function(){return h.abort()},u),v=new URL(r.url);o._logger.log({message:"ExternalService - Request ("+v.host+")",content:{request:r,attempt:s,maxAttempts:l},method:"send",correlationId:r.correlationId,level:t.Information});var m,g=new n,p=function(n,i){try{var a=Promise.resolve(fetch(r.url,{headers:e({},r.headers,{"x-attempt":s.toString(),"x-max-attempts":l.toString(),accept:"application/json","content-type":"application/json",correlationId:r.correlationId}),keepalive:!0,body:JSON.stringify(r.body),method:r.method,signal:h.signal})).then(function(e){o._logger.log({message:"ExternalService - Response ("+v.host+") in "+g.elapsed+"ms",content:{request:r,attempt:s,maxAttempts:l,response:m=e},method:"send",correlationId:r.correlationId,level:t.Error})})}catch(e){return i(e)}return a&&a.then?a.then(void 0,i):a}(0,function(e){throw o._logger.log({message:"ExternalService - Error ("+v.host+") in "+g.elapsed+"ms",content:{request:r,attempt:s,maxAttempts:l,error:e},method:"send",correlationId:r.correlationId,level:t.Error}),e});return Promise.resolve(p&&p.then?p.then(c):c())}catch(e){return Promise.reject(e)}},method:"["+r.method+"] "+r.url,correlationId:r.correlationId}))}catch(e){return Promise.reject(e)}},o.isTransientError=function(e){return[409,424,500,503,504].includes(e.status)},r}(),m={__proto__:null,FetchHttpClient:v,Abstractions:{__proto__:null}},g=/*#__PURE__*/function(){function t(){}var r=t.prototype;return r.flush=function(){return Promise.resolve()},r.log=function(t){var r,n=e({},t,{error:null==(r=t.error)?void 0:r.toString()});console.log(n)},t}();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;const 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 _(e){return e instanceof f&&1&e.s}var I=/*#__PURE__*/function(){function r(e,t,n){void 0===t&&(t=new g),void 0===n&&(n=new v(e,t,new d({maxAttempts:3,attemptDelay:5e3},t))),this._httpClient=void 0,this._logger=void 0,this._options=void 0,this._logs=[],this._interval=void 0,this._logger=t,this._options=e,this._httpClient=n,this._interval=setInterval(this.sendBatch.bind(this),1e3*(this._options.batchLogIntervalInSeconds||r.DEFAULT_BATCH_TIMEOUT))}var n=r.prototype;return n.log=function(t){var r;this._logger.log(t),this._options.restLoggerUrl&&this._logs.unshift({customMessage:t.message,message:"[Paybyrd.ThreeDSecure.JS] "+t.message,service:{name:"Paybyrd.ThreeDSecure.JS",version:"3.0.0"},environment:this._options.environment||"Development",executionDate:new Date,entrypoint:"Execute",method:t.method,correlationId:t.correlationId,content:e({},t.content,{error:null==(r=t.error)?void 0:r.toString()}),level:t.level})},n.flush=function(){try{var e=function(){t._interval=setInterval(t.sendBatch.bind(t),1e3*(t._options.batchLogIntervalInSeconds||r.DEFAULT_BATCH_TIMEOUT))},t=this;clearInterval(t._interval);var n=function(e,t,r){for(var n;;){var o=e();if(_(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!_(i)){n=1;break}i=i.s}if(t){var a=t();if(a&&a.then&&!_(a)){n=2;break}}}var s=new f,l=p.bind(null,s,2);return(0===n?o.then(u):1===n?i.then(c):a.then(h)).then(void 0,l),s;function c(n){i=n;do{if(t&&(a=t())&&a.then&&!_(a))return void a.then(h).then(void 0,l);if(!(o=e())||_(o)&&!o.v)return void p(s,1,i);if(o.then)return void o.then(u).then(void 0,l);_(i=r())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,l)}function u(e){e?(i=r())&&i.then?i.then(c).then(void 0,l):c(i):p(s,1,i)}function h(){(o=e())?o.then?o.then(u).then(void 0,l):u(o):p(s,1,i)}}(function(){return!!t._logs.length},void 0,function(){return Promise.resolve(t.sendBatch()).then(function(){})});return Promise.resolve(n&&n.then?n.then(e):e())}catch(e){return Promise.reject(e)}},n.sendBatch=function(){try{var e=this,r=e._logs.splice(0,10);if(!r.length)return Promise.resolve();var n=r.map(function(e){return e.correlationId})[0],o=function(t,o){try{var i=Promise.resolve(e._httpClient.send({url:e._options.restLoggerUrl,method:"POST",body:r,correlationId:n})).then(function(){})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(r){e._logger.log({error:r,message:"Error sending message to elastic",method:"sendBatch",correlationId:n,level:t.Error})});return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},r}();I.DEFAULT_BATCH_TIMEOUT=5;var y,S={__proto__:null,ConsoleLogger:g,RestLogger:I,Abstractions:r};!function(e){e.width250xheight400="01",e.width390xheight400="02",e.width500xheight600="03",e.width600xheight400="04",e.fullscreen="05"}(y||(y={}));var P={__proto__:null,get ChallengeWindowSize(){return y}},D=/*#__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(r){var i=this;return r.authResponse.challengeUrl?new Promise(function(a,l){try{i._logger.log({message:"Challenge - Start",content:{authResponse:r.authResponse},method:"executeChallenge",correlationId:r.correlationId,level:t.Information}),i._options.container.innerHTML="";var c=s.createIFrame({parent:i._options.container,name:e.IFRAME_NAME,isVisible:!0,useDefaultStyle:!!i._options.onIFrameCreatedFn,onCreatedFn:i._options.onIFrameCreatedFn,onReadyFn:i._options.onIFrameReadyFn});i._logger.log({message:"Challenge - Create iFrame",method:"executeChallenge",correlationId:r.correlationId,level:t.Information});var u=s.createForm({parent:i._options.container,name:e.FORM_NAME,actionUrl:r.authResponse.challengeUrl,target:e.IFRAME_NAME,method:"post"});i._logger.log({message:"Challenge - Create form",method:"executeChallenge",correlationId:r.correlationId,level:t.Information});var h=s.createInput({parent:u,name:e.CREQ_INPUT_NAME,type:e.CREQ_INPUT_TYPE});i._logger.log({message:"Challenge - Create input",method:"executeChallenge",correlationId:r.correlationId,level:t.Information});var d={threeDSServerTransID:r.authResponse.processId,acsTransID:r.authResponse.challengeId,messageVersion:r.authResponse.challengeVersion,messageType:"CReq",challengeWindowSize:i._options.challengeWindowSize||y.width250xheight400},v=o.convert(d);h.value=v,i._logger.log({message:"Challenge - Prepare cReq",content:{cReq:d,base64CReq:v},method:"executeChallenge",correlationId:r.correlationId,level:t.Information});var m=new n;u.submit(),setTimeout(function e(){var n,o=c.contentDocument||(null==(n=c.contentWindow)?void 0:n.document);"complete"!=(null==o?void 0:o.readyState)?setTimeout(e,100):i._logger.log({message:"Challenge - iFrame loaded in "+m.elapsed+"ms",content:{iFrame:o.body.innerText},method:"executeChallenge",correlationId:r.correlationId,level:t.Information})},100),i._logger.log({message:"Challenge - Submit form",content:{authResponse:r.authResponse,cReq:d,base64CReq:v},method:"executeChallenge",correlationId:r.correlationId,level:t.Information}),a()}catch(e){return i._logger.log({message:"Challenge - error",content:{authResponse:r.authResponse},error:e,method:"executeChallenge",correlationId:r.correlationId,level:t.Error}),l({message:e.toString()})}}):Promise.resolve()},e}();D.IFRAME_NAME="challengeIframe",D.FORM_NAME="challengeForm",D.CREQ_INPUT_NAME="creq",D.CREQ_INPUT_TYPE="hidden";var b=/*#__PURE__*/function(){function e(e,t){this._logger=void 0,this._options=void 0,this._logger=t,this._options=e}return e.prototype.execute=function(r){var i=this;return r.preAuthResponse.dsMethodUrl?new Promise(function(a,l){try{var c;i._logger.log({message:"DirectoryServer - Start",content:{preAuthResponse:r},method:"executeDirectoryServer",correlationId:r.correlationId,level:t.Information}),i._options.container.innerHTML="";var u=s.createIFrame({parent:i._options.container,isVisible:!1,name:e.IFRAME_NAME,useDefaultStyle:!!i._options.onIFrameCreatedFn});null==(c=i._options.onIFrameCreatedFn)||c.call(i._options,u),i._logger.log({message:"DirectoryServer - Create iFrame",method:"executeDirectoryServer",correlationId:r.correlationId,level:t.Information});var h=s.createForm({parent:i._options.container,name:e.FORM_NAME,actionUrl:r.preAuthResponse.dsMethodUrl,target:e.IFRAME_NAME,method:"POST"});i._logger.log({message:"DirectoryServer - Create Form",method:"executeDirectoryServer",correlationId:r.correlationId,level:t.Information});var d=s.createInput({parent:h,name:e.FORM_INPUT_NAME,type:e.FROM_INPUT_TYPE});i._logger.log({message:"DirectoryServer - Create Input",method:"executeDirectoryServer",correlationId:r.correlationId,level:t.Information});var v={threeDSServerTransID:r.preAuthResponse.processId,threeDSMethodNotificationURL:r.preAuthResponse.notificationUrl},m=o.convert(v);d.value=m,i._logger.log({message:"DirectoryServer - Prepare threeDSMethodData",content:{threeDSMethodData:v,threeDSMethodDataBase64:m},method:"executeDirectoryServer",correlationId:r.correlationId,level:t.Information});var g=new n;h.submit(),setTimeout(function e(){var n,o=u.contentDocument||(null==(n=u.contentWindow)?void 0:n.document);"complete"!=(null==o?void 0:o.readyState)?setTimeout(e,100):i._logger.log({message:"DirectoryServer - iFrame loaded in "+g.elapsed+"ms",content:{iFrame:o.body.innerText},method:"executeDirectoryServer",correlationId:r.correlationId,level:t.Information})},100),i._logger.log({message:"DirectoryServer - Submit form",content:{threeDSMethodData:v,threeDSMethodDataBase64:m},method:"executeDirectoryServer",correlationId:r.correlationId,level:t.Information}),a()}catch(e){return i._logger.log({message:"DirectoryServer - Error",content:{preAuthResponse:r},error:e,method:"directoryServerExecute",correlationId:r.correlationId,level:t.Error}),l({message:e.toString()})}}):Promise.resolve()},e}();b.IFRAME_NAME="threeDSMethodIframe",b.FORM_NAME="threeDSMethodForm",b.FORM_INPUT_NAME="threeDSMethodData",b.FROM_INPUT_TYPE="hidden";var A=/*#__PURE__*/function(){function e(e,t,r,n,o){void 0===t&&(t=new I(e)),void 0===r&&(r=new v(e,t)),void 0===n&&(n=new b(e,t)),void 0===o&&(o=new D(e,t)),this._options=void 0,this._logger=void 0,this._client=void 0,this._directoryServer=void 0,this._challenge=void 0,this._options=e,this._logger=t,this._client=r,this._directoryServer=n,this._challenge=o}var r=e.prototype;return r.execute=function(e,r){try{var n=this;return void 0===r&&(r=crypto.randomUUID()),e.correlationId||(e.correlationId=r,n._logger.log({message:"Obsolete request. CorrelationId is not set.",content:e,method:"execute",correlationId:e.correlationId,level:t.Information})),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)).then(function(e){return Promise.resolve(n._logger.flush()).then(function(){return e})})})})})})}catch(e){return Promise.reject(e)}},r.preAuth=function(e){try{var r=this;return r._logger.log({message:"Executing PreAuth",content:e,method:"_preAuth",correlationId:e.correlationId,level:t.Information}),Promise.resolve(r._client.send({url:r._options.threeDSecureUrl+"/api/v2/"+e.id+"/preAuth",method:"POST",body:{browser:i.create()},correlationId:e.correlationId})).then(function(e){return Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},r.auth=function(e){try{var r=this;return r._logger.log({message:"Executing Auth",content:e,method:"_auth",correlationId:e.correlationId,level:t.Information}),Promise.resolve(r._client.send({url:r._options.threeDSecureUrl+"/api/v1/"+e.id+"/auth",method:"POST",correlationId:e.correlationId})).then(function(e){return Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},r.postAuth=function(e){try{var r=this;return r._logger.log({message:"Executing PostAuth",content:e,method:"_postAuth",correlationId:e.correlationId,level:t.Information}),Promise.resolve(r._client.send({url:r._options.threeDSecureUrl+"/api/v2/"+e.id+"/postAuth",method:"POST",correlationId:e.correlationId})).then(function(e){return Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},e}(),E={__proto__:null,IFrameDirectoryServerService:b,IFrameChallengeService:D,ThreeDSecureService:A,Abstractions:P},x={__proto__:null,Abstractions:{__proto__:null},Utils:l};export{m as HttpClients,S as Loggers,E as Services,x as Shared,A as ThreeDSecureService};
//# sourceMappingURL=index.module.js.map

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).threedsecureService={})}(this,function(e){function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}var r;!function(e){e[e.Trace=0]="Trace",e[e.Debug=1]="Debug",e[e.Information=2]="Information",e[e.Warning=3]="Warning",e[e.Error=4]="Error",e[e.Critical=5]="Critical",e[e.None=6]="None"}(r||(r={}));var n={__proto__:null,get LogLevel(){return r}},o=/*#__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}(),i=/*#__PURE__*/function(){function e(){}return e.convert=function(e){var t=JSON.stringify(e);return btoa(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")},e}(),a=/*#__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}(),s=/*#__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}(),l=/*#__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}(),c={__proto__:null,Base64Converter:i,Browser:a,Delay:s,HtmlElementFactory:l,Abstractions:{__proto__:null}};function u(e,t,r){if(!e.s){if(r instanceof h){if(!r.s)return void(r.o=u.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(u.bind(null,e,t),u.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var h=/*#__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{u(n,1,i(this.v))}catch(e){u(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?u(n,1,t?t(o):o):r?u(n,1,r(o)):u(n,2,o)}catch(e){u(n,2,e)}},n},e}();function d(e){return e instanceof h&&1&e.s}var v=/*#__PURE__*/function(){function e(e,t){this._options=void 0,this._logger=void 0,this._options=e,this._logger=t}return e.prototype.execute=function(e){var t=this,n=e.executeFn,o=e.method,i=e.correlationId;return new Promise(function(e,a){try{var l,c=function(e){var n;if(l)return e;a(m),t._logger.log({message:'Unhandled error calling "'+o+'"',error:null==(n=m)?void 0:n.error,content:{attempt:v,maxAttempts:t._options.maxAttempts},method:o,correlationId:i,level:r.Error})},v=1,m=null,g=function(e,t){var r;do{var n=e();if(n&&n.then){if(!d(n)){r=!0;break}n=n.v}var o=t();if(d(o)&&(o=o.v),!o)return n}while(!o.then);var i=new h,a=u.bind(null,i,2);return(r?n.then(s):o.then(l)).then(void 0,a),i;function s(r){for(n=r;d(o=t())&&(o=o.v),o;){if(o.then)return void o.then(l).then(void 0,a);if((n=e())&&n.then){if(!d(n))return void n.then(s).then(void 0,a);n=n.v}}u(i,1,n)}function l(r){if(r){do{if((n=e())&&n.then){if(!d(n))return void n.then(s).then(void 0,a);n=n.v}if(d(r=t())&&(r=r.v),!r)return void u(i,1,n)}while(!r.then);r.then(l).then(void 0,a)}else u(i,1,n)}}(function(){function c(e){return l?e:(v++,Promise.resolve(s.sleep(t._options.attemptDelay).wait()).then(function(){}))}var u=function(r,o){try{var i=Promise.resolve(n({attempt:v,maxAttempts:t._options.maxAttempts})).then(function(t){if(t.isSuccess)return e(t),void(l=1);t.isTransientError||(a(t),l=1)})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){m={message:'Unhandled error calling "'+o+'"',error:e,additionalData:{attempt:v,maxAttempts:t._options.maxAttempts}},t._logger.log({message:'Unhandled error calling "'+o+'"',error:e,content:{attempt:v,maxAttempts:t._options.maxAttempts},method:o,correlationId:i,level:r.Warning})});return u&&u.then?u.then(c):c(u)},function(){return!l&&v<=t._options.maxAttempts});return Promise.resolve(g&&g.then?g.then(c):c(g))}catch(e){return Promise.reject(e)}})},e}(),m=/*#__PURE__*/function(){function e(e,t,r){void 0===r&&(r=new v(e,t)),this._options=void 0,this._retryPolicy=void 0,this._logger=void 0,this._retryPolicy=r,this._logger=t,this._options=e}var n=e.prototype;return n.send=function(e){try{var n=this,i=n;return Promise.resolve(n._retryPolicy.execute({executeFn:function(a){var s=a.attempt,l=a.maxAttempts;try{var c=function(e){return clearTimeout(d),{isSuccess:m.ok,isTransientError:n.isTransientError(m),getData:function(){try{return Promise.resolve(m.json()).then(function(e){return e.data})}catch(e){return Promise.reject(e)}}}},u=1e3*(i._options.timeoutInSeconds||30),h=new AbortController,d=setTimeout(function(){return h.abort()},u),v=new URL(e.url);n._logger.log({message:"ExternalService - Request ("+v.host+")",content:{request:e,attempt:s,maxAttempts:l},method:"send",correlationId:e.correlationId,level:r.Information});var m,g=new o,p=function(o,i){try{var a=Promise.resolve(fetch(e.url,{headers:t({},e.headers,{"x-attempt":s.toString(),"x-max-attempts":l.toString(),accept:"application/json","content-type":"application/json",correlationId:e.correlationId}),keepalive:!0,body:JSON.stringify(e.body),method:e.method,signal:h.signal})).then(function(t){n._logger.log({message:"ExternalService - Response ("+v.host+") in "+g.elapsed+"ms",content:{request:e,attempt:s,maxAttempts:l,response:m=t},method:"send",correlationId:e.correlationId,level:r.Error})})}catch(e){return i(e)}return a&&a.then?a.then(void 0,i):a}(0,function(t){throw n._logger.log({message:"ExternalService - Error ("+v.host+") in "+g.elapsed+"ms",content:{request:e,attempt:s,maxAttempts:l,error:t},method:"send",correlationId:e.correlationId,level:r.Error}),t});return Promise.resolve(p&&p.then?p.then(c):c())}catch(e){return Promise.reject(e)}},method:"["+e.method+"] "+e.url,correlationId:e.correlationId}))}catch(e){return Promise.reject(e)}},n.isTransientError=function(e){return[409,424,500,503,504].includes(e.status)},e}(),g={__proto__:null,FetchHttpClient:m,Abstractions:{__proto__:null}},p=/*#__PURE__*/function(){function e(){}var r=e.prototype;return r.flush=function(){return Promise.resolve()},r.log=function(e){var r,n=t({},e,{error:null==(r=e.error)?void 0:r.toString()});console.log(n)},e}();function f(e,t,r){if(!e.s){if(r instanceof _){if(!r.s)return void(r.o=f.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(f.bind(null,e,t),f.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var _=/*#__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{f(n,1,i(this.v))}catch(e){f(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?f(n,1,t?t(o):o):r?f(n,1,r(o)):f(n,2,o)}catch(e){f(n,2,e)}},n},e}();function I(e){return e instanceof _&&1&e.s}var y=/*#__PURE__*/function(){function e(t,r,n){void 0===r&&(r=new p),void 0===n&&(n=new m(t,r,new v({maxAttempts:3,attemptDelay:5e3},r))),this._httpClient=void 0,this._logger=void 0,this._options=void 0,this._logs=[],this._interval=void 0,this._logger=r,this._options=t,this._httpClient=n,this._interval=setInterval(this.sendBatch.bind(this),1e3*(this._options.batchLogIntervalInSeconds||e.DEFAULT_BATCH_TIMEOUT))}var n=e.prototype;return n.log=function(e){var r;this._logger.log(e),this._options.restLoggerUrl&&this._logs.unshift({customMessage:e.message,message:"[Paybyrd.ThreeDSecure.JS] "+e.message,service:{name:"Paybyrd.ThreeDSecure.JS",version:"3.0.0"},environment:this._options.environment||"Development",executionDate:new Date,entrypoint:"Execute",method:e.method,correlationId:e.correlationId,content:t({},e.content,{error:null==(r=e.error)?void 0:r.toString()}),level:e.level})},n.flush=function(){try{var t=function(){r._interval=setInterval(r.sendBatch.bind(r),1e3*(r._options.batchLogIntervalInSeconds||e.DEFAULT_BATCH_TIMEOUT))},r=this;clearInterval(r._interval);var n=function(e,t,r){for(var n;;){var o=e();if(I(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!I(i)){n=1;break}i=i.s}if(t){var a=t();if(a&&a.then&&!I(a)){n=2;break}}}var s=new _,l=f.bind(null,s,2);return(0===n?o.then(u):1===n?i.then(c):a.then(h)).then(void 0,l),s;function c(n){i=n;do{if(t&&(a=t())&&a.then&&!I(a))return void a.then(h).then(void 0,l);if(!(o=e())||I(o)&&!o.v)return void f(s,1,i);if(o.then)return void o.then(u).then(void 0,l);I(i=r())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,l)}function u(e){e?(i=r())&&i.then?i.then(c).then(void 0,l):c(i):f(s,1,i)}function h(){(o=e())?o.then?o.then(u).then(void 0,l):u(o):f(s,1,i)}}(function(){return!!r._logs.length},void 0,function(){return Promise.resolve(r.sendBatch()).then(function(){})});return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},n.sendBatch=function(){try{var e=this,t=e._logs.splice(0,10);if(!t.length)return Promise.resolve();var n=t.map(function(e){return e.correlationId})[0],o=function(r,o){try{var i=Promise.resolve(e._httpClient.send({url:e._options.restLoggerUrl,method:"POST",body:t,correlationId:n})).then(function(){})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(t){e._logger.log({error:t,message:"Error sending message to elastic",method:"sendBatch",correlationId:n,level:r.Error})});return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},e}();y.DEFAULT_BATCH_TIMEOUT=5;var S,P={__proto__:null,ConsoleLogger:p,RestLogger:y,Abstractions:n};!function(e){e.width250xheight400="01",e.width390xheight400="02",e.width500xheight600="03",e.width600xheight400="04",e.fullscreen="05"}(S||(S={}));var D={__proto__:null,get ChallengeWindowSize(){return S}},b=/*#__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(t){var n=this;return t.authResponse.challengeUrl?new Promise(function(a,s){try{n._logger.log({message:"Challenge - Start",content:{authResponse:t.authResponse},method:"executeChallenge",correlationId:t.correlationId,level:r.Information}),n._options.container.innerHTML="";var c=l.createIFrame({parent:n._options.container,name:e.IFRAME_NAME,isVisible:!0,useDefaultStyle:!!n._options.onIFrameCreatedFn,onCreatedFn:n._options.onIFrameCreatedFn,onReadyFn:n._options.onIFrameReadyFn});n._logger.log({message:"Challenge - Create iFrame",method:"executeChallenge",correlationId:t.correlationId,level:r.Information});var u=l.createForm({parent:n._options.container,name:e.FORM_NAME,actionUrl:t.authResponse.challengeUrl,target:e.IFRAME_NAME,method:"post"});n._logger.log({message:"Challenge - Create form",method:"executeChallenge",correlationId:t.correlationId,level:r.Information});var h=l.createInput({parent:u,name:e.CREQ_INPUT_NAME,type:e.CREQ_INPUT_TYPE});n._logger.log({message:"Challenge - Create input",method:"executeChallenge",correlationId:t.correlationId,level:r.Information});var d={threeDSServerTransID:t.authResponse.processId,acsTransID:t.authResponse.challengeId,messageVersion:t.authResponse.challengeVersion,messageType:"CReq",challengeWindowSize:n._options.challengeWindowSize||S.width250xheight400},v=i.convert(d);h.value=v,n._logger.log({message:"Challenge - Prepare cReq",content:{cReq:d,base64CReq:v},method:"executeChallenge",correlationId:t.correlationId,level:r.Information});var m=new o;u.submit(),setTimeout(function e(){var o,i=c.contentDocument||(null==(o=c.contentWindow)?void 0:o.document);"complete"!=(null==i?void 0:i.readyState)?setTimeout(e,100):n._logger.log({message:"Challenge - iFrame loaded in "+m.elapsed+"ms",content:{iFrame:i.body.innerText},method:"executeChallenge",correlationId:t.correlationId,level:r.Information})},100),n._logger.log({message:"Challenge - Submit form",content:{authResponse:t.authResponse,cReq:d,base64CReq:v},method:"executeChallenge",correlationId:t.correlationId,level:r.Information}),a()}catch(e){return n._logger.log({message:"Challenge - error",content:{authResponse:t.authResponse},error:e,method:"executeChallenge",correlationId:t.correlationId,level:r.Error}),s({message:e.toString()})}}):Promise.resolve()},e}();b.IFRAME_NAME="challengeIframe",b.FORM_NAME="challengeForm",b.CREQ_INPUT_NAME="creq",b.CREQ_INPUT_TYPE="hidden";var A=/*#__PURE__*/function(){function e(e,t){this._logger=void 0,this._options=void 0,this._logger=t,this._options=e}return e.prototype.execute=function(t){var n=this;return t.preAuthResponse.dsMethodUrl?new Promise(function(a,s){try{var c;n._logger.log({message:"DirectoryServer - Start",content:{preAuthResponse:t},method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information}),n._options.container.innerHTML="";var u=l.createIFrame({parent:n._options.container,isVisible:!1,name:e.IFRAME_NAME,useDefaultStyle:!!n._options.onIFrameCreatedFn});null==(c=n._options.onIFrameCreatedFn)||c.call(n._options,u),n._logger.log({message:"DirectoryServer - Create iFrame",method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information});var h=l.createForm({parent:n._options.container,name:e.FORM_NAME,actionUrl:t.preAuthResponse.dsMethodUrl,target:e.IFRAME_NAME,method:"POST"});n._logger.log({message:"DirectoryServer - Create Form",method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information});var d=l.createInput({parent:h,name:e.FORM_INPUT_NAME,type:e.FROM_INPUT_TYPE});n._logger.log({message:"DirectoryServer - Create Input",method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information});var v={threeDSServerTransID:t.preAuthResponse.processId,threeDSMethodNotificationURL:t.preAuthResponse.notificationUrl},m=i.convert(v);d.value=m,n._logger.log({message:"DirectoryServer - Prepare threeDSMethodData",content:{threeDSMethodData:v,threeDSMethodDataBase64:m},method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information});var g=new o;h.submit(),setTimeout(function e(){var o,i=u.contentDocument||(null==(o=u.contentWindow)?void 0:o.document);"complete"!=(null==i?void 0:i.readyState)?setTimeout(e,100):n._logger.log({message:"DirectoryServer - iFrame loaded in "+g.elapsed+"ms",content:{iFrame:i.body.innerText},method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information})},100),n._logger.log({message:"DirectoryServer - Submit form",content:{threeDSMethodData:v,threeDSMethodDataBase64:m},method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information}),a()}catch(e){return n._logger.log({message:"DirectoryServer - Error",content:{preAuthResponse:t},error:e,method:"directoryServerExecute",correlationId:t.correlationId,level:r.Error}),s({message:e.toString()})}}):Promise.resolve()},e}();A.IFRAME_NAME="threeDSMethodIframe",A.FORM_NAME="threeDSMethodForm",A.FORM_INPUT_NAME="threeDSMethodData",A.FROM_INPUT_TYPE="hidden";var x=/*#__PURE__*/function(){function e(e,t,r,n,o){void 0===t&&(t=new y(e)),void 0===r&&(r=new m(e,t)),void 0===n&&(n=new A(e,t)),void 0===o&&(o=new b(e,t)),this._options=void 0,this._logger=void 0,this._client=void 0,this._directoryServer=void 0,this._challenge=void 0,this._options=e,this._logger=t,this._client=r,this._directoryServer=n,this._challenge=o}var t=e.prototype;return t.execute=function(e){try{var t=this;return e.correlationId||(e.correlationId=crypto.randomUUID()),Promise.resolve(t.preAuth(e)).then(function(r){return Promise.resolve(t._directoryServer.execute({preAuthResponse:r,correlationId:e.correlationId})).then(function(){return Promise.resolve(t.auth(e)).then(function(r){return Promise.resolve(t._challenge.execute({authResponse:r,correlationId:e.correlationId})).then(function(){return Promise.resolve(t.postAuth(e)).then(function(e){return Promise.resolve(t._logger.flush()).then(function(){return e})})})})})})}catch(e){return Promise.reject(e)}},t.preAuth=function(e){try{var t=this;return t._logger.log({message:"Executing PreAuth",content:e,method:"_preAuth",correlationId:e.correlationId,level:r.Information}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v2/"+e.id+"/preAuth",method:"POST",body:{browser:a.create()},correlationId:e.correlationId})).then(function(e){return Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},t.auth=function(e){try{var t=this;return t._logger.log({message:"Executing Auth",content:e,method:"_auth",correlationId:e.correlationId,level:r.Information}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v1/"+e.id+"/auth",method:"POST",correlationId:e.correlationId})).then(function(e){return Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},t.postAuth=function(e){try{var t=this;return t._logger.log({message:"Executing PostAuth",content:e,method:"_postAuth",correlationId:e.correlationId,level:r.Information}),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())})}catch(e){return Promise.reject(e)}},e}(),E={__proto__:null,IFrameDirectoryServerService:A,IFrameChallengeService:b,ThreeDSecureService:x,Abstractions:D},T={__proto__:null,Abstractions:{__proto__:null},Utils:c};e.HttpClients=g,e.Loggers=P,e.Services=E,e.Shared=T,e.ThreeDSecureService=x});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).threedsecureService={})}(this,function(e){function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}var r;!function(e){e[e.Trace=0]="Trace",e[e.Debug=1]="Debug",e[e.Information=2]="Information",e[e.Warning=3]="Warning",e[e.Error=4]="Error",e[e.Critical=5]="Critical",e[e.None=6]="None"}(r||(r={}));var n={__proto__:null,get LogLevel(){return r}},o=/*#__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}(),i=/*#__PURE__*/function(){function e(){}return e.convert=function(e){var t=JSON.stringify(e);return btoa(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")},e}(),a=/*#__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}(),s=/*#__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}(),l=/*#__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}(),c={__proto__:null,Base64Converter:i,Browser:a,Delay:s,HtmlElementFactory:l,Abstractions:{__proto__:null}};function u(e,t,r){if(!e.s){if(r instanceof h){if(!r.s)return void(r.o=u.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(u.bind(null,e,t),u.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var h=/*#__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{u(n,1,i(this.v))}catch(e){u(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?u(n,1,t?t(o):o):r?u(n,1,r(o)):u(n,2,o)}catch(e){u(n,2,e)}},n},e}();function d(e){return e instanceof h&&1&e.s}var v=/*#__PURE__*/function(){function e(e,t){this._options=void 0,this._logger=void 0,this._options=e,this._logger=t}return e.prototype.execute=function(e){var t=this,n=e.executeFn,o=e.method,i=e.correlationId;return new Promise(function(e,a){try{var l,c=function(e){var n;if(l)return e;a(m),t._logger.log({message:'Unhandled error calling "'+o+'"',error:null==(n=m)?void 0:n.error,content:{attempt:v,maxAttempts:t._options.maxAttempts},method:o,correlationId:i,level:r.Error})},v=1,m=null,g=function(e,t){var r;do{var n=e();if(n&&n.then){if(!d(n)){r=!0;break}n=n.v}var o=t();if(d(o)&&(o=o.v),!o)return n}while(!o.then);var i=new h,a=u.bind(null,i,2);return(r?n.then(s):o.then(l)).then(void 0,a),i;function s(r){for(n=r;d(o=t())&&(o=o.v),o;){if(o.then)return void o.then(l).then(void 0,a);if((n=e())&&n.then){if(!d(n))return void n.then(s).then(void 0,a);n=n.v}}u(i,1,n)}function l(r){if(r){do{if((n=e())&&n.then){if(!d(n))return void n.then(s).then(void 0,a);n=n.v}if(d(r=t())&&(r=r.v),!r)return void u(i,1,n)}while(!r.then);r.then(l).then(void 0,a)}else u(i,1,n)}}(function(){function c(e){return l?e:(v++,Promise.resolve(s.sleep(t._options.attemptDelay).wait()).then(function(){}))}var u=function(r,o){try{var i=Promise.resolve(n({attempt:v,maxAttempts:t._options.maxAttempts})).then(function(t){if(t.isSuccess)return e(t),void(l=1);t.isTransientError||(a(t),l=1)})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){m={message:'Unhandled error calling "'+o+'"',error:e,additionalData:{attempt:v,maxAttempts:t._options.maxAttempts}},t._logger.log({message:'Unhandled error calling "'+o+'"',error:e,content:{attempt:v,maxAttempts:t._options.maxAttempts},method:o,correlationId:i,level:r.Warning})});return u&&u.then?u.then(c):c(u)},function(){return!l&&v<=t._options.maxAttempts});return Promise.resolve(g&&g.then?g.then(c):c(g))}catch(e){return Promise.reject(e)}})},e}(),m=/*#__PURE__*/function(){function e(e,t,r){void 0===r&&(r=new v(e,t)),this._options=void 0,this._retryPolicy=void 0,this._logger=void 0,this._retryPolicy=r,this._logger=t,this._options=e}var n=e.prototype;return n.send=function(e){try{var n=this,i=n;return Promise.resolve(n._retryPolicy.execute({executeFn:function(a){var s=a.attempt,l=a.maxAttempts;try{var c=function(e){return clearTimeout(d),{isSuccess:m.ok,isTransientError:n.isTransientError(m),getData:function(){try{return Promise.resolve(m.json()).then(function(e){return e.data})}catch(e){return Promise.reject(e)}}}},u=1e3*(i._options.timeoutInSeconds||30),h=new AbortController,d=setTimeout(function(){return h.abort()},u),v=new URL(e.url);n._logger.log({message:"ExternalService - Request ("+v.host+")",content:{request:e,attempt:s,maxAttempts:l},method:"send",correlationId:e.correlationId,level:r.Information});var m,g=new o,p=function(o,i){try{var a=Promise.resolve(fetch(e.url,{headers:t({},e.headers,{"x-attempt":s.toString(),"x-max-attempts":l.toString(),accept:"application/json","content-type":"application/json",correlationId:e.correlationId}),keepalive:!0,body:JSON.stringify(e.body),method:e.method,signal:h.signal})).then(function(t){n._logger.log({message:"ExternalService - Response ("+v.host+") in "+g.elapsed+"ms",content:{request:e,attempt:s,maxAttempts:l,response:m=t},method:"send",correlationId:e.correlationId,level:r.Error})})}catch(e){return i(e)}return a&&a.then?a.then(void 0,i):a}(0,function(t){throw n._logger.log({message:"ExternalService - Error ("+v.host+") in "+g.elapsed+"ms",content:{request:e,attempt:s,maxAttempts:l,error:t},method:"send",correlationId:e.correlationId,level:r.Error}),t});return Promise.resolve(p&&p.then?p.then(c):c())}catch(e){return Promise.reject(e)}},method:"["+e.method+"] "+e.url,correlationId:e.correlationId}))}catch(e){return Promise.reject(e)}},n.isTransientError=function(e){return[409,424,500,503,504].includes(e.status)},e}(),g={__proto__:null,FetchHttpClient:m,Abstractions:{__proto__:null}},p=/*#__PURE__*/function(){function e(){}var r=e.prototype;return r.flush=function(){return Promise.resolve()},r.log=function(e){var r,n=t({},e,{error:null==(r=e.error)?void 0:r.toString()});console.log(n)},e}();function f(e,t,r){if(!e.s){if(r instanceof _){if(!r.s)return void(r.o=f.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(f.bind(null,e,t),f.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var _=/*#__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{f(n,1,i(this.v))}catch(e){f(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?f(n,1,t?t(o):o):r?f(n,1,r(o)):f(n,2,o)}catch(e){f(n,2,e)}},n},e}();function I(e){return e instanceof _&&1&e.s}var y=/*#__PURE__*/function(){function e(t,r,n){void 0===r&&(r=new p),void 0===n&&(n=new m(t,r,new v({maxAttempts:3,attemptDelay:5e3},r))),this._httpClient=void 0,this._logger=void 0,this._options=void 0,this._logs=[],this._interval=void 0,this._logger=r,this._options=t,this._httpClient=n,this._interval=setInterval(this.sendBatch.bind(this),1e3*(this._options.batchLogIntervalInSeconds||e.DEFAULT_BATCH_TIMEOUT))}var n=e.prototype;return n.log=function(e){var r;this._logger.log(e),this._options.restLoggerUrl&&this._logs.unshift({customMessage:e.message,message:"[Paybyrd.ThreeDSecure.JS] "+e.message,service:{name:"Paybyrd.ThreeDSecure.JS",version:"3.0.0"},environment:this._options.environment||"Development",executionDate:new Date,entrypoint:"Execute",method:e.method,correlationId:e.correlationId,content:t({},e.content,{error:null==(r=e.error)?void 0:r.toString()}),level:e.level})},n.flush=function(){try{var t=function(){r._interval=setInterval(r.sendBatch.bind(r),1e3*(r._options.batchLogIntervalInSeconds||e.DEFAULT_BATCH_TIMEOUT))},r=this;clearInterval(r._interval);var n=function(e,t,r){for(var n;;){var o=e();if(I(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!I(i)){n=1;break}i=i.s}if(t){var a=t();if(a&&a.then&&!I(a)){n=2;break}}}var s=new _,l=f.bind(null,s,2);return(0===n?o.then(u):1===n?i.then(c):a.then(h)).then(void 0,l),s;function c(n){i=n;do{if(t&&(a=t())&&a.then&&!I(a))return void a.then(h).then(void 0,l);if(!(o=e())||I(o)&&!o.v)return void f(s,1,i);if(o.then)return void o.then(u).then(void 0,l);I(i=r())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,l)}function u(e){e?(i=r())&&i.then?i.then(c).then(void 0,l):c(i):f(s,1,i)}function h(){(o=e())?o.then?o.then(u).then(void 0,l):u(o):f(s,1,i)}}(function(){return!!r._logs.length},void 0,function(){return Promise.resolve(r.sendBatch()).then(function(){})});return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},n.sendBatch=function(){try{var e=this,t=e._logs.splice(0,10);if(!t.length)return Promise.resolve();var n=t.map(function(e){return e.correlationId})[0],o=function(r,o){try{var i=Promise.resolve(e._httpClient.send({url:e._options.restLoggerUrl,method:"POST",body:t,correlationId:n})).then(function(){})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(t){e._logger.log({error:t,message:"Error sending message to elastic",method:"sendBatch",correlationId:n,level:r.Error})});return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},e}();y.DEFAULT_BATCH_TIMEOUT=5;var S,P={__proto__:null,ConsoleLogger:p,RestLogger:y,Abstractions:n};!function(e){e.width250xheight400="01",e.width390xheight400="02",e.width500xheight600="03",e.width600xheight400="04",e.fullscreen="05"}(S||(S={}));var D={__proto__:null,get ChallengeWindowSize(){return S}},b=/*#__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(t){var n=this;return t.authResponse.challengeUrl?new Promise(function(a,s){try{n._logger.log({message:"Challenge - Start",content:{authResponse:t.authResponse},method:"executeChallenge",correlationId:t.correlationId,level:r.Information}),n._options.container.innerHTML="";var c=l.createIFrame({parent:n._options.container,name:e.IFRAME_NAME,isVisible:!0,useDefaultStyle:!!n._options.onIFrameCreatedFn,onCreatedFn:n._options.onIFrameCreatedFn,onReadyFn:n._options.onIFrameReadyFn});n._logger.log({message:"Challenge - Create iFrame",method:"executeChallenge",correlationId:t.correlationId,level:r.Information});var u=l.createForm({parent:n._options.container,name:e.FORM_NAME,actionUrl:t.authResponse.challengeUrl,target:e.IFRAME_NAME,method:"post"});n._logger.log({message:"Challenge - Create form",method:"executeChallenge",correlationId:t.correlationId,level:r.Information});var h=l.createInput({parent:u,name:e.CREQ_INPUT_NAME,type:e.CREQ_INPUT_TYPE});n._logger.log({message:"Challenge - Create input",method:"executeChallenge",correlationId:t.correlationId,level:r.Information});var d={threeDSServerTransID:t.authResponse.processId,acsTransID:t.authResponse.challengeId,messageVersion:t.authResponse.challengeVersion,messageType:"CReq",challengeWindowSize:n._options.challengeWindowSize||S.width250xheight400},v=i.convert(d);h.value=v,n._logger.log({message:"Challenge - Prepare cReq",content:{cReq:d,base64CReq:v},method:"executeChallenge",correlationId:t.correlationId,level:r.Information});var m=new o;u.submit(),setTimeout(function e(){var o,i=c.contentDocument||(null==(o=c.contentWindow)?void 0:o.document);"complete"!=(null==i?void 0:i.readyState)?setTimeout(e,100):n._logger.log({message:"Challenge - iFrame loaded in "+m.elapsed+"ms",content:{iFrame:i.body.innerText},method:"executeChallenge",correlationId:t.correlationId,level:r.Information})},100),n._logger.log({message:"Challenge - Submit form",content:{authResponse:t.authResponse,cReq:d,base64CReq:v},method:"executeChallenge",correlationId:t.correlationId,level:r.Information}),a()}catch(e){return n._logger.log({message:"Challenge - error",content:{authResponse:t.authResponse},error:e,method:"executeChallenge",correlationId:t.correlationId,level:r.Error}),s({message:e.toString()})}}):Promise.resolve()},e}();b.IFRAME_NAME="challengeIframe",b.FORM_NAME="challengeForm",b.CREQ_INPUT_NAME="creq",b.CREQ_INPUT_TYPE="hidden";var x=/*#__PURE__*/function(){function e(e,t){this._logger=void 0,this._options=void 0,this._logger=t,this._options=e}return e.prototype.execute=function(t){var n=this;return t.preAuthResponse.dsMethodUrl?new Promise(function(a,s){try{var c;n._logger.log({message:"DirectoryServer - Start",content:{preAuthResponse:t},method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information}),n._options.container.innerHTML="";var u=l.createIFrame({parent:n._options.container,isVisible:!1,name:e.IFRAME_NAME,useDefaultStyle:!!n._options.onIFrameCreatedFn});null==(c=n._options.onIFrameCreatedFn)||c.call(n._options,u),n._logger.log({message:"DirectoryServer - Create iFrame",method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information});var h=l.createForm({parent:n._options.container,name:e.FORM_NAME,actionUrl:t.preAuthResponse.dsMethodUrl,target:e.IFRAME_NAME,method:"POST"});n._logger.log({message:"DirectoryServer - Create Form",method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information});var d=l.createInput({parent:h,name:e.FORM_INPUT_NAME,type:e.FROM_INPUT_TYPE});n._logger.log({message:"DirectoryServer - Create Input",method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information});var v={threeDSServerTransID:t.preAuthResponse.processId,threeDSMethodNotificationURL:t.preAuthResponse.notificationUrl},m=i.convert(v);d.value=m,n._logger.log({message:"DirectoryServer - Prepare threeDSMethodData",content:{threeDSMethodData:v,threeDSMethodDataBase64:m},method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information});var g=new o;h.submit(),setTimeout(function e(){var o,i=u.contentDocument||(null==(o=u.contentWindow)?void 0:o.document);"complete"!=(null==i?void 0:i.readyState)?setTimeout(e,100):n._logger.log({message:"DirectoryServer - iFrame loaded in "+g.elapsed+"ms",content:{iFrame:i.body.innerText},method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information})},100),n._logger.log({message:"DirectoryServer - Submit form",content:{threeDSMethodData:v,threeDSMethodDataBase64:m},method:"executeDirectoryServer",correlationId:t.correlationId,level:r.Information}),a()}catch(e){return n._logger.log({message:"DirectoryServer - Error",content:{preAuthResponse:t},error:e,method:"directoryServerExecute",correlationId:t.correlationId,level:r.Error}),s({message:e.toString()})}}):Promise.resolve()},e}();x.IFRAME_NAME="threeDSMethodIframe",x.FORM_NAME="threeDSMethodForm",x.FORM_INPUT_NAME="threeDSMethodData",x.FROM_INPUT_TYPE="hidden";var A=/*#__PURE__*/function(){function e(e,t,r,n,o){void 0===t&&(t=new y(e)),void 0===r&&(r=new m(e,t)),void 0===n&&(n=new x(e,t)),void 0===o&&(o=new b(e,t)),this._options=void 0,this._logger=void 0,this._client=void 0,this._directoryServer=void 0,this._challenge=void 0,this._options=e,this._logger=t,this._client=r,this._directoryServer=n,this._challenge=o}var t=e.prototype;return t.execute=function(e,t){try{var n=this;return void 0===t&&(t=crypto.randomUUID()),e.correlationId||(e.correlationId=t,n._logger.log({message:"Obsolete request. CorrelationId is not set.",content:e,method:"execute",correlationId:e.correlationId,level:r.Information})),Promise.resolve(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)).then(function(e){return Promise.resolve(n._logger.flush()).then(function(){return e})})})})})})}catch(e){return Promise.reject(e)}},t.preAuth=function(e){try{var t=this;return t._logger.log({message:"Executing PreAuth",content:e,method:"_preAuth",correlationId:e.correlationId,level:r.Information}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v2/"+e.id+"/preAuth",method:"POST",body:{browser:a.create()},correlationId:e.correlationId})).then(function(e){return Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},t.auth=function(e){try{var t=this;return t._logger.log({message:"Executing Auth",content:e,method:"_auth",correlationId:e.correlationId,level:r.Information}),Promise.resolve(t._client.send({url:t._options.threeDSecureUrl+"/api/v1/"+e.id+"/auth",method:"POST",correlationId:e.correlationId})).then(function(e){return Promise.resolve(e.getData())})}catch(e){return Promise.reject(e)}},t.postAuth=function(e){try{var t=this;return t._logger.log({message:"Executing PostAuth",content:e,method:"_postAuth",correlationId:e.correlationId,level:r.Information}),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())})}catch(e){return Promise.reject(e)}},e}(),E={__proto__:null,IFrameDirectoryServerService:x,IFrameChallengeService:b,ThreeDSecureService:A,Abstractions:D},T={__proto__:null,Abstractions:{__proto__:null},Utils:c};e.HttpClients=g,e.Loggers=P,e.Services=E,e.Shared=T,e.ThreeDSecureService=A});
//# sourceMappingURL=index.umd.js.map

@@ -11,3 +11,3 @@ import { IHttpClient } from "../httpClients/abstractions";

constructor(options: IThreeDSecureOptions, logger?: ILogger, httpClient?: IHttpClient, directoryServer?: IDirectoryServerService, challenge?: IChallengeService);
execute(request: IExecuteRequest): Promise<IPostAuthResponse>;
execute(request: IExecuteRequest, correlationId?: string): Promise<IPostAuthResponse>;
private preAuth;

@@ -14,0 +14,0 @@ private auth;

{
"name": "@paybyrd/threedsecure-service",
"version": "3.0.0-rc.17",
"version": "3.0.0-rc.18",
"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

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