@accithus/security-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/types/client.d.ts +37 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/controllers/fraud-analysis.d.ts +13 -0
- package/dist/types/controllers/fraud-analysis.d.ts.map +1 -0
- package/dist/types/controllers/three-ds.d.ts +25 -0
- package/dist/types/controllers/three-ds.d.ts.map +1 -0
- package/dist/types/controllers/tokenizer.d.ts +11 -0
- package/dist/types/controllers/tokenizer.d.ts.map +1 -0
- package/dist/types/errors/index.d.ts +26 -0
- package/dist/types/errors/index.d.ts.map +1 -0
- package/dist/types/helpers/http.d.ts +18 -0
- package/dist/types/helpers/http.d.ts.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types/client.d.ts +19 -0
- package/dist/types/types/client.d.ts.map +1 -0
- package/dist/types/types/fraud-analysis.d.ts +12 -0
- package/dist/types/types/fraud-analysis.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +6 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/payment.d.ts +114 -0
- package/dist/types/types/payment.d.ts.map +1 -0
- package/dist/types/types/three-ds.d.ts +69 -0
- package/dist/types/types/three-ds.d.ts.map +1 -0
- package/dist/types/types/tokenizer.d.ts +18 -0
- package/dist/types/types/tokenizer.d.ts.map +1 -0
- package/dist/types/utils/browser.d.ts +17 -0
- package/dist/types/utils/browser.d.ts.map +1 -0
- package/dist/types/utils/logger.d.ts +8 -0
- package/dist/types/utils/logger.d.ts.map +1 -0
- package/dist/types/utils/modal.d.ts +11 -0
- package/dist/types/utils/modal.d.ts.map +1 -0
- package/dist/types/utils/validator.d.ts +3 -0
- package/dist/types/utils/validator.d.ts.map +1 -0
- package/dist/umd/index.js +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";class e extends Error{constructor(t){super(t),this.name="AccithusError",Object.setPrototypeOf(this,e.prototype)}}class t extends e{constructor(e="Invalid public key"){super(e),this.name="AuthenticationError",Object.setPrototypeOf(this,t.prototype)}}class i extends e{constructor(e,t){super(t),this.name="ValidationError",this.field=e,Object.setPrototypeOf(this,i.prototype)}}class r extends e{constructor(e,t,i){super(i),this.name="ApiError",this.status=e,this.code=t,Object.setPrototypeOf(this,r.prototype)}}class s extends e{constructor(e="Network error"){super(e),this.name="NetworkError",Object.setPrototypeOf(this,s.prototype)}}class o extends e{constructor(e="Request timed out"){super(e),this.name="TimeoutError",Object.setPrototypeOf(this,o.prototype)}}class n extends e{constructor(e,t){super(t),this.name="ThreeDSError",this.status=e,Object.setPrototypeOf(this,n.prototype)}}class a{constructor(e){this.config=e}async get(e){return this.request("GET",e)}async post(e,t){return this.request("POST",e,t)}async request(e,i,n){const a=`${this.config.baseUrl}${i}`,c={"Content-Type":"application/json",Authorization:`Basic ${function(e){if("function"==typeof btoa)return btoa(e);const t=globalThis.Buffer;if(t)return t.from(e).toString("base64");throw new Error("No base64 encoding available")}(`${this.config.publicKey}:`)}`};let d=null;const u=this.config.retries+1;for(let l=1;l<=u;l++)try{const o=new AbortController,p=setTimeout(()=>o.abort(),this.config.timeout);this.config.logger.debug(`${e} ${i}`,{attempt:l});const h=await fetch(a,{method:e,headers:c,body:n?JSON.stringify(n):void 0,signal:o.signal});let m;clearTimeout(p);try{m=await h.json()}catch{if(!h.ok)throw new r(h.status,"PARSE_ERROR",`HTTP ${h.status} (non-JSON response)`);throw new s("Failed to parse response")}if(!h.ok){if(401===h.status)throw new t(m.message||"Invalid public key");const e=new r(h.status,m.error||"UNKNOWN_ERROR",m.message||`HTTP ${h.status} error`);if(h.status>=500&&l<u){d=e,await this.backoff(l);continue}throw e}return m.data}catch(e){if(e instanceof t||e instanceof r)throw e;if(d=e instanceof DOMException&&"AbortError"===e.name?new o(`Request timed out after ${this.config.timeout}ms`):new s(e instanceof Error?e.message:"Network error"),l<u){await this.backoff(l);continue}}throw d||new s("Request failed")}async backoff(e){const t=Math.min(1e3*Math.pow(2,e-1),1e4);this.config.logger.debug(`Retrying in ${t}ms (attempt ${e})`),await new Promise(e=>setTimeout(e,t))}}class c{constructor(e=!1){this.enabled=e}debug(e,t){this.enabled&&console.log(`[Accithus SDK] ${e}`,t??"")}warn(e,t){this.enabled&&console.warn(`[Accithus SDK] ${e}`,t??"")}error(e,t){console.error(`[Accithus SDK] ${e}`,t??"")}}class d{static collectBrowserInfo(e=""){return{user_agent:"undefined"!=typeof navigator?navigator.userAgent:"",ip_address:e,language:"undefined"!=typeof navigator&&navigator.language||"",timezone_offset:(new Date).getTimezoneOffset(),screen_width:"undefined"!=typeof screen?screen.width:0,screen_height:"undefined"!=typeof screen?screen.height:0,color_depth:"undefined"!=typeof screen?screen.colorDepth:0,java_enabled:!1,javascript_enabled:!0}}static async getPublicIP(){try{const e=new AbortController,t=setTimeout(()=>e.abort(),3e3),i=await fetch("https://api.ipify.org?format=json",{signal:e.signal});clearTimeout(t);return(await i.json()).ip}catch{return""}}static async collectBrowserInfoWithIP(){const e=await d.getPublicIP();return d.collectBrowserInfo(e)}}const u={BRL:"986",USD:"840",EUR:"978",ARS:"032",GBP:"826"};class l{constructor(e,t,i){this.http=e,this.logger=t,this.readyCheck=i}async authenticate(t,r){if(!this.readyCheck())throw new e("SDK not initialized. Call client.initialize() first.");if(!t.card?.number||t.card.number.length<13)throw new i("card.number","Card number must be at least 13 digits");if(!t.card?.expirationMonth||!t.card?.expirationYear)throw new i("card","Expiration month and year are required");if(!t.customer?.name||!t.customer?.email)throw new i("customer","Customer name and email are required");if(!t.amount||t.amount<=0)throw new i("amount","Amount must be greater than 0");this.logger.debug("Starting 3DS authentication via BP.Mpi");try{const e=await d.collectBrowserInfoWithIP();this.logger.debug("Browser info collected",{ip:e.ip_address});const i=await this.http.post("/3ds/sessions",{amount:t.amount,currency:t.currency,card_bin:t.card.number.slice(0,6),expiration_month:t.card.expirationMonth,expiration_year:t.card.expirationYear,customer:{name:t.customer.name,email:t.customer.email,phone:t.customer.phone},address:t.address?{street:t.address.street,number:t.address.number,zip_code:t.address.zipCode,neighborhood:t.address.neighborhood,city:t.address.city,state:t.address.state,country:t.address.country}:void 0,browser_info:e});if(this.logger.debug("3DS session created",{sessionId:i.session_id,status:i.status,hasAuthConfig:!!i.auth_config}),"authenticated"===i.status)return{status:"authenticated",cavv:i.cavv,eci:i.eci,xid:i.xid,version:i.version,referenceId:i.reference_id};if(!i.auth_config)return this.logger.error("3DS session missing auth_config"),{status:"error"};const s=await this.authenticateWithBpMpi(t,i,r,e.ip_address),o={status:s.status};s.cavv&&(o.cavv=s.cavv),s.eci&&(o.eci=s.eci),s.xid&&(o.xid=s.xid),s.version&&(o.version=s.version),s.referenceId&&(o.reference_id=s.referenceId);const n=await this.http.post(`/3ds/sessions/${i.session_id}/fingerprinting`,o);return this.logger.debug("3DS result submitted to API",{status:n.status}),{status:s.status,cavv:s.cavv,eci:s.eci,xid:s.xid,version:s.version,referenceId:s.referenceId}}catch(e){if(e instanceof n)return{status:e.status};throw this.logger.error("3DS authentication failed",e),e}}authenticateWithBpMpi(e,t,i,r){const s=t.auth_config,o=i?.timeout??12e4;return new Promise((i,a)=>{let c=null,d=null,l=!1;const p=()=>{d&&(clearTimeout(d),d=null),c&&(c.remove(),c=null),delete window.bpmpi_config},h=e=>{l||(l=!0,p(),i(e))},m=e=>{l||(l=!0,p(),a(e))};d=setTimeout(()=>{m(new n("error","3DS authentication timed out"))},o),c=document.createElement("div"),c.style.cssText="position:absolute;left:-9999px;top:-9999px;width:0;height:0;overflow:hidden;";const g=e.currency?.toUpperCase()??"BRL",f=u[g]??"986",b=[["bpmpi_auth","true"],["bpmpi_accesstoken",s.access_token],["bpmpi_ordernumber",t.session_id],["bpmpi_currency",f],["bpmpi_totalamount",String(e.amount)],["bpmpi_paymentmethod","credit"],["bpmpi_cardnumber",e.card.number],["bpmpi_cardexpirationmonth",e.card.expirationMonth],["bpmpi_cardexpirationyear",e.card.expirationYear],["bpmpi_installments",String(e.installments??1)],["bpmpi_order_productcode","PHY"],["bpmpi_merchant_url",window.location.origin],["bpmpi_billto_contactname",e.customer.name],["bpmpi_billto_email",e.customer.email],["bpmpi_billto_phonenumber",e.customer.phone],["bpmpi_device_channel","Browser"],["bpmpi_device_ipaddress",r]];if(e.address){const t=e.address.number?`${e.address.street}, ${e.address.number}`:e.address.street,i=[e.address.complement,e.address.neighborhood].filter(Boolean).join(" - ");b.push(["bpmpi_billto_street1",t],...i?[["bpmpi_billto_street2",i]]:[],["bpmpi_billto_city",e.address.city],["bpmpi_billto_state",e.address.state],["bpmpi_billto_zipcode",e.address.zipCode],["bpmpi_billto_country",e.address.country||"BR"])}for(const[e,t]of b){const i=document.createElement("input");i.type="hidden",i.className=e,i.value=t,c.appendChild(i)}document.body.appendChild(c);window.bpmpi_config=e=>({Environment:s.environment,Debug:!1,onReady:()=>{this.logger.debug("BP.Mpi onReady — calling bpmpi_authenticate()");try{bpmpi_authenticate()}catch(e){this.logger.error("bpmpi_authenticate() call failed",e),m(new n("error","Failed to call bpmpi_authenticate()"))}},onSuccess:e=>{this.logger.debug("BP.Mpi onSuccess",{eci:e.Eci,version:e.Version}),h({status:"authenticated",cavv:e.Cavv,eci:e.Eci,xid:e.Xid,version:e.Version,referenceId:e.ReferenceId})},onFailure:e=>{this.logger.debug("BP.Mpi onFailure",{eci:e?.Eci,xid:e?.Xid,version:e?.Version}),h({status:"failed",eci:e?.Eci,xid:e?.Xid,version:e?.Version,referenceId:e?.ReferenceId})},onUnenrolled:e=>{this.logger.debug("BP.Mpi onUnenrolled",{eci:e?.Eci,xid:e?.Xid,version:e?.Version}),h({status:"unenrolled",eci:e?.Eci,xid:e?.Xid,version:e?.Version,referenceId:e?.ReferenceId})},onError:e=>{this.logger.error("BP.Mpi onError",{returnCode:e?.ReturnCode,returnMessage:e?.ReturnMessage,xid:e?.Xid}),h({status:"error",eci:e?.Eci,xid:e?.Xid,referenceId:e?.ReferenceId})},onUnsupportedBrand:e=>{this.logger.debug("BP.Mpi onUnsupportedBrand",{returnCode:e?.ReturnCode,returnMessage:e?.ReturnMessage}),h({status:"error"})},onDisabled:()=>{this.logger.debug("BP.Mpi onDisabled"),h({status:"error"})}}),this.loadScript(s.script_url).catch(e=>{this.logger.error("Failed to load BP.Mpi script",e),m(new n("error","Failed to load BP.Mpi script"))})})}loadScript(e){return new Promise((t,i)=>{try{const t=new URL(e);if(!l.TRUSTED_SCRIPT_ORIGINS.some(e=>t.origin===new URL(e).origin))return void i(new n("error",`Untrusted 3DS script origin: ${t.origin}`))}catch{return void i(new n("error","Invalid 3DS script URL"))}const r=document.querySelector(`script[src="${e}"]`);r&&r.remove();const s=document.createElement("script");s.src=e,s.async=!0,s.onload=()=>t(),s.onerror=()=>i(new n("error","Failed to load 3DS script")),document.head.appendChild(s)})}}l.TRUSTED_SCRIPT_ORIGINS=["https://mpisandbox.braspag.com.br","https://mpi.braspag.com.br"];class p{constructor(e,t,i){this.http=e,this.logger=t,this.readyCheck=i}async tokenize(t){if(!this.readyCheck())throw new e("SDK not initialized. Call client.initialize() first.");if(!t.card?.number||t.card.number.length<13)throw new i("card.number","Card number must be at least 13 digits");if(!t.card?.cvv||t.card.cvv.length<3)throw new i("card.cvv","CVV must be at least 3 digits");if(!t.card?.holderName)throw new i("card.holderName","Holder name is required");if(!t.card?.expirationMonth||!t.card?.expirationYear)throw new i("card","Expiration month and year are required");this.logger.debug("Tokenizing card",{lastFour:t.card.number.slice(-4)});const r=await this.http.post("/tokenize/",{card:{number:t.card.number,holder_name:t.card.holderName,expiration_month:t.card.expirationMonth,expiration_year:t.card.expirationYear,cvv:t.card.cvv}}),s={token:r.token,brand:r.brand,lastFourDigits:r.last_four_digits,firstSixDigits:r.first_six_digits,expirationMonth:r.expiration_month,expirationYear:r.expiration_year};return this.logger.debug("Card tokenized",{token:s.token,brand:s.brand}),s}}const h=[".online-metrix.net"];class m{constructor(e,t,i){this.http=e,this.logger=t,this.isReady=i}async setup(){if(!this.isReady())throw new i("setup","SDK must be initialized before calling setup()");this.logger.debug("Collecting browser data for fraud analysis");const e={ip_address:await d.getPublicIP(),type:this.getBrowserType(),host_name:"undefined"!=typeof window?window.location.hostname:"unknown",cookies_accepted:"undefined"!=typeof navigator&&navigator.cookieEnabled,user_agent:"undefined"!=typeof navigator?navigator.userAgent:void 0};this.logger.debug("Browser data collected",{browserData:e});const t=await this.http.post("/fraud/setup",{browser_data:e});return this.logger.debug("Fraud session created",{sessionId:t.session_id}),this.loadThreatMetrix(t.threat_metrix.org_id,t.threat_metrix.session_id,t.threat_metrix.script_url),{sessionId:t.session_id}}loadThreatMetrix(e,t,i){if("undefined"==typeof document)return;const r=`${i}?org_id=${e}&session_id=${t}`;let s=!1;try{const e=new URL(i);s=h.some(t=>e.hostname.endsWith(t))}catch{s=!1}if(!s)return void this.logger.warn("Skipping ThreatMetrix load: untrusted script URL",{scriptUrl:i});const o=document.createElement("script");o.src=r,o.async=!0,document.head.appendChild(o);const n=document.createElement("noscript"),a=document.createElement("iframe");a.src=`${i.replace("/tags.js","/tags")}?org_id=${e}&session_id=${t}`,a.style.cssText="width:100px;height:100px;border:0;position:absolute;top:-5000px;",n.appendChild(a),document.body.appendChild(n),this.logger.debug("ThreatMetrix script injected")}getBrowserType(){if("undefined"==typeof navigator)return"Unknown";const e=navigator.userAgent;return e.includes("Chrome")&&!e.includes("Edg")?"Chrome":e.includes("Firefox")?"Firefox":e.includes("Safari")&&!e.includes("Chrome")?"Safari":e.includes("Edg")?"Edge":e.includes("Opera")||e.includes("OPR")?"Opera":"Other"}}const g=()=>{};function f(e,t,i,r,s){return{success:!1,error:e,failedAt:t,partialResult:{...i},steps:r,durationMs:Date.now()-s}}exports.AccithusError=e,exports.ApiError=r,exports.AuthenticationError=t,exports.Client=class{constructor(e){this.config=null,this._ready=!1,this.initPromise=null,function(e){if(!e.publicKey||"string"!=typeof e.publicKey)throw new i("publicKey","publicKey is required and must be a string");if(!e.publicKey.startsWith("pk_"))throw new i("publicKey",'publicKey must start with "pk_"');if(e.publicKey.length<10)throw new i("publicKey","publicKey must be at least 10 characters");if(void 0!==e.timeout&&("number"!=typeof e.timeout||e.timeout<1e3||e.timeout>6e4))throw new i("timeout","timeout must be between 1000 and 60000")}(e),this.options={publicKey:e.publicKey,debug:e.debug??!1,timeout:e.timeout??3e4,baseUrl:e.baseUrl},this.logger=new c(this.options.debug),this.http=new a({baseUrl:e.baseUrl??"https://api.accithus.com/v1/public/sdk",publicKey:this.options.publicKey,timeout:this.options.timeout,retries:3,logger:this.logger});const t=()=>this._ready;this.threeds=new l(this.http,this.logger,t),this.tokenizer=new p(this.http,this.logger,t),this.fraudAnalysis=new m(this.http,this.logger,t)}async initialize(){if(!this._ready){if(this.initPromise)return this.initPromise;this.initPromise=this._doInitialize();try{await this.initPromise}finally{this.initPromise=null}}}async _doInitialize(){this.logger.debug("Initializing SDK"),this.config=await this.http.get("/config/"),this._ready=!0,this.logger.debug("SDK initialized",{merchantId:this.config.merchant_id,capabilities:this.config.capabilities})}isReady(){return this._ready}isThreeDSAvailable(){return this._ready&&(this.config?.capabilities.threeds??!1)}isTokenizationAvailable(){return this._ready&&(this.config?.capabilities.tokenization??!1)}isFraudAnalysisAvailable(){return this._ready&&(this.config?.capabilities.fraud_analysis??!1)}getConfig(){return this.config}async preparePayment(e,t){const r=Date.now(),s=[],o=t?.onStepChange??g,n={};if(!e.card.holderName)throw new i("card.holderName","Nome do portador é obrigatório para o fluxo completo");if(!t?.skipFraudAnalysis&&this.isFraudAnalysisAvailable()){const e=await this.executeStep("fraud_analysis",async()=>{const e=await this.fraudAnalysis.setup();n.fraudSessionId=e.sessionId},s,o);if(!e.ok)return f(e.error,"fraud_analysis",n,s,r)}else s.push({step:"fraud_analysis",status:"skipped",durationMs:0}),o({step:"fraud_analysis",status:"skipped"});const a=await this.executeStep("tokenization",async()=>{const t=await this.tokenizer.tokenize({card:{number:e.card.number,holderName:e.card.holderName,expirationMonth:e.card.expirationMonth,expirationYear:e.card.expirationYear,cvv:e.card.cvv}});n.token=t.token,n.brand=t.brand,n.lastFourDigits=t.lastFourDigits,n.firstSixDigits=t.firstSixDigits},s,o);if(!a.ok)return f(a.error,"tokenization",n,s,r);let c;if(!t?.skipThreeDS&&this.isThreeDSAvailable()){const i=await this.executeStep("three_ds",async()=>{const i=await this.threeds.authenticate({amount:e.amount,currency:e.currency,installments:e.installments,card:{number:e.card.number,holderName:e.card.holderName,expirationMonth:e.card.expirationMonth,expirationYear:e.card.expirationYear},customer:e.customer,address:e.address},{timeout:t?.threeDSTimeout});if("failed"===i.status||"error"===i.status||"cancelled"===i.status){const e="failed"===i.status?"Autenticação negada pelo emissor":"cancelled"===i.status?"Autenticação cancelada":"Erro na autenticação 3DS";throw Object.assign(new Error(e),{threeDSStatus:i.status})}c={status:i.status,cavv:i.cavv,eci:i.eci,xid:i.xid,version:i.version,referenceId:i.referenceId}},s,o);if(!i.ok)return f(i.error,"three_ds",n,s,r)}else s.push({step:"three_ds",status:"skipped",durationMs:0}),o({step:"three_ds",status:"skipped"});return n.token&&n.brand&&n.lastFourDigits&&n.firstSixDigits?{success:!0,token:n.token,brand:n.brand,lastFourDigits:n.lastFourDigits,firstSixDigits:n.firstSixDigits,threeds:c,fraudSessionId:n.fraudSessionId,steps:s,durationMs:Date.now()-r}:f(new Error("Tokenization completed but returned incomplete data"),"tokenization",n,s,r)}async executeStep(e,t,i,r){const s=Date.now();r({step:e,status:"started"});try{await t();const o=Date.now()-s;return i.push({step:e,status:"completed",durationMs:o}),r({step:e,status:"completed"}),{ok:!0}}catch(t){const o=Date.now()-s,n=t instanceof Error?t:new Error(String(t));return this.logger.error(`Step "${e}" failed: ${n.message}`),i.push({step:e,status:"failed",durationMs:o}),r({step:e,status:"failed"}),{ok:!1,error:n}}}},exports.NetworkError=s,exports.ThreeDSError=n,exports.TimeoutError=o,exports.ValidationError=i;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/errors/index.ts","../../src/helpers/http.ts","../../src/utils/logger.ts","../../src/utils/browser.ts","../../src/controllers/three-ds.ts","../../src/controllers/tokenizer.ts","../../src/controllers/fraud-analysis.ts","../../src/client.ts","../../src/utils/validator.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null],"names":["AccithusError","Error","constructor","message","super","this","name","Object","setPrototypeOf","prototype","AuthenticationError","ValidationError","field","ApiError","status","code","NetworkError","TimeoutError","ThreeDSError","HttpHelper","config","get","path","request","post","body","method","url","baseUrl","headers","Authorization","str","btoa","B","globalThis","from","toString","toBase64","publicKey","lastError","maxAttempts","retries","attempt","controller","AbortController","timeoutId","setTimeout","abort","timeout","logger","debug","response","fetch","JSON","stringify","undefined","signal","responseData","clearTimeout","json","ok","error","backoff","data","DOMException","delay","Math","min","pow","Promise","resolve","Logger","enabled","console","log","warn","BrowserUtils","collectBrowserInfo","ipAddress","user_agent","navigator","userAgent","ip_address","language","timezone_offset","Date","getTimezoneOffset","screen_width","screen","width","screen_height","height","color_depth","colorDepth","java_enabled","javascript_enabled","getPublicIP","ip","collectBrowserInfoWithIP","CURRENCY_NUMERIC_CODES","BRL","USD","EUR","ARS","GBP","ThreeDSController","http","readyCheck","authenticate","options","card","number","length","expirationMonth","expirationYear","customer","email","amount","browserInfo","session","currency","card_bin","slice","expiration_month","expiration_year","phone","address","street","zip_code","zipCode","neighborhood","city","state","country","browser_info","sessionId","session_id","hasAuthConfig","auth_config","cavv","eci","xid","version","referenceId","reference_id","bpMpiResult","authenticateWithBpMpi","fingerprintingBody","fingerprintingResponse","authConfig","reject","container","settled","cleanup","remove","window","bpmpi_config","settle","result","settleError","document","createElement","style","cssText","currencyCode","toUpperCase","numericCurrency","fields","access_token","String","installments","location","origin","street1","street2","complement","filter","Boolean","join","push","className","value","input","type","appendChild","_setupCallId","Environment","environment","Debug","onReady","bpmpi_authenticate","err","onSuccess","Eci","Version","Cavv","Xid","ReferenceId","onFailure","e","onUnenrolled","onError","returnCode","ReturnCode","returnMessage","ReturnMessage","onUnsupportedBrand","onDisabled","loadScript","script_url","catch","parsed","URL","TRUSTED_SCRIPT_ORIGINS","some","existing","querySelector","script","src","async","onload","onerror","head","TokenizerController","tokenize","cvv","holderName","lastFour","apiResponse","holder_name","token","brand","lastFourDigits","last_four_digits","firstSixDigits","first_six_digits","TRUSTED_TM_ORIGINS","FraudAnalysisController","isReady","setup","browserData","getBrowserType","host_name","hostname","cookies_accepted","cookieEnabled","browser_data","loadThreatMetrix","threat_metrix","org_id","orgId","scriptUrl","fullUrl","isTrusted","parsedUrl","endsWith","noscript","iframe","replace","ua","includes","noop","buildFailure","failedAt","partial","steps","flowStart","success","partialResult","durationMs","now","_ready","initPromise","startsWith","validateClientOptions","threeds","tokenizer","fraudAnalysis","initialize","_doInitialize","merchantId","merchant_id","capabilities","isThreeDSAvailable","isTokenizationAvailable","tokenization","isFraudAnalysisAvailable","fraud_analysis","getConfig","preparePayment","notify","onStepChange","skipFraudAnalysis","executeStep","fraud","fraudSessionId","step","tokenResult","tokenized","threeDSData","skipThreeDS","threeDSResult","auth","threeDSTimeout","msg","assign","threeDSStatus","fn","start","wrappedError"],"mappings":"aAAM,MAAOA,UAAsBC,MACjC,WAAAC,CAAYC,GACVC,MAAMD,GACNE,KAAKC,KAAO,gBACZC,OAAOC,eAAeH,KAAML,EAAcS,UAC5C,EAGI,MAAOC,UAA4BV,EACvC,WAAAE,CAAYC,EAAkB,sBAC5BC,MAAMD,GACNE,KAAKC,KAAO,sBACZC,OAAOC,eAAeH,KAAMK,EAAoBD,UAClD,EAGI,MAAOE,UAAwBX,EAEnC,WAAAE,CAAYU,EAAeT,GACzBC,MAAMD,GACNE,KAAKC,KAAO,kBACZD,KAAKO,MAAQA,EACbL,OAAOC,eAAeH,KAAMM,EAAg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AAchP,MAAO,WAAY2M,EAASC,EAAOC,EAEzE,MACED,EAAMtF,KAAK,CAAEqH,KAAM,WAAY1R,OAAQ,UAAW+P,WAAY,IAC9DqB,EAAO,CAAEM,KAAM,WAAY1R,OAAQ,YAIrC,OAAK0P,EAAQlC,OAAUkC,EAAQjC,OAAUiC,EAAQhC,gBAAmBgC,EAAQ9B,eAUrE,CACLiC,SAAS,EACTrC,MAAOkC,EAAQlC,MACfC,MAAOiC,EAAQjC,MACfC,eAAgBgC,EAAQhC,eACxBE,eAAgB8B,EAAQ9B,eACxByC,QAASwB,EACTJ,eAAgB/B,EAAQ+B,eACxB9B,QACAI,WAAYxL,KAAKyL,MAAQJ,GAlBlBJ,EACL,IAAIrQ,MAAM,uDACV,eACAuQ,EACAC,EACAC,EAeN,CAMQ,iBAAM2B,CACZG,EACAW,EACA1C,EACAyB,GAEA,MAAMkB,EAAQ/N,KAAKyL,MACnBoB,EAAO,CAAEM,OAAM1R,OAAQ,YACvB,UACQqS,IACN,MAAMtC,EAAaxL,KAAKyL,MAAQsC,EAGhC,OAFA3C,EAAMtF,KAAK,CAAEqH,OAAM1R,OAAQ,YAAa+P,eACxCqB,EAAO,CAAEM,OAAM1R,OAAQ,cAChB,CAAE8C,IAAI,EACf,CAAE,MAAOC,GACP,MAAMgN,EAAaxL,KAAKyL,MAAQsC,EAC1BC,EAAexP,aAAiB5D,MAAQ4D,EAAQ,IAAI5D,MAAMwK,OAAO5G,IAIvE,OAHAxD,KAAK4C,OAAOY,MAAM,SAAS2O,cAAiBa,EAAalT,WACzDsQ,EAAMtF,KAAK,CAAEqH,OAAM1R,OAAQ,SAAU+P,eACrCqB,EAAO,CAAEM,OAAM1R,OAAQ,WAChB,CAAE8C,IAAI,EAAOC,MAAOwP,EAC7B,CACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
class e extends Error{constructor(t){super(t),this.name="AccithusError",Object.setPrototypeOf(this,e.prototype)}}class t extends e{constructor(e="Invalid public key"){super(e),this.name="AuthenticationError",Object.setPrototypeOf(this,t.prototype)}}class i extends e{constructor(e,t){super(t),this.name="ValidationError",this.field=e,Object.setPrototypeOf(this,i.prototype)}}class r extends e{constructor(e,t,i){super(i),this.name="ApiError",this.status=e,this.code=t,Object.setPrototypeOf(this,r.prototype)}}class s extends e{constructor(e="Network error"){super(e),this.name="NetworkError",Object.setPrototypeOf(this,s.prototype)}}class o extends e{constructor(e="Request timed out"){super(e),this.name="TimeoutError",Object.setPrototypeOf(this,o.prototype)}}class n extends e{constructor(e,t){super(t),this.name="ThreeDSError",this.status=e,Object.setPrototypeOf(this,n.prototype)}}class a{constructor(e){this.config=e}async get(e){return this.request("GET",e)}async post(e,t){return this.request("POST",e,t)}async request(e,i,n){const a=`${this.config.baseUrl}${i}`,c={"Content-Type":"application/json",Authorization:`Basic ${function(e){if("function"==typeof btoa)return btoa(e);const t=globalThis.Buffer;if(t)return t.from(e).toString("base64");throw new Error("No base64 encoding available")}(`${this.config.publicKey}:`)}`};let d=null;const u=this.config.retries+1;for(let l=1;l<=u;l++)try{const o=new AbortController,p=setTimeout(()=>o.abort(),this.config.timeout);this.config.logger.debug(`${e} ${i}`,{attempt:l});const h=await fetch(a,{method:e,headers:c,body:n?JSON.stringify(n):void 0,signal:o.signal});let m;clearTimeout(p);try{m=await h.json()}catch{if(!h.ok)throw new r(h.status,"PARSE_ERROR",`HTTP ${h.status} (non-JSON response)`);throw new s("Failed to parse response")}if(!h.ok){if(401===h.status)throw new t(m.message||"Invalid public key");const e=new r(h.status,m.error||"UNKNOWN_ERROR",m.message||`HTTP ${h.status} error`);if(h.status>=500&&l<u){d=e,await this.backoff(l);continue}throw e}return m.data}catch(e){if(e instanceof t||e instanceof r)throw e;if(d=e instanceof DOMException&&"AbortError"===e.name?new o(`Request timed out after ${this.config.timeout}ms`):new s(e instanceof Error?e.message:"Network error"),l<u){await this.backoff(l);continue}}throw d||new s("Request failed")}async backoff(e){const t=Math.min(1e3*Math.pow(2,e-1),1e4);this.config.logger.debug(`Retrying in ${t}ms (attempt ${e})`),await new Promise(e=>setTimeout(e,t))}}class c{constructor(e=!1){this.enabled=e}debug(e,t){this.enabled&&console.log(`[Accithus SDK] ${e}`,t??"")}warn(e,t){this.enabled&&console.warn(`[Accithus SDK] ${e}`,t??"")}error(e,t){console.error(`[Accithus SDK] ${e}`,t??"")}}class d{static collectBrowserInfo(e=""){return{user_agent:"undefined"!=typeof navigator?navigator.userAgent:"",ip_address:e,language:"undefined"!=typeof navigator&&navigator.language||"",timezone_offset:(new Date).getTimezoneOffset(),screen_width:"undefined"!=typeof screen?screen.width:0,screen_height:"undefined"!=typeof screen?screen.height:0,color_depth:"undefined"!=typeof screen?screen.colorDepth:0,java_enabled:!1,javascript_enabled:!0}}static async getPublicIP(){try{const e=new AbortController,t=setTimeout(()=>e.abort(),3e3),i=await fetch("https://api.ipify.org?format=json",{signal:e.signal});clearTimeout(t);return(await i.json()).ip}catch{return""}}static async collectBrowserInfoWithIP(){const e=await d.getPublicIP();return d.collectBrowserInfo(e)}}const u={BRL:"986",USD:"840",EUR:"978",ARS:"032",GBP:"826"};class l{constructor(e,t,i){this.http=e,this.logger=t,this.readyCheck=i}async authenticate(t,r){if(!this.readyCheck())throw new e("SDK not initialized. Call client.initialize() first.");if(!t.card?.number||t.card.number.length<13)throw new i("card.number","Card number must be at least 13 digits");if(!t.card?.expirationMonth||!t.card?.expirationYear)throw new i("card","Expiration month and year are required");if(!t.customer?.name||!t.customer?.email)throw new i("customer","Customer name and email are required");if(!t.amount||t.amount<=0)throw new i("amount","Amount must be greater than 0");this.logger.debug("Starting 3DS authentication via BP.Mpi");try{const e=await d.collectBrowserInfoWithIP();this.logger.debug("Browser info collected",{ip:e.ip_address});const i=await this.http.post("/3ds/sessions",{amount:t.amount,currency:t.currency,card_bin:t.card.number.slice(0,6),expiration_month:t.card.expirationMonth,expiration_year:t.card.expirationYear,customer:{name:t.customer.name,email:t.customer.email,phone:t.customer.phone},address:t.address?{street:t.address.street,number:t.address.number,zip_code:t.address.zipCode,neighborhood:t.address.neighborhood,city:t.address.city,state:t.address.state,country:t.address.country}:void 0,browser_info:e});if(this.logger.debug("3DS session created",{sessionId:i.session_id,status:i.status,hasAuthConfig:!!i.auth_config}),"authenticated"===i.status)return{status:"authenticated",cavv:i.cavv,eci:i.eci,xid:i.xid,version:i.version,referenceId:i.reference_id};if(!i.auth_config)return this.logger.error("3DS session missing auth_config"),{status:"error"};const s=await this.authenticateWithBpMpi(t,i,r,e.ip_address),o={status:s.status};s.cavv&&(o.cavv=s.cavv),s.eci&&(o.eci=s.eci),s.xid&&(o.xid=s.xid),s.version&&(o.version=s.version),s.referenceId&&(o.reference_id=s.referenceId);const n=await this.http.post(`/3ds/sessions/${i.session_id}/fingerprinting`,o);return this.logger.debug("3DS result submitted to API",{status:n.status}),{status:s.status,cavv:s.cavv,eci:s.eci,xid:s.xid,version:s.version,referenceId:s.referenceId}}catch(e){if(e instanceof n)return{status:e.status};throw this.logger.error("3DS authentication failed",e),e}}authenticateWithBpMpi(e,t,i,r){const s=t.auth_config,o=i?.timeout??12e4;return new Promise((i,a)=>{let c=null,d=null,l=!1;const p=()=>{d&&(clearTimeout(d),d=null),c&&(c.remove(),c=null),delete window.bpmpi_config},h=e=>{l||(l=!0,p(),i(e))},m=e=>{l||(l=!0,p(),a(e))};d=setTimeout(()=>{m(new n("error","3DS authentication timed out"))},o),c=document.createElement("div"),c.style.cssText="position:absolute;left:-9999px;top:-9999px;width:0;height:0;overflow:hidden;";const g=e.currency?.toUpperCase()??"BRL",f=u[g]??"986",b=[["bpmpi_auth","true"],["bpmpi_accesstoken",s.access_token],["bpmpi_ordernumber",t.session_id],["bpmpi_currency",f],["bpmpi_totalamount",String(e.amount)],["bpmpi_paymentmethod","credit"],["bpmpi_cardnumber",e.card.number],["bpmpi_cardexpirationmonth",e.card.expirationMonth],["bpmpi_cardexpirationyear",e.card.expirationYear],["bpmpi_installments",String(e.installments??1)],["bpmpi_order_productcode","PHY"],["bpmpi_merchant_url",window.location.origin],["bpmpi_billto_contactname",e.customer.name],["bpmpi_billto_email",e.customer.email],["bpmpi_billto_phonenumber",e.customer.phone],["bpmpi_device_channel","Browser"],["bpmpi_device_ipaddress",r]];if(e.address){const t=e.address.number?`${e.address.street}, ${e.address.number}`:e.address.street,i=[e.address.complement,e.address.neighborhood].filter(Boolean).join(" - ");b.push(["bpmpi_billto_street1",t],...i?[["bpmpi_billto_street2",i]]:[],["bpmpi_billto_city",e.address.city],["bpmpi_billto_state",e.address.state],["bpmpi_billto_zipcode",e.address.zipCode],["bpmpi_billto_country",e.address.country||"BR"])}for(const[e,t]of b){const i=document.createElement("input");i.type="hidden",i.className=e,i.value=t,c.appendChild(i)}document.body.appendChild(c);window.bpmpi_config=e=>({Environment:s.environment,Debug:!1,onReady:()=>{this.logger.debug("BP.Mpi onReady — calling bpmpi_authenticate()");try{bpmpi_authenticate()}catch(e){this.logger.error("bpmpi_authenticate() call failed",e),m(new n("error","Failed to call bpmpi_authenticate()"))}},onSuccess:e=>{this.logger.debug("BP.Mpi onSuccess",{eci:e.Eci,version:e.Version}),h({status:"authenticated",cavv:e.Cavv,eci:e.Eci,xid:e.Xid,version:e.Version,referenceId:e.ReferenceId})},onFailure:e=>{this.logger.debug("BP.Mpi onFailure",{eci:e?.Eci,xid:e?.Xid,version:e?.Version}),h({status:"failed",eci:e?.Eci,xid:e?.Xid,version:e?.Version,referenceId:e?.ReferenceId})},onUnenrolled:e=>{this.logger.debug("BP.Mpi onUnenrolled",{eci:e?.Eci,xid:e?.Xid,version:e?.Version}),h({status:"unenrolled",eci:e?.Eci,xid:e?.Xid,version:e?.Version,referenceId:e?.ReferenceId})},onError:e=>{this.logger.error("BP.Mpi onError",{returnCode:e?.ReturnCode,returnMessage:e?.ReturnMessage,xid:e?.Xid}),h({status:"error",eci:e?.Eci,xid:e?.Xid,referenceId:e?.ReferenceId})},onUnsupportedBrand:e=>{this.logger.debug("BP.Mpi onUnsupportedBrand",{returnCode:e?.ReturnCode,returnMessage:e?.ReturnMessage}),h({status:"error"})},onDisabled:()=>{this.logger.debug("BP.Mpi onDisabled"),h({status:"error"})}}),this.loadScript(s.script_url).catch(e=>{this.logger.error("Failed to load BP.Mpi script",e),m(new n("error","Failed to load BP.Mpi script"))})})}loadScript(e){return new Promise((t,i)=>{try{const t=new URL(e);if(!l.TRUSTED_SCRIPT_ORIGINS.some(e=>t.origin===new URL(e).origin))return void i(new n("error",`Untrusted 3DS script origin: ${t.origin}`))}catch{return void i(new n("error","Invalid 3DS script URL"))}const r=document.querySelector(`script[src="${e}"]`);r&&r.remove();const s=document.createElement("script");s.src=e,s.async=!0,s.onload=()=>t(),s.onerror=()=>i(new n("error","Failed to load 3DS script")),document.head.appendChild(s)})}}l.TRUSTED_SCRIPT_ORIGINS=["https://mpisandbox.braspag.com.br","https://mpi.braspag.com.br"];class p{constructor(e,t,i){this.http=e,this.logger=t,this.readyCheck=i}async tokenize(t){if(!this.readyCheck())throw new e("SDK not initialized. Call client.initialize() first.");if(!t.card?.number||t.card.number.length<13)throw new i("card.number","Card number must be at least 13 digits");if(!t.card?.cvv||t.card.cvv.length<3)throw new i("card.cvv","CVV must be at least 3 digits");if(!t.card?.holderName)throw new i("card.holderName","Holder name is required");if(!t.card?.expirationMonth||!t.card?.expirationYear)throw new i("card","Expiration month and year are required");this.logger.debug("Tokenizing card",{lastFour:t.card.number.slice(-4)});const r=await this.http.post("/tokenize/",{card:{number:t.card.number,holder_name:t.card.holderName,expiration_month:t.card.expirationMonth,expiration_year:t.card.expirationYear,cvv:t.card.cvv}}),s={token:r.token,brand:r.brand,lastFourDigits:r.last_four_digits,firstSixDigits:r.first_six_digits,expirationMonth:r.expiration_month,expirationYear:r.expiration_year};return this.logger.debug("Card tokenized",{token:s.token,brand:s.brand}),s}}const h=[".online-metrix.net"];class m{constructor(e,t,i){this.http=e,this.logger=t,this.isReady=i}async setup(){if(!this.isReady())throw new i("setup","SDK must be initialized before calling setup()");this.logger.debug("Collecting browser data for fraud analysis");const e={ip_address:await d.getPublicIP(),type:this.getBrowserType(),host_name:"undefined"!=typeof window?window.location.hostname:"unknown",cookies_accepted:"undefined"!=typeof navigator&&navigator.cookieEnabled,user_agent:"undefined"!=typeof navigator?navigator.userAgent:void 0};this.logger.debug("Browser data collected",{browserData:e});const t=await this.http.post("/fraud/setup",{browser_data:e});return this.logger.debug("Fraud session created",{sessionId:t.session_id}),this.loadThreatMetrix(t.threat_metrix.org_id,t.threat_metrix.session_id,t.threat_metrix.script_url),{sessionId:t.session_id}}loadThreatMetrix(e,t,i){if("undefined"==typeof document)return;const r=`${i}?org_id=${e}&session_id=${t}`;let s=!1;try{const e=new URL(i);s=h.some(t=>e.hostname.endsWith(t))}catch{s=!1}if(!s)return void this.logger.warn("Skipping ThreatMetrix load: untrusted script URL",{scriptUrl:i});const o=document.createElement("script");o.src=r,o.async=!0,document.head.appendChild(o);const n=document.createElement("noscript"),a=document.createElement("iframe");a.src=`${i.replace("/tags.js","/tags")}?org_id=${e}&session_id=${t}`,a.style.cssText="width:100px;height:100px;border:0;position:absolute;top:-5000px;",n.appendChild(a),document.body.appendChild(n),this.logger.debug("ThreatMetrix script injected")}getBrowserType(){if("undefined"==typeof navigator)return"Unknown";const e=navigator.userAgent;return e.includes("Chrome")&&!e.includes("Edg")?"Chrome":e.includes("Firefox")?"Firefox":e.includes("Safari")&&!e.includes("Chrome")?"Safari":e.includes("Edg")?"Edge":e.includes("Opera")||e.includes("OPR")?"Opera":"Other"}}const g=()=>{};function f(e,t,i,r,s){return{success:!1,error:e,failedAt:t,partialResult:{...i},steps:r,durationMs:Date.now()-s}}class b{constructor(e){this.config=null,this._ready=!1,this.initPromise=null,function(e){if(!e.publicKey||"string"!=typeof e.publicKey)throw new i("publicKey","publicKey is required and must be a string");if(!e.publicKey.startsWith("pk_"))throw new i("publicKey",'publicKey must start with "pk_"');if(e.publicKey.length<10)throw new i("publicKey","publicKey must be at least 10 characters");if(void 0!==e.timeout&&("number"!=typeof e.timeout||e.timeout<1e3||e.timeout>6e4))throw new i("timeout","timeout must be between 1000 and 60000")}(e),this.options={publicKey:e.publicKey,debug:e.debug??!1,timeout:e.timeout??3e4,baseUrl:e.baseUrl},this.logger=new c(this.options.debug),this.http=new a({baseUrl:e.baseUrl??"https://api.accithus.com/v1/public/sdk",publicKey:this.options.publicKey,timeout:this.options.timeout,retries:3,logger:this.logger});const t=()=>this._ready;this.threeds=new l(this.http,this.logger,t),this.tokenizer=new p(this.http,this.logger,t),this.fraudAnalysis=new m(this.http,this.logger,t)}async initialize(){if(!this._ready){if(this.initPromise)return this.initPromise;this.initPromise=this._doInitialize();try{await this.initPromise}finally{this.initPromise=null}}}async _doInitialize(){this.logger.debug("Initializing SDK"),this.config=await this.http.get("/config/"),this._ready=!0,this.logger.debug("SDK initialized",{merchantId:this.config.merchant_id,capabilities:this.config.capabilities})}isReady(){return this._ready}isThreeDSAvailable(){return this._ready&&(this.config?.capabilities.threeds??!1)}isTokenizationAvailable(){return this._ready&&(this.config?.capabilities.tokenization??!1)}isFraudAnalysisAvailable(){return this._ready&&(this.config?.capabilities.fraud_analysis??!1)}getConfig(){return this.config}async preparePayment(e,t){const r=Date.now(),s=[],o=t?.onStepChange??g,n={};if(!e.card.holderName)throw new i("card.holderName","Nome do portador é obrigatório para o fluxo completo");if(!t?.skipFraudAnalysis&&this.isFraudAnalysisAvailable()){const e=await this.executeStep("fraud_analysis",async()=>{const e=await this.fraudAnalysis.setup();n.fraudSessionId=e.sessionId},s,o);if(!e.ok)return f(e.error,"fraud_analysis",n,s,r)}else s.push({step:"fraud_analysis",status:"skipped",durationMs:0}),o({step:"fraud_analysis",status:"skipped"});const a=await this.executeStep("tokenization",async()=>{const t=await this.tokenizer.tokenize({card:{number:e.card.number,holderName:e.card.holderName,expirationMonth:e.card.expirationMonth,expirationYear:e.card.expirationYear,cvv:e.card.cvv}});n.token=t.token,n.brand=t.brand,n.lastFourDigits=t.lastFourDigits,n.firstSixDigits=t.firstSixDigits},s,o);if(!a.ok)return f(a.error,"tokenization",n,s,r);let c;if(!t?.skipThreeDS&&this.isThreeDSAvailable()){const i=await this.executeStep("three_ds",async()=>{const i=await this.threeds.authenticate({amount:e.amount,currency:e.currency,installments:e.installments,card:{number:e.card.number,holderName:e.card.holderName,expirationMonth:e.card.expirationMonth,expirationYear:e.card.expirationYear},customer:e.customer,address:e.address},{timeout:t?.threeDSTimeout});if("failed"===i.status||"error"===i.status||"cancelled"===i.status){const e="failed"===i.status?"Autenticação negada pelo emissor":"cancelled"===i.status?"Autenticação cancelada":"Erro na autenticação 3DS";throw Object.assign(new Error(e),{threeDSStatus:i.status})}c={status:i.status,cavv:i.cavv,eci:i.eci,xid:i.xid,version:i.version,referenceId:i.referenceId}},s,o);if(!i.ok)return f(i.error,"three_ds",n,s,r)}else s.push({step:"three_ds",status:"skipped",durationMs:0}),o({step:"three_ds",status:"skipped"});return n.token&&n.brand&&n.lastFourDigits&&n.firstSixDigits?{success:!0,token:n.token,brand:n.brand,lastFourDigits:n.lastFourDigits,firstSixDigits:n.firstSixDigits,threeds:c,fraudSessionId:n.fraudSessionId,steps:s,durationMs:Date.now()-r}:f(new Error("Tokenization completed but returned incomplete data"),"tokenization",n,s,r)}async executeStep(e,t,i,r){const s=Date.now();r({step:e,status:"started"});try{await t();const o=Date.now()-s;return i.push({step:e,status:"completed",durationMs:o}),r({step:e,status:"completed"}),{ok:!0}}catch(t){const o=Date.now()-s,n=t instanceof Error?t:new Error(String(t));return this.logger.error(`Step "${e}" failed: ${n.message}`),i.push({step:e,status:"failed",durationMs:o}),r({step:e,status:"failed"}),{ok:!1,error:n}}}}export{e as AccithusError,r as ApiError,t as AuthenticationError,b as Client,s as NetworkError,n as ThreeDSError,o as TimeoutError,i as ValidationError};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/errors/index.ts","../../src/helpers/http.ts","../../src/utils/logger.ts","../../src/utils/browser.ts","../../src/controllers/three-ds.ts","../../src/controllers/tokenizer.ts","../../src/controllers/fraud-analysis.ts","../../src/client.ts","../../src/utils/validator.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null],"names":["AccithusError","Error","constructor","message","super","this","name","Object","setPrototypeOf","prototype","AuthenticationError","ValidationError","field","ApiError","status","code","NetworkError","TimeoutError","ThreeDSError","HttpHelper","config","get","path","request","post","body","method","url","baseUrl","headers","Authorization","str","btoa","B","globalThis","from","toString","toBase64","publicKey","lastError","maxAttempts","retries","attempt","controller","AbortController","timeoutId","setTimeout","abort","timeout","logger","debug","response","fetch","JSON","stringify","undefined","signal","responseData","clearTimeout","json","ok","error","backoff","data","DOMException","delay","Math","min","pow","Promise","resolve","Logger","enabled","console","log","warn","BrowserUtils","collectBrowserInfo","ipAddress","user_agent","navigator","userAgent","ip_address","language","timezone_offset","Date","getTimezoneOffset","screen_width","screen","width","screen_height","height","color_depth","colorDepth","java_enabled","javascript_enabled","getPublicIP","ip","collectBrowserInfoWithIP","CURRENCY_NUMERIC_CODES","BRL","USD","EUR","ARS","GBP","ThreeDSController","http","readyCheck","authenticate","options","card","number","length","expirationMonth","expirationYear","customer","email","amount","browserInfo","session","currency","card_bin","slice","expiration_month","expiration_year","phone","address","street","zip_code","zipCode","neighborhood","city","state","country","browser_info","sessionId","session_id","hasAuthConfig","auth_config","cavv","eci","xid","version","referenceId","reference_id","bpMpiResult","authenticateWithBpMpi","fingerprintingBody","fingerprintingResponse","authConfig","reject","container","settled","cleanup","remove","window","bpmpi_config","settle","result","settleError","document","createElement","style","cssText","currencyCode","toUpperCase","numericCurrency","fields","access_token","String","installments","location","origin","street1","street2","complement","filter","Boolean","join","push","className","value","input","type","appendChild","_setupCallId","Environment","environment","Debug","onReady","bpmpi_authenticate","err","onSuccess","Eci","Version","Cavv","Xid","ReferenceId","onFailure","e","onUnenrolled","onError","returnCode","ReturnCode","returnMessage","ReturnMessage","onUnsupportedBrand","onDisabled","loadScript","script_url","catch","parsed","URL","TRUSTED_SCRIPT_ORIGINS","some","existing","querySelector","script","src","async","onload","onerror","head","TokenizerController","tokenize","cvv","holderName","lastFour","apiResponse","holder_name","token","brand","lastFourDigits","last_four_digits","firstSixDigits","first_six_digits","TRUSTED_TM_ORIGINS","FraudAnalysisController","isReady","setup","browserData","getBrowserType","host_name","hostname","cookies_accepted","cookieEnabled","browser_data","loadThreatMetrix","threat_metrix","org_id","orgId","scriptUrl","fullUrl","isTrusted","parsedUrl","endsWith","noscript","iframe","replace","ua","includes","noop","buildFailure","failedAt","partial","steps","flowStart","success","partialResult","durationMs","now","Client","_ready","initPromise","startsWith","validateClientOptions","threeds","tokenizer","fraudAnalysis","initialize","_doInitialize","merchantId","merchant_id","capabilities","isThreeDSAvailable","isTokenizationAvailable","tokenization","isFraudAnalysisAvailable","fraud_analysis","getConfig","preparePayment","notify","onStepChange","skipFraudAnalysis","executeStep","fraud","fraudSessionId","step","tokenResult","tokenized","threeDSData","skipThreeDS","threeDSResult","auth","threeDSTimeout","msg","assign","threeDSStatus","fn","start","wrappedError"],"mappings":"AAAM,MAAOA,UAAsBC,MACjC,WAAAC,CAAYC,GACVC,MAAMD,GACNE,KAAKC,KAAO,gBACZC,OAAOC,eAAeH,KAAML,EAAcS,UAC5C,EAGI,MAAOC,UAA4BV,EACvC,WAAAE,CAAYC,EAAkB,sBAC5BC,MAAMD,GACNE,KAAKC,KAAO,sBACZC,OAAOC,eAAeH,KAAMK,EAAoBD,UAClD,EAGI,MAAOE,UAAwBX,EAEnC,WAAAE,CAAYU,EAAeT,GACzBC,MAAMD,GACNE,KAAKC,KAAO,kBACZD,KAAKO,MAAQA,EACbL,OAAOC,eAAeH,KAAMM,EAAgBF,UAC9C,EAGI,MAAOI,UAAiBb,EAG5B,WAAAE,CAAYY,EAAgBC,EAAcZ,GACxCC,MAAMD,GACNE,KAAKC,KAAO,WACZD,KAAKS,OAASA,EACdT,KAAKU,KAAOA,EACZR,OAAOC,eAAeH,KAAMQ,EAASJ,UACvC,EAGI,MAAOO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,EAAQhC,gBAAmBgC,EAAQ9B,eAUrE,CACLiC,SAAS,EACTrC,MAAOkC,EAAQlC,MACfC,MAAOiC,EAAQjC,MACfC,eAAgBgC,EAAQhC,eACxBE,eAAgB8B,EAAQ9B,eACxB0C,QAASwB,EACTJ,eAAgBhC,EAAQgC,eACxB/B,QACAI,WAAYxL,KAAKyL,MAAQJ,GAlBlBJ,EACL,IAAIrQ,MAAM,uDACV,eACAuQ,EACAC,EACAC,EAeN,CAMQ,iBAAM4B,CACZG,EACAW,EACA3C,EACA0B,GAEA,MAAMkB,EAAQhO,KAAKyL,MACnBqB,EAAO,CAAEM,OAAM3R,OAAQ,YACvB,UACQsS,IACN,MAAMvC,EAAaxL,KAAKyL,MAAQuC,EAGhC,OAFA5C,EAAMtF,KAAK,CAAEsH,OAAM3R,OAAQ,YAAa+P,eACxCsB,EAAO,CAAEM,OAAM3R,OAAQ,cAChB,CAAE8C,IAAI,EACf,CAAE,MAAOC,GACP,MAAMgN,EAAaxL,KAAKyL,MAAQuC,EAC1BC,EAAezP,aAAiB5D,MAAQ4D,EAAQ,IAAI5D,MAAMwK,OAAO5G,IAIvE,OAHAxD,KAAK4C,OAAOY,MAAM,SAAS4O,cAAiBa,EAAanT,WACzDsQ,EAAMtF,KAAK,CAAEsH,OAAM3R,OAAQ,SAAU+P,eACrCsB,EAAO,CAAEM,OAAM3R,OAAQ,WAChB,CAAE8C,IAAI,EAAOC,MAAOyP,EAC7B,CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ThreeDSController } from './controllers/three-ds';
|
|
2
|
+
import { TokenizerController } from './controllers/tokenizer';
|
|
3
|
+
import { FraudAnalysisController } from './controllers/fraud-analysis';
|
|
4
|
+
import type { ClientOptions, SdkConfig } from './types';
|
|
5
|
+
import type { PreparePaymentRequest, PreparePaymentOptions, PreparePaymentResult } from './types/payment';
|
|
6
|
+
export declare class Client {
|
|
7
|
+
private options;
|
|
8
|
+
private http;
|
|
9
|
+
private logger;
|
|
10
|
+
private config;
|
|
11
|
+
private _ready;
|
|
12
|
+
private initPromise;
|
|
13
|
+
readonly threeds: ThreeDSController;
|
|
14
|
+
readonly tokenizer: TokenizerController;
|
|
15
|
+
readonly fraudAnalysis: FraudAnalysisController;
|
|
16
|
+
constructor(options: ClientOptions);
|
|
17
|
+
initialize(): Promise<void>;
|
|
18
|
+
private _doInitialize;
|
|
19
|
+
isReady(): boolean;
|
|
20
|
+
isThreeDSAvailable(): boolean;
|
|
21
|
+
isTokenizationAvailable(): boolean;
|
|
22
|
+
isFraudAnalysisAvailable(): boolean;
|
|
23
|
+
getConfig(): SdkConfig | null;
|
|
24
|
+
/**
|
|
25
|
+
* Execute the complete payment flow in a single call.
|
|
26
|
+
*
|
|
27
|
+
* Orchestrates fraud analysis → tokenization → 3DS authentication,
|
|
28
|
+
* skipping steps that are unavailable or explicitly disabled.
|
|
29
|
+
*
|
|
30
|
+
* Returns a discriminated union: check `result.success` to determine
|
|
31
|
+
* the outcome. On failure, `partialResult` contains data from steps
|
|
32
|
+
* that completed before the error.
|
|
33
|
+
*/
|
|
34
|
+
preparePayment(request: PreparePaymentRequest, options?: PreparePaymentOptions): Promise<PreparePaymentResult>;
|
|
35
|
+
private executeStep;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAGvE,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EAMrB,MAAM,iBAAiB,CAAC;AAuBzB,qBAAa,MAAM;IACjB,OAAO,CAAC,OAAO,CAAkE;IACjF,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAA8B;IAEjD,SAAgB,OAAO,EAAE,iBAAiB,CAAC;IAC3C,SAAgB,SAAS,EAAE,mBAAmB,CAAC;IAC/C,SAAgB,aAAa,EAAE,uBAAuB,CAAC;gBAE3C,OAAO,EAAE,aAAa;IA0B5B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;YAYnB,aAAa;IAY3B,OAAO,IAAI,OAAO;IAIlB,kBAAkB,IAAI,OAAO;IAI7B,uBAAuB,IAAI,OAAO;IAIlC,wBAAwB,IAAI,OAAO;IAInC,SAAS,IAAI,SAAS,GAAG,IAAI;IAI7B;;;;;;;;;OASG;IACG,cAAc,CAClB,OAAO,EAAE,qBAAqB,EAC9B,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,oBAAoB,CAAC;YAgJlB,WAAW;CAuB1B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HttpHelper } from '../helpers/http';
|
|
2
|
+
import type { Logger } from '../utils/logger';
|
|
3
|
+
import type { FraudSetupResult } from '../types/fraud-analysis';
|
|
4
|
+
export declare class FraudAnalysisController {
|
|
5
|
+
private readonly http;
|
|
6
|
+
private readonly logger;
|
|
7
|
+
private readonly isReady;
|
|
8
|
+
constructor(http: HttpHelper, logger: Logger, isReady: () => boolean);
|
|
9
|
+
setup(): Promise<FraudSetupResult>;
|
|
10
|
+
private loadThreatMetrix;
|
|
11
|
+
private getBrowserType;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=fraud-analysis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fraud-analysis.d.ts","sourceRoot":"","sources":["../../../src/controllers/fraud-analysis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,KAAK,EAAsB,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAIpF,qBAAa,uBAAuB;IAEhC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAFP,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,OAAO;IAGnC,KAAK,IAAI,OAAO,CAAC,gBAAgB,CAAC;IA4CxC,OAAO,CAAC,gBAAgB;IAyCxB,OAAO,CAAC,cAAc;CAUvB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { HttpHelper } from '../helpers/http';
|
|
2
|
+
import type { Logger } from '../utils/logger';
|
|
3
|
+
import type { ThreeDSAuthenticateRequest, ThreeDSAuthenticateOptions, ThreeDSResult } from '../types';
|
|
4
|
+
export declare class ThreeDSController {
|
|
5
|
+
private http;
|
|
6
|
+
private logger;
|
|
7
|
+
private readyCheck;
|
|
8
|
+
constructor(http: HttpHelper, logger: Logger, readyCheck: () => boolean);
|
|
9
|
+
authenticate(request: ThreeDSAuthenticateRequest, options?: ThreeDSAuthenticateOptions): Promise<ThreeDSResult>;
|
|
10
|
+
/**
|
|
11
|
+
* BP.Mpi client-side 3DS authentication.
|
|
12
|
+
*
|
|
13
|
+
* Flow:
|
|
14
|
+
* 1. Create hidden inputs with CSS classes for BP.Mpi
|
|
15
|
+
* 2. Define global bpmpi_config() returning callbacks
|
|
16
|
+
* 3. Load BP.Mpi script
|
|
17
|
+
* 4. onReady fires -> call bpmpi_authenticate()
|
|
18
|
+
* 5. BP.Mpi handles enrollment + fingerprinting + challenge internally
|
|
19
|
+
* 6. onSuccess/onFailure/onUnenrolled/onError fires with result
|
|
20
|
+
*/
|
|
21
|
+
private authenticateWithBpMpi;
|
|
22
|
+
private static readonly TRUSTED_SCRIPT_ORIGINS;
|
|
23
|
+
private loadScript;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=three-ds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"three-ds.d.ts","sourceRoot":"","sources":["../../../src/controllers/three-ds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,KAAK,EACV,0BAA0B,EAC1B,0BAA0B,EAC1B,aAAa,EAGd,MAAM,UAAU,CAAC;AAmClB,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAgB;gBAEtB,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,OAAO;IAMjE,YAAY,CAChB,OAAO,EAAE,0BAA0B,EACnC,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,aAAa,CAAC;IAyIzB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,qBAAqB;IAsM7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,sBAAsB,CAG5C;IAEF,OAAO,CAAC,UAAU;CAqCnB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HttpHelper } from '../helpers/http';
|
|
2
|
+
import type { Logger } from '../utils/logger';
|
|
3
|
+
import type { TokenizeRequest, TokenizeResult } from '../types';
|
|
4
|
+
export declare class TokenizerController {
|
|
5
|
+
private http;
|
|
6
|
+
private logger;
|
|
7
|
+
private readyCheck;
|
|
8
|
+
constructor(http: HttpHelper, logger: Logger, readyCheck: () => boolean);
|
|
9
|
+
tokenize(request: TokenizeRequest): Promise<TokenizeResult>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=tokenizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenizer.d.ts","sourceRoot":"","sources":["../../../src/controllers/tokenizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAWhE,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAgB;gBAEtB,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,OAAO;IAMjE,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;CAiDlE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare class AccithusError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class AuthenticationError extends AccithusError {
|
|
5
|
+
constructor(message?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class ValidationError extends AccithusError {
|
|
8
|
+
readonly field: string;
|
|
9
|
+
constructor(field: string, message: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class ApiError extends AccithusError {
|
|
12
|
+
readonly status: number;
|
|
13
|
+
readonly code: string;
|
|
14
|
+
constructor(status: number, code: string, message: string);
|
|
15
|
+
}
|
|
16
|
+
export declare class NetworkError extends AccithusError {
|
|
17
|
+
constructor(message?: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class TimeoutError extends AccithusError {
|
|
20
|
+
constructor(message?: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class ThreeDSError extends AccithusError {
|
|
23
|
+
readonly status: string;
|
|
24
|
+
constructor(status: string, message: string);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,mBAAoB,SAAQ,aAAa;gBACxC,OAAO,GAAE,MAA6B;CAKnD;AAED,qBAAa,eAAgB,SAAQ,aAAa;IAChD,SAAgB,KAAK,EAAE,MAAM,CAAC;gBAClB,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAM3C;AAED,qBAAa,QAAS,SAAQ,aAAa;IACzC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,IAAI,EAAE,MAAM,CAAC;gBACjB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAO1D;AAED,qBAAa,YAAa,SAAQ,aAAa;gBACjC,OAAO,GAAE,MAAwB;CAK9C;AAED,qBAAa,YAAa,SAAQ,aAAa;gBACjC,OAAO,GAAE,MAA4B;CAKlD;AAED,qBAAa,YAAa,SAAQ,aAAa;IAC7C,SAAgB,MAAM,EAAE,MAAM,CAAC;gBACnB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAM5C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Logger } from '../utils/logger';
|
|
2
|
+
interface HttpConfig {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
publicKey: string;
|
|
5
|
+
timeout: number;
|
|
6
|
+
retries: number;
|
|
7
|
+
logger: Logger;
|
|
8
|
+
}
|
|
9
|
+
export declare class HttpHelper {
|
|
10
|
+
private config;
|
|
11
|
+
constructor(config: HttpConfig);
|
|
12
|
+
get<T>(path: string): Promise<T>;
|
|
13
|
+
post<T>(path: string, body?: unknown): Promise<T>;
|
|
14
|
+
private request;
|
|
15
|
+
private backoff;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/helpers/http.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAS9C,UAAU,UAAU;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAaD,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAa;gBAEf,MAAM,EAAE,UAAU;IAIxB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAIhC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;YAIzC,OAAO;YAgFP,OAAO;CAKtB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Client } from './client';
|
|
2
|
+
export type { ClientOptions, SdkConfig } from './types/client';
|
|
3
|
+
export type { ThreeDSAuthenticateRequest, ThreeDSAuthenticateOptions, ThreeDSResult, } from './types/three-ds';
|
|
4
|
+
export type { TokenizeRequest, TokenizeResult } from './types/tokenizer';
|
|
5
|
+
export type { FraudSetupResult } from './types/fraud-analysis';
|
|
6
|
+
export type { PreparePaymentRequest, PreparePaymentOptions, PreparePaymentResult, PaymentSuccess, PaymentFailure, PaymentStep, PaymentStepEvent, PaymentStepSummary, PaymentThreeDSDetail, PaymentAddress, } from './types/payment';
|
|
7
|
+
export { AccithusError, AuthenticationError, ValidationError, ApiError, NetworkError, TimeoutError, ThreeDSError, } from './errors';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC/D,YAAY,EACV,0BAA0B,EAC1B,0BAA0B,EAC1B,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACzE,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,YAAY,EACV,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,GACf,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,YAAY,GACb,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ClientOptions {
|
|
2
|
+
publicKey: string;
|
|
3
|
+
debug?: boolean;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
/** Override the API base URL (useful for local development/testing) */
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SdkConfig {
|
|
9
|
+
merchant_id: string;
|
|
10
|
+
merchant_name: string;
|
|
11
|
+
capabilities: {
|
|
12
|
+
threeds: boolean;
|
|
13
|
+
tokenization: boolean;
|
|
14
|
+
fraud_analysis: boolean;
|
|
15
|
+
};
|
|
16
|
+
require_three_ds: boolean;
|
|
17
|
+
require_fraud_analysis: boolean;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/types/client.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE;QACZ,OAAO,EAAE,OAAO,CAAC;QACjB,YAAY,EAAE,OAAO,CAAC;QACtB,cAAc,EAAE,OAAO,CAAC;KACzB,CAAC;IACF,gBAAgB,EAAE,OAAO,CAAC;IAC1B,sBAAsB,EAAE,OAAO,CAAC;CACjC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface FraudSetupResponse {
|
|
2
|
+
session_id: string;
|
|
3
|
+
threat_metrix: {
|
|
4
|
+
org_id: string;
|
|
5
|
+
session_id: string;
|
|
6
|
+
script_url: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface FraudSetupResult {
|
|
10
|
+
sessionId: string;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=fraud-analysis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fraud-analysis.d.ts","sourceRoot":"","sources":["../../../src/types/fraud-analysis.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE;QACb,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** Steps executed during the payment flow, in order. */
|
|
2
|
+
export type PaymentStep = 'fraud_analysis' | 'tokenization' | 'three_ds';
|
|
3
|
+
/** Status of a step after execution. */
|
|
4
|
+
export type PaymentStepStatus = 'completed' | 'skipped' | 'failed';
|
|
5
|
+
/** Emitted via `onStepChange` during the flow. */
|
|
6
|
+
export interface PaymentStepEvent {
|
|
7
|
+
step: PaymentStep;
|
|
8
|
+
status: 'started' | PaymentStepStatus;
|
|
9
|
+
}
|
|
10
|
+
/** Summary of a step included in the final result. */
|
|
11
|
+
export interface PaymentStepSummary {
|
|
12
|
+
step: PaymentStep;
|
|
13
|
+
status: PaymentStepStatus;
|
|
14
|
+
durationMs: number;
|
|
15
|
+
}
|
|
16
|
+
/** 3DS authentication details included in the result. */
|
|
17
|
+
export interface PaymentThreeDSDetail {
|
|
18
|
+
status: 'authenticated' | 'unenrolled';
|
|
19
|
+
cavv?: string;
|
|
20
|
+
eci?: string;
|
|
21
|
+
xid?: string;
|
|
22
|
+
version?: string;
|
|
23
|
+
referenceId?: string;
|
|
24
|
+
}
|
|
25
|
+
/** Full billing address (optional, but recommended for higher 3DS approval). */
|
|
26
|
+
export interface PaymentAddress {
|
|
27
|
+
street: string;
|
|
28
|
+
number: string;
|
|
29
|
+
complement?: string;
|
|
30
|
+
zipCode: string;
|
|
31
|
+
neighborhood: string;
|
|
32
|
+
city: string;
|
|
33
|
+
state: string;
|
|
34
|
+
country: string;
|
|
35
|
+
}
|
|
36
|
+
/** Everything needed to process a payment through the SDK. */
|
|
37
|
+
export interface PreparePaymentRequest {
|
|
38
|
+
/** Amount in cents (e.g. 15000 = R$ 150,00). */
|
|
39
|
+
amount: number;
|
|
40
|
+
/** ISO 4217 currency code. */
|
|
41
|
+
currency: string;
|
|
42
|
+
/** Number of installments (default: 1). */
|
|
43
|
+
installments?: number;
|
|
44
|
+
card: {
|
|
45
|
+
number: string;
|
|
46
|
+
holderName: string;
|
|
47
|
+
expirationMonth: string;
|
|
48
|
+
expirationYear: string;
|
|
49
|
+
cvv: string;
|
|
50
|
+
};
|
|
51
|
+
customer: {
|
|
52
|
+
name: string;
|
|
53
|
+
email: string;
|
|
54
|
+
phone: string;
|
|
55
|
+
};
|
|
56
|
+
/** Billing address. Recommended — improves 3DS frictionless approval rate. */
|
|
57
|
+
address?: PaymentAddress;
|
|
58
|
+
}
|
|
59
|
+
export interface PreparePaymentOptions {
|
|
60
|
+
/** Skip fraud analysis even if available (default: false). */
|
|
61
|
+
skipFraudAnalysis?: boolean;
|
|
62
|
+
/** Skip 3DS even if available (default: false). */
|
|
63
|
+
skipThreeDS?: boolean;
|
|
64
|
+
/** Timeout for the 3DS flow in ms (default: 120000). */
|
|
65
|
+
threeDSTimeout?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Called when each step starts, completes, is skipped, or fails.
|
|
68
|
+
* Useful for updating progress indicators in the UI.
|
|
69
|
+
*/
|
|
70
|
+
onStepChange?: (event: PaymentStepEvent) => void;
|
|
71
|
+
}
|
|
72
|
+
export interface PaymentSuccess {
|
|
73
|
+
success: true;
|
|
74
|
+
/** Card token to send to your backend for creating the charge. */
|
|
75
|
+
token: string;
|
|
76
|
+
/** Detected card brand. */
|
|
77
|
+
brand: string;
|
|
78
|
+
/** Last four digits (safe to display). */
|
|
79
|
+
lastFourDigits: string;
|
|
80
|
+
/** First six digits (BIN). */
|
|
81
|
+
firstSixDigits: string;
|
|
82
|
+
/** 3DS authentication details. Present if 3DS was executed. */
|
|
83
|
+
threeds?: PaymentThreeDSDetail;
|
|
84
|
+
/** Fraud session ID. Present if fraud analysis was executed. */
|
|
85
|
+
fraudSessionId?: string;
|
|
86
|
+
/** Per-step execution summary. */
|
|
87
|
+
steps: PaymentStepSummary[];
|
|
88
|
+
/** Total flow duration in ms. */
|
|
89
|
+
durationMs: number;
|
|
90
|
+
}
|
|
91
|
+
export interface PaymentFailure {
|
|
92
|
+
success: false;
|
|
93
|
+
/** The error that caused the failure. */
|
|
94
|
+
error: Error;
|
|
95
|
+
/** The step where the failure occurred. */
|
|
96
|
+
failedAt: PaymentStep;
|
|
97
|
+
/**
|
|
98
|
+
* Partial results from steps that completed before the failure.
|
|
99
|
+
* Useful for retrying from a specific point.
|
|
100
|
+
*/
|
|
101
|
+
partialResult: {
|
|
102
|
+
token?: string;
|
|
103
|
+
brand?: string;
|
|
104
|
+
lastFourDigits?: string;
|
|
105
|
+
firstSixDigits?: string;
|
|
106
|
+
fraudSessionId?: string;
|
|
107
|
+
};
|
|
108
|
+
/** Per-step execution summary (includes the failed step). */
|
|
109
|
+
steps: PaymentStepSummary[];
|
|
110
|
+
/** Total flow duration in ms. */
|
|
111
|
+
durationMs: number;
|
|
112
|
+
}
|
|
113
|
+
export type PreparePaymentResult = PaymentSuccess | PaymentFailure;
|
|
114
|
+
//# sourceMappingURL=payment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../../src/types/payment.ts"],"names":[],"mappings":"AAIA,wDAAwD;AACxD,MAAM,MAAM,WAAW,GAAG,gBAAgB,GAAG,cAAc,GAAG,UAAU,CAAC;AAEzE,wCAAwC;AACxC,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEnE,kDAAkD;AAClD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,EAAE,SAAS,GAAG,iBAAiB,CAAC;CACvC;AAED,sDAAsD;AACtD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,U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|
+
installments?: number;
|
|
5
|
+
card: {
|
|
6
|
+
number: string;
|
|
7
|
+
holderName?: string;
|
|
8
|
+
expirationMonth: string;
|
|
9
|
+
expirationYear: string;
|
|
10
|
+
};
|
|
11
|
+
customer: {
|
|
12
|
+
name: string;
|
|
13
|
+
email: string;
|
|
14
|
+
phone: string;
|
|
15
|
+
};
|
|
16
|
+
address?: {
|
|
17
|
+
street: string;
|
|
18
|
+
number: string;
|
|
19
|
+
complement?: string;
|
|
20
|
+
zipCode: string;
|
|
21
|
+
neighborhood: string;
|
|
22
|
+
city: string;
|
|
23
|
+
state: string;
|
|
24
|
+
country: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface ThreeDSAuthenticateOptions {
|
|
28
|
+
/** Timeout in ms for the entire 3DS flow (default: 120000) */
|
|
29
|
+
timeout?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface ModalOptions {
|
|
32
|
+
width?: string;
|
|
33
|
+
height?: string;
|
|
34
|
+
showCloseButton?: boolean;
|
|
35
|
+
closeOnOverlayClick?: boolean;
|
|
36
|
+
onCancel?: () => void;
|
|
37
|
+
}
|
|
38
|
+
export interface ThreeDSResult {
|
|
39
|
+
status: 'authenticated' | 'failed' | 'unenrolled' | 'error' | 'cancelled';
|
|
40
|
+
cavv?: string;
|
|
41
|
+
eci?: string;
|
|
42
|
+
xid?: string;
|
|
43
|
+
version?: string;
|
|
44
|
+
referenceId?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ThreeDSSessionResponse {
|
|
47
|
+
session_id: string;
|
|
48
|
+
status: string;
|
|
49
|
+
auth_config?: {
|
|
50
|
+
access_token: string;
|
|
51
|
+
script_url: string;
|
|
52
|
+
environment: string;
|
|
53
|
+
};
|
|
54
|
+
cavv?: string;
|
|
55
|
+
eci?: string;
|
|
56
|
+
xid?: string;
|
|
57
|
+
version?: string;
|
|
58
|
+
reference_id?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface ThreeDSFingerprintingResponse {
|
|
61
|
+
session_id: string;
|
|
62
|
+
status: string;
|
|
63
|
+
cavv?: string;
|
|
64
|
+
eci?: string;
|
|
65
|
+
xid?: string;
|
|
66
|
+
version?: string;
|
|
67
|
+
reference_id?: string;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=three-ds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"three-ds.d.ts","sourceRoot":"","sources":["../../../src/types/three-ds.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;QACxB,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,OAAO,CAAC,EAAE;QACR,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED,MAAM,WAAW,0BAA0B;IACzC,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,eAAe,GAAG,QAAQ,GAAG,YAAY,GAAG,OAAO,GAAG,WAAW,CAAC;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAGD,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE;QACZ,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,6BAA6B;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface TokenizeRequest {
|
|
2
|
+
card: {
|
|
3
|
+
number: string;
|
|
4
|
+
holderName: string;
|
|
5
|
+
expirationMonth: string;
|
|
6
|
+
expirationYear: string;
|
|
7
|
+
cvv: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface TokenizeResult {
|
|
11
|
+
token: string;
|
|
12
|
+
brand: string;
|
|
13
|
+
lastFourDigits: string;
|
|
14
|
+
firstSixDigits: string;
|
|
15
|
+
expirationMonth: string;
|
|
16
|
+
expirationYear: string;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=tokenizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenizer.d.ts","sourceRoot":"","sources":["../../../src/types/tokenizer.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,eAAe,EAAE,MAAM,CAAC;QACxB,cAAc,EAAE,MAAM,CAAC;QACvB,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;CACxB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface BrowserInfo {
|
|
2
|
+
user_agent: string;
|
|
3
|
+
ip_address: string;
|
|
4
|
+
language: string;
|
|
5
|
+
timezone_offset: number;
|
|
6
|
+
screen_width: number;
|
|
7
|
+
screen_height: number;
|
|
8
|
+
color_depth: number;
|
|
9
|
+
java_enabled: boolean;
|
|
10
|
+
javascript_enabled: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class BrowserUtils {
|
|
13
|
+
static collectBrowserInfo(ipAddress?: string): BrowserInfo;
|
|
14
|
+
static getPublicIP(): Promise<string>;
|
|
15
|
+
static collectBrowserInfoWithIP(): Promise<BrowserInfo>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../src/utils/browser.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AAED,qBAAa,YAAY;IACvB,MAAM,CAAC,kBAAkB,CAAC,SAAS,GAAE,MAAW,GAAG,WAAW;WAcjD,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;WAa9B,wBAAwB,IAAI,OAAO,CAAC,WAAW,CAAC;CAI9D"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class Logger {
|
|
2
|
+
private enabled;
|
|
3
|
+
constructor(enabled?: boolean);
|
|
4
|
+
debug(message: string, data?: unknown): void;
|
|
5
|
+
warn(message: string, data?: unknown): void;
|
|
6
|
+
error(message: string, data?: unknown): void;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,qBAAa,MAAM;IACjB,OAAO,CAAC,OAAO,CAAU;gBAEb,OAAO,GAAE,OAAe;IAIpC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAM5C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAM3C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;CAG7C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ModalOptions } from '../types';
|
|
2
|
+
export declare class ModalManager {
|
|
3
|
+
private overlay;
|
|
4
|
+
private options;
|
|
5
|
+
private cancelCallback;
|
|
6
|
+
constructor(options?: ModalOptions);
|
|
7
|
+
open(iframeUrl: string): HTMLDivElement;
|
|
8
|
+
close(): void;
|
|
9
|
+
private cancel;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=modal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../../../src/utils/modal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAU7C,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAA+B;IAC9C,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,cAAc,CAA2B;gBAErC,OAAO,CAAC,EAAE,YAAY;IAKlC,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc;IA+DvC,KAAK,IAAI,IAAI;IAUb,OAAO,CAAC,MAAM;CAIf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../../src/utils/validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAkBlE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Accithus={})}(this,function(e){"use strict";class t extends Error{constructor(e){super(e),this.name="AccithusError",Object.setPrototypeOf(this,t.prototype)}}class i extends t{constructor(e="Invalid public key"){super(e),this.name="AuthenticationError",Object.setPrototypeOf(this,i.prototype)}}class r extends t{constructor(e,t){super(t),this.name="ValidationError",this.field=e,Object.setPrototypeOf(this,r.prototype)}}class s extends t{constructor(e,t,i){super(i),this.name="ApiError",this.status=e,this.code=t,Object.setPrototypeOf(this,s.prototype)}}class o extends t{constructor(e="Network error"){super(e),this.name="NetworkError",Object.setPrototypeOf(this,o.prototype)}}class n extends t{constructor(e="Request timed out"){super(e),this.name="TimeoutError",Object.setPrototypeOf(this,n.prototype)}}class a extends t{constructor(e,t){super(t),this.name="ThreeDSError",this.status=e,Object.setPrototypeOf(this,a.prototype)}}class c{constructor(e){this.config=e}async get(e){return this.request("GET",e)}async post(e,t){return this.request("POST",e,t)}async request(e,t,r){const a=`${this.config.baseUrl}${t}`,c={"Content-Type":"application/json",Authorization:`Basic ${function(e){if("function"==typeof btoa)return btoa(e);const t=globalThis.Buffer;if(t)return t.from(e).toString("base64");throw new Error("No base64 encoding available")}(`${this.config.publicKey}:`)}`};let d=null;const u=this.config.retries+1;for(let l=1;l<=u;l++)try{const n=new AbortController,p=setTimeout(()=>n.abort(),this.config.timeout);this.config.logger.debug(`${e} ${t}`,{attempt:l});const h=await fetch(a,{method:e,headers:c,body:r?JSON.stringify(r):void 0,signal:n.signal});let m;clearTimeout(p);try{m=await h.json()}catch{if(!h.ok)throw new s(h.status,"PARSE_ERROR",`HTTP ${h.status} (non-JSON response)`);throw new o("Failed to parse response")}if(!h.ok){if(401===h.status)throw new i(m.message||"Invalid public key");const e=new s(h.status,m.error||"UNKNOWN_ERROR",m.message||`HTTP ${h.status} error`);if(h.status>=500&&l<u){d=e,await this.backoff(l);continue}throw e}return m.data}catch(e){if(e instanceof i||e instanceof s)throw e;if(d=e instanceof DOMException&&"AbortError"===e.name?new n(`Request timed out after ${this.config.timeout}ms`):new o(e instanceof Error?e.message:"Network error"),l<u){await this.backoff(l);continue}}throw d||new o("Request failed")}async backoff(e){const t=Math.min(1e3*Math.pow(2,e-1),1e4);this.config.logger.debug(`Retrying in ${t}ms (attempt ${e})`),await new Promise(e=>setTimeout(e,t))}}class d{constructor(e=!1){this.enabled=e}debug(e,t){this.enabled&&console.log(`[Accithus SDK] ${e}`,t??"")}warn(e,t){this.enabled&&console.warn(`[Accithus SDK] ${e}`,t??"")}error(e,t){console.error(`[Accithus SDK] ${e}`,t??"")}}class u{static collectBrowserInfo(e=""){return{user_agent:"undefined"!=typeof navigator?navigator.userAgent:"",ip_address:e,language:"undefined"!=typeof navigator&&navigator.language||"",timezone_offset:(new Date).getTimezoneOffset(),screen_width:"undefined"!=typeof screen?screen.width:0,screen_height:"undefined"!=typeof screen?screen.height:0,color_depth:"undefined"!=typeof screen?screen.colorDepth:0,java_enabled:!1,javascript_enabled:!0}}static async getPublicIP(){try{const e=new AbortController,t=setTimeout(()=>e.abort(),3e3),i=await fetch("https://api.ipify.org?format=json",{signal:e.signal});clearTimeout(t);return(await i.json()).ip}catch{return""}}static async collectBrowserInfoWithIP(){const e=await u.getPublicIP();return u.collectBrowserInfo(e)}}const l={BRL:"986",USD:"840",EUR:"978",ARS:"032",GBP:"826"};class p{constructor(e,t,i){this.http=e,this.logger=t,this.readyCheck=i}async authenticate(e,i){if(!this.readyCheck())throw new t("SDK not initialized. Call client.initialize() first.");if(!e.card?.number||e.card.number.length<13)throw new r("card.number","Card number must be at least 13 digits");if(!e.card?.expirationMonth||!e.card?.expirationYear)throw new r("card","Expiration month and year are required");if(!e.customer?.name||!e.customer?.email)throw new r("customer","Customer name and email are required");if(!e.amount||e.amount<=0)throw new r("amount","Amount must be greater than 0");this.logger.debug("Starting 3DS authentication via BP.Mpi");try{const t=await u.collectBrowserInfoWithIP();this.logger.debug("Browser info collected",{ip:t.ip_address});const r=await this.http.post("/3ds/sessions",{amount:e.amount,currency:e.currency,card_bin:e.card.number.slice(0,6),expiration_month:e.card.expirationMonth,expiration_year:e.card.expirationYear,customer:{name:e.customer.name,email:e.customer.email,phone:e.customer.phone},address:e.address?{street:e.address.street,number:e.address.number,zip_code:e.address.zipCode,neighborhood:e.address.neighborhood,city:e.address.city,state:e.address.state,country:e.address.country}:void 0,browser_info:t});if(this.logger.debug("3DS session created",{sessionId:r.session_id,status:r.status,hasAuthConfig:!!r.auth_config}),"authenticated"===r.status)return{status:"authenticated",cavv:r.cavv,eci:r.eci,xid:r.xid,version:r.version,referenceId:r.reference_id};if(!r.auth_config)return this.logger.error("3DS session missing auth_config"),{status:"error"};const s=await this.authenticateWithBpMpi(e,r,i,t.ip_address),o={status:s.status};s.cavv&&(o.cavv=s.cavv),s.eci&&(o.eci=s.eci),s.xid&&(o.xid=s.xid),s.version&&(o.version=s.version),s.referenceId&&(o.reference_id=s.referenceId);const n=await this.http.post(`/3ds/sessions/${r.session_id}/fingerprinting`,o);return this.logger.debug("3DS result submitted to API",{status:n.status}),{status:s.status,cavv:s.cavv,eci:s.eci,xid:s.xid,version:s.version,referenceId:s.referenceId}}catch(e){if(e instanceof a)return{status:e.status};throw this.logger.error("3DS authentication failed",e),e}}authenticateWithBpMpi(e,t,i,r){const s=t.auth_config,o=i?.timeout??12e4;return new Promise((i,n)=>{let c=null,d=null,u=!1;const p=()=>{d&&(clearTimeout(d),d=null),c&&(c.remove(),c=null),delete window.bpmpi_config},h=e=>{u||(u=!0,p(),i(e))},m=e=>{u||(u=!0,p(),n(e))};d=setTimeout(()=>{m(new a("error","3DS authentication timed out"))},o),c=document.createElement("div"),c.style.cssText="position:absolute;left:-9999px;top:-9999px;width:0;height:0;overflow:hidden;";const g=e.currency?.toUpperCase()??"BRL",f=l[g]??"986",b=[["bpmpi_auth","true"],["bpmpi_accesstoken",s.access_token],["bpmpi_ordernumber",t.session_id],["bpmpi_currency",f],["bpmpi_totalamount",String(e.amount)],["bpmpi_paymentmethod","credit"],["bpmpi_cardnumber",e.card.number],["bpmpi_cardexpirationmonth",e.card.expirationMonth],["bpmpi_cardexpirationyear",e.card.expirationYear],["bpmpi_installments",String(e.installments??1)],["bpmpi_order_productcode","PHY"],["bpmpi_merchant_url",window.location.origin],["bpmpi_billto_contactname",e.customer.name],["bpmpi_billto_email",e.customer.email],["bpmpi_billto_phonenumber",e.customer.phone],["bpmpi_device_channel","Browser"],["bpmpi_device_ipaddress",r]];if(e.address){const t=e.address.number?`${e.address.street}, ${e.address.number}`:e.address.street,i=[e.address.complement,e.address.neighborhood].filter(Boolean).join(" - ");b.push(["bpmpi_billto_street1",t],...i?[["bpmpi_billto_street2",i]]:[],["bpmpi_billto_city",e.address.city],["bpmpi_billto_state",e.address.state],["bpmpi_billto_zipcode",e.address.zipCode],["bpmpi_billto_country",e.address.country||"BR"])}for(const[e,t]of b){const i=document.createElement("input");i.type="hidden",i.className=e,i.value=t,c.appendChild(i)}document.body.appendChild(c);window.bpmpi_config=e=>({Environment:s.environment,Debug:!1,onReady:()=>{this.logger.debug("BP.Mpi onReady — calling bpmpi_authenticate()");try{bpmpi_authenticate()}catch(e){this.logger.error("bpmpi_authenticate() call failed",e),m(new a("error","Failed to call bpmpi_authenticate()"))}},onSuccess:e=>{this.logger.debug("BP.Mpi onSuccess",{eci:e.Eci,version:e.Version}),h({status:"authenticated",cavv:e.Cavv,eci:e.Eci,xid:e.Xid,version:e.Version,referenceId:e.ReferenceId})},onFailure:e=>{this.logger.debug("BP.Mpi onFailure",{eci:e?.Eci,xid:e?.Xid,version:e?.Version}),h({status:"failed",eci:e?.Eci,xid:e?.Xid,version:e?.Version,referenceId:e?.ReferenceId})},onUnenrolled:e=>{this.logger.debug("BP.Mpi onUnenrolled",{eci:e?.Eci,xid:e?.Xid,version:e?.Version}),h({status:"unenrolled",eci:e?.Eci,xid:e?.Xid,version:e?.Version,referenceId:e?.ReferenceId})},onError:e=>{this.logger.error("BP.Mpi onError",{returnCode:e?.ReturnCode,returnMessage:e?.ReturnMessage,xid:e?.Xid}),h({status:"error",eci:e?.Eci,xid:e?.Xid,referenceId:e?.ReferenceId})},onUnsupportedBrand:e=>{this.logger.debug("BP.Mpi onUnsupportedBrand",{returnCode:e?.ReturnCode,returnMessage:e?.ReturnMessage}),h({status:"error"})},onDisabled:()=>{this.logger.debug("BP.Mpi onDisabled"),h({status:"error"})}}),this.loadScript(s.script_url).catch(e=>{this.logger.error("Failed to load BP.Mpi script",e),m(new a("error","Failed to load BP.Mpi script"))})})}loadScript(e){return new Promise((t,i)=>{try{const t=new URL(e);if(!p.TRUSTED_SCRIPT_ORIGINS.some(e=>t.origin===new URL(e).origin))return void i(new a("error",`Untrusted 3DS script origin: ${t.origin}`))}catch{return void i(new a("error","Invalid 3DS script URL"))}const r=document.querySelector(`script[src="${e}"]`);r&&r.remove();const s=document.createElement("script");s.src=e,s.async=!0,s.onload=()=>t(),s.onerror=()=>i(new a("error","Failed to load 3DS script")),document.head.appendChild(s)})}}p.TRUSTED_SCRIPT_ORIGINS=["https://mpisandbox.braspag.com.br","https://mpi.braspag.com.br"];class h{constructor(e,t,i){this.http=e,this.logger=t,this.readyCheck=i}async tokenize(e){if(!this.readyCheck())throw new t("SDK not initialized. Call client.initialize() first.");if(!e.card?.number||e.card.number.length<13)throw new r("card.number","Card number must be at least 13 digits");if(!e.card?.cvv||e.card.cvv.length<3)throw new r("card.cvv","CVV must be at least 3 digits");if(!e.card?.holderName)throw new r("card.holderName","Holder name is required");if(!e.card?.expirationMonth||!e.card?.expirationYear)throw new r("card","Expiration month and year are required");this.logger.debug("Tokenizing card",{lastFour:e.card.number.slice(-4)});const i=await this.http.post("/tokenize/",{card:{number:e.card.number,holder_name:e.card.holderName,expiration_month:e.card.expirationMonth,expiration_year:e.card.expirationYear,cvv:e.card.cvv}}),s={token:i.token,brand:i.brand,lastFourDigits:i.last_four_digits,firstSixDigits:i.first_six_digits,expirationMonth:i.expiration_month,expirationYear:i.expiration_year};return this.logger.debug("Card tokenized",{token:s.token,brand:s.brand}),s}}const m=[".online-metrix.net"];class g{constructor(e,t,i){this.http=e,this.logger=t,this.isReady=i}async setup(){if(!this.isReady())throw new r("setup","SDK must be initialized before calling setup()");this.logger.debug("Collecting browser data for fraud analysis");const e={ip_address:await u.getPublicIP(),type:this.getBrowserType(),host_name:"undefined"!=typeof window?window.location.hostname:"unknown",cookies_accepted:"undefined"!=typeof navigator&&navigator.cookieEnabled,user_agent:"undefined"!=typeof navigator?navigator.userAgent:void 0};this.logger.debug("Browser data collected",{browserData:e});const t=await this.http.post("/fraud/setup",{browser_data:e});return this.logger.debug("Fraud session created",{sessionId:t.session_id}),this.loadThreatMetrix(t.threat_metrix.org_id,t.threat_metrix.session_id,t.threat_metrix.script_url),{sessionId:t.session_id}}loadThreatMetrix(e,t,i){if("undefined"==typeof document)return;const r=`${i}?org_id=${e}&session_id=${t}`;let s=!1;try{const e=new URL(i);s=m.some(t=>e.hostname.endsWith(t))}catch{s=!1}if(!s)return void this.logger.warn("Skipping ThreatMetrix load: untrusted script URL",{scriptUrl:i});const o=document.createElement("script");o.src=r,o.async=!0,document.head.appendChild(o);const n=document.createElement("noscript"),a=document.createElement("iframe");a.src=`${i.replace("/tags.js","/tags")}?org_id=${e}&session_id=${t}`,a.style.cssText="width:100px;height:100px;border:0;position:absolute;top:-5000px;",n.appendChild(a),document.body.appendChild(n),this.logger.debug("ThreatMetrix script injected")}getBrowserType(){if("undefined"==typeof navigator)return"Unknown";const e=navigator.userAgent;return e.includes("Chrome")&&!e.includes("Edg")?"Chrome":e.includes("Firefox")?"Firefox":e.includes("Safari")&&!e.includes("Chrome")?"Safari":e.includes("Edg")?"Edge":e.includes("Opera")||e.includes("OPR")?"Opera":"Other"}}const f=()=>{};function b(e,t,i,r,s){return{success:!1,error:e,failedAt:t,partialResult:{...i},steps:r,durationMs:Date.now()-s}}e.AccithusError=t,e.ApiError=s,e.AuthenticationError=i,e.Client=class{constructor(e){this.config=null,this._ready=!1,this.initPromise=null,function(e){if(!e.publicKey||"string"!=typeof e.publicKey)throw new r("publicKey","publicKey is required and must be a string");if(!e.publicKey.startsWith("pk_"))throw new r("publicKey",'publicKey must start with "pk_"');if(e.publicKey.length<10)throw new r("publicKey","publicKey must be at least 10 characters");if(void 0!==e.timeout&&("number"!=typeof e.timeout||e.timeout<1e3||e.timeout>6e4))throw new r("timeout","timeout must be between 1000 and 60000")}(e),this.options={publicKey:e.publicKey,debug:e.debug??!1,timeout:e.timeout??3e4,baseUrl:e.baseUrl},this.logger=new d(this.options.debug),this.http=new c({baseUrl:e.baseUrl??"https://api.accithus.com/v1/public/sdk",publicKey:this.options.publicKey,timeout:this.options.timeout,retries:3,logger:this.logger});const t=()=>this._ready;this.threeds=new p(this.http,this.logger,t),this.tokenizer=new h(this.http,this.logger,t),this.fraudAnalysis=new g(this.http,this.logger,t)}async initialize(){if(!this._ready){if(this.initPromise)return this.initPromise;this.initPromise=this._doInitialize();try{await this.initPromise}finally{this.initPromise=null}}}async _doInitialize(){this.logger.debug("Initializing SDK"),this.config=await this.http.get("/config/"),this._ready=!0,this.logger.debug("SDK initialized",{merchantId:this.config.merchant_id,capabilities:this.config.capabilities})}isReady(){return this._ready}isThreeDSAvailable(){return this._ready&&(this.config?.capabilities.threeds??!1)}isTokenizationAvailable(){return this._ready&&(this.config?.capabilities.tokenization??!1)}isFraudAnalysisAvailable(){return this._ready&&(this.config?.capabilities.fraud_analysis??!1)}getConfig(){return this.config}async preparePayment(e,t){const i=Date.now(),s=[],o=t?.onStepChange??f,n={};if(!e.card.holderName)throw new r("card.holderName","Nome do portador é obrigatório para o fluxo completo");if(!t?.skipFraudAnalysis&&this.isFraudAnalysisAvailable()){const e=await this.executeStep("fraud_analysis",async()=>{const e=await this.fraudAnalysis.setup();n.fraudSessionId=e.sessionId},s,o);if(!e.ok)return b(e.error,"fraud_analysis",n,s,i)}else s.push({step:"fraud_analysis",status:"skipped",durationMs:0}),o({step:"fraud_analysis",status:"skipped"});const a=await this.executeStep("tokenization",async()=>{const t=await this.tokenizer.tokenize({card:{number:e.card.number,holderName:e.card.holderName,expirationMonth:e.card.expirationMonth,expirationYear:e.card.expirationYear,cvv:e.card.cvv}});n.token=t.token,n.brand=t.brand,n.lastFourDigits=t.lastFourDigits,n.firstSixDigits=t.firstSixDigits},s,o);if(!a.ok)return b(a.error,"tokenization",n,s,i);let c;if(!t?.skipThreeDS&&this.isThreeDSAvailable()){const r=await this.executeStep("three_ds",async()=>{const i=await this.threeds.authenticate({amount:e.amount,currency:e.currency,installments:e.installments,card:{number:e.card.number,holderName:e.card.holderName,expirationMonth:e.card.expirationMonth,expirationYear:e.card.expirationYear},customer:e.customer,address:e.address},{timeout:t?.threeDSTimeout});if("failed"===i.status||"error"===i.status||"cancelled"===i.status){const e="failed"===i.status?"Autenticação negada pelo emissor":"cancelled"===i.status?"Autenticação cancelada":"Erro na autenticação 3DS";throw Object.assign(new Error(e),{threeDSStatus:i.status})}c={status:i.status,cavv:i.cavv,eci:i.eci,xid:i.xid,version:i.version,referenceId:i.referenceId}},s,o);if(!r.ok)return b(r.error,"three_ds",n,s,i)}else s.push({step:"three_ds",status:"skipped",durationMs:0}),o({step:"three_ds",status:"skipped"});return n.token&&n.brand&&n.lastFourDigits&&n.firstSixDigits?{success:!0,token:n.token,brand:n.brand,lastFourDigits:n.lastFourDigits,firstSixDigits:n.firstSixDigits,threeds:c,fraudSessionId:n.fraudSessionId,steps:s,durationMs:Date.now()-i}:b(new Error("Tokenization completed but returned incomplete data"),"tokenization",n,s,i)}async executeStep(e,t,i,r){const s=Date.now();r({step:e,status:"started"});try{await t();const o=Date.now()-s;return i.push({step:e,status:"completed",durationMs:o}),r({step:e,status:"completed"}),{ok:!0}}catch(t){const o=Date.now()-s,n=t instanceof Error?t:new Error(String(t));return this.logger.error(`Step "${e}" failed: ${n.message}`),i.push({step:e,status:"failed",durationMs:o}),r({step:e,status:"failed"}),{ok:!1,error:n}}}},e.NetworkError=o,e.ThreeDSError=a,e.TimeoutError=n,e.ValidationError=r});
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@accithus/security-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Accithus Security SDK for 3DS authentication and card tokenization",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/accithus/accithus-elysia-api.git",
|
|
9
|
+
"directory": "apps/sdk"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"3ds",
|
|
13
|
+
"tokenization",
|
|
14
|
+
"payments",
|
|
15
|
+
"pci",
|
|
16
|
+
"security",
|
|
17
|
+
"accithus"
|
|
18
|
+
],
|
|
19
|
+
"main": "dist/cjs/index.cjs",
|
|
20
|
+
"module": "dist/esm/index.js",
|
|
21
|
+
"browser": "dist/umd/index.js",
|
|
22
|
+
"types": "dist/types/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": "./dist/esm/index.js",
|
|
26
|
+
"require": "./dist/cjs/index.cjs",
|
|
27
|
+
"types": "./dist/types/index.d.ts"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"type": "module",
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "rollup -c && tsc --emitDeclarationOnly --outDir dist/types",
|
|
37
|
+
"prepublishOnly": "bun run build",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"clean": "rm -rf dist"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@rollup/plugin-typescript": "^12.1.0",
|
|
43
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
44
|
+
"@rollup/plugin-commonjs": "^28.0.0",
|
|
45
|
+
"@rollup/plugin-terser": "^0.4.0",
|
|
46
|
+
"rollup": "^4.0.0",
|
|
47
|
+
"tslib": "^2.8.0",
|
|
48
|
+
"typescript": "^5.8.0"
|
|
49
|
+
}
|
|
50
|
+
}
|