"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;var _events = require('events'); var _events2 = _interopRequireDefault(_events);var m=(r=>(r.DEVELOPMENT="DEVELOPMENT",r.STAGING="STAGING",r.PRODUCTION="PRODUCTION",r))(m||{});var i=(s=>(s.TRANSAK_WIDGET_INITIALISED="TRANSAK_WIDGET_INITIALISED",s.TRANSAK_ORDER_CREATED="TRANSAK_ORDER_CREATED",s.TRANSAK_ORDER_SUCCESSFUL="TRANSAK_ORDER_SUCCESSFUL",s.TRANSAK_ORDER_CANCELLED="TRANSAK_ORDER_CANCELLED",s.TRANSAK_ORDER_FAILED="TRANSAK_ORDER_FAILED",s.TRANSAK_WALLET_REDIRECTION="TRANSAK_WALLET_REDIRECTION",s.TRANSAK_WIDGET_CLOSE_REQUEST="TRANSAK_WIDGET_CLOSE_REQUEST",s.TRANSAK_WIDGET_CLOSE="TRANSAK_WIDGET_CLOSE",s.TRANSAK_USER_INFO_RECEIVED="TRANSAK_USER_INFO_RECEIVED",s.TRANSAK_GET_USER_REQUEST="TRANSAK_GET_USER_REQUEST",s.TRANSAK_LOGOUT_USER_REQUEST="TRANSAK_LOGOUT_USER_REQUEST",s))(i||{});var _querystring = require('query-string'); var _querystring2 = _interopRequireDefault(_querystring);var _pako = require('pako'); var _pako2 = _interopRequireDefault(_pako);var R={DEVELOPMENT:"https://localhost:5005/",STAGING:"https://global-stg.transak.com",PRODUCTION:"https://global.transak.com"};var A={name:"@transak/transak-sdk",version:"3.1.3",description:"Transak SDK that allows you to easily integrate fiat on/off ramp",type:"module",types:"lib/index.d.ts",main:"lib/index.cjs",exports:{".":{import:{types:"./lib/index.d.ts",default:"./lib/index.js"},require:{types:"./lib/index.d.cts",default:"./lib/index.cjs"}}},engines:{node:">=18.0.0"},packageManager:"pnpm@9.5.0+sha256.fc4a49bd609550a41e14d20efbce802a4b892aa4cac877322de2f0924f122991",files:["lib/**/*"],scripts:{eslint:"eslint . --ext .ts","eslint:fix":"pnpm eslint --fix",build:"tsc && tsup",prepack:"pnpm build",packDev:"pnpm pack"},author:"Transak",license:"ISC",homepage:"https://docs.transak.com/docs/web-integration#transak-sdk-reactvueangularts",repository:{type:"git",url:"https://github.com/Transak/transak-sdk"},dependencies:{events:"^3.3.0",pako:"^2.1.0","query-string":"^8.2.0"},devDependencies:{"@types/events":"^3.0.3","@types/pako":"^2.0.3",eslint:"^8.56.0","eslint-config-airbnb-base":"^15.0.0","eslint-config-airbnb-typescript":"^17.1.0","eslint-config-prettier":"^9.1.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.29.1","eslint-plugin-no-relative-import-paths":"^1.5.3","eslint-plugin-prettier":"^5.1.3","eslint-plugin-promise":"^6.1.1",prettier:"^3.2.5",tsup:"^8.0.2",typescript:"^5.3.3"},keywords:["crypto","cryptocurrency","fiat","on","off","ramp","sdk","ts","js"]};function E(e){let{name:n,version:t}=A,{environment:r="STAGING"}=e,a={sdkName:n,sdkVersion:t},l="";return Object.keys(e).forEach(o=>{if(!["environment","widgetWidth","widgetHeight"].includes(o)){if(["walletAddressesData","userData"].includes(o)){try{a[o]=JSON.stringify(e[o])}catch (e2){}return}if(["nftData","sourceTokenData","cryptoCurrencyData","tokenData"].includes(o)){try{a[o]=btoa(JSON.stringify(e[o]))}catch (e3){}return}if(["calldata"].includes(o)){try{a[o]=btoa(String.fromCharCode.apply(null,_pako2.default.deflate(e[o])))}catch (e4){}return}a[o]=e[o]}}),l=_querystring2.default.stringify(a,{arrayFormat:"comma"}),`${R[r]}?${l}`}function c(e){let n=document.createElement("iframe");return Object.assign(n,{id:"transakIframe",allow:"camera;microphone;payment",src:e}),n}function f(){return` #transakIframe{ width: 100%; height: 100%; border: none; } `}function _(){let e=document.createElement("style");return e.innerHTML=f(),_optionalChain([document, 'access', _2 => _2.getElementsByTagName, 'call', _3 => _3("head"), 'access', _4 => _4[0], 'optionalAccess', _5 => _5.appendChild, 'call', _6 => _6(e)]),e}function S(e){let n=_(),t=c(E(e));if(e.containerId){let r=document.getElementById(e.containerId);if(r)r.appendChild(t);else throw new Error("[Transak SDK] => Please enter a valid containerId")}return{styleElement:n,iframeElement:t}}function I(e){return function(t){if(_optionalChain([t, 'optionalAccess', _7 => _7.data, 'optionalAccess', _8 => _8.event_id]))switch(t.data.event_id){case"TRANSAK_WIDGET_INITIALISED":{e.emit("TRANSAK_WIDGET_INITIALISED",{eventName:"TRANSAK_WIDGET_INITIALISED",status:!0});break}case"TRANSAK_ORDER_CREATED":{e.emit("TRANSAK_ORDER_CREATED",{eventName:"TRANSAK_ORDER_CREATED",status:t.data.data});break}case"TRANSAK_ORDER_SUCCESSFUL":{e.emit("TRANSAK_ORDER_SUCCESSFUL",{eventName:"TRANSAK_ORDER_SUCCESSFUL",status:t.data.data});break}case"TRANSAK_ORDER_CANCELLED":{e.emit("TRANSAK_ORDER_CANCELLED",{eventName:"TRANSAK_ORDER_CANCELLED",status:t.data.data});break}case"TRANSAK_ORDER_FAILED":{e.emit("TRANSAK_ORDER_FAILED",{eventName:"TRANSAK_ORDER_FAILED",status:t.data.data});break}case"TRANSAK_WALLET_REDIRECTION":{e.emit("TRANSAK_WALLET_REDIRECTION",{eventName:"TRANSAK_WALLET_REDIRECTION",status:t.data.data});break}case"TRANSAK_WIDGET_CLOSE":{e.emit("TRANSAK_WIDGET_CLOSE",{eventName:"TRANSAK_WIDGET_CLOSE",status:!0});break}case"TRANSAK_USER_INFO_RECEIVED":{e.emit("TRANSAK_USER_INFO_RECEIVED",{eventName:"TRANSAK_USER_INFO_RECEIVED",status:t.data.data});break}}}}var u=` `;function g(e,n,t){return` #transakRoot { z-index: 9997; position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0, 0, 0, 0.6); } #transakModal { z-index: 9998; position: fixed; width: ${n}; height: calc(${t} - 24px); top: 50%; left: 50%; transform: translate(-50%, calc(-50% - 12px)); margin-top: 24px; } #transakCloseIcon { z-index: 9999; position: absolute; width: 36px; height: 36px; top: -24px; right: 0; transition: 0.5s; color: #${e}; background: white; border-radius: 50%; } #transakCloseIcon:hover, #transakCloseIcon:focus { color: white; background: #${e}; cursor: pointer; } #transakIframe{ width: 100%; height: 100%; border: none; border-radius: 10px; background: white; } @media screen and (max-width: 600px) { #transakModal { width: 100%; height: calc(100% - 24px); } #transakIframe{ border-radius: 10px 10px 0 0; } } `}function h(e){let{themeColor:n="1461db",widgetWidth:t="480px",widgetHeight:r="650px"}=e,a=document.createElement("style");return a.innerHTML=g(n,t,r),_optionalChain([document, 'access', _9 => _9.getElementsByTagName, 'call', _10 => _10("head"), 'access', _11 => _11[0], 'optionalAccess', _12 => _12.appendChild, 'call', _13 => _13(a)]),a}function N(e,n){let t=h(e),r=document.createElement("div"),a=document.createElement("div"),l=c(E(e));return Object.assign(a,{id:"transakModal",innerHTML:u}),a.appendChild(l),Object.assign(r,{id:"transakRoot",onclick:()=>n()}),r.appendChild(a),document.getElementsByTagName("body")[0].appendChild(r),_optionalChain([document, 'access', _14 => _14.getElementById, 'call', _15 => _15("transakCloseIcon"), 'optionalAccess', _16 => _16.addEventListener, 'call', _17 => _17("click",()=>n())]),{styleElement:t,rootElement:r,iframeElement:l}}var d=new _events2.default.EventEmitter,p= exports.Transak = (_class =class{#t;#n;#o;#e;#a;#r=!1;static __initStatic() {this.ENVIRONMENTS=m}static __initStatic2() {this.EVENTS=i}constructor(n){;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);if(!_optionalChain([n, 'optionalAccess', _38 => _38.apiKey]))throw new Error("[Transak SDK] => Please enter your API Key");this.#t=n,this.#a=I(d)}static __initStatic3() {this.on=(n,t)=>{n==="*"?Object.keys(i).forEach(r=>{d.on(i[r],t)}):i[n]&&d.on(n,t)}}__init() {this.init=()=>{this.#r||(this.#i(),this.#r=!0)}}__init2() {this.cleanup=()=>{_optionalChain([this, 'access', _39 => _39.#n, 'optionalAccess', _40 => _40.remove, 'call', _41 => _41()]),this.#s(),_optionalChain([this, 'access', _42 => _42.#e, 'optionalAccess', _43 => _43.remove, 'call', _44 => _44()]),this.#r=!1}}__init3() {this.close=()=>{_optionalChain([this, 'access', _45 => _45.#n, 'optionalAccess', _46 => _46.remove, 'call', _47 => _47()]),_optionalChain([this, 'access', _48 => _48.#o, 'optionalAccess', _49 => _49.remove, 'call', _50 => _50()]),this.#s(),this.#e=void 0,this.#r=!1}}__init4() {this.getUser=()=>{_optionalChain([this, 'access', _51 => _51.#e, 'optionalAccess', _52 => _52.contentWindow, 'optionalAccess', _53 => _53.postMessage, 'call', _54 => _54({event_id:"TRANSAK_GET_USER_REQUEST"},"*")])}}__init5() {this.logoutUser=()=>{_optionalChain([this, 'access', _55 => _55.#e, 'optionalAccess', _56 => _56.contentWindow, 'optionalAccess', _57 => _57.postMessage, 'call', _58 => _58({event_id:"TRANSAK_LOGOUT_USER_REQUEST"},"*")])}}#i=()=>{if(window.addEventListener("message",this.#a),this.#t.containerId){let{styleElement:n,iframeElement:t}=S(this.#t);this.#n=n,this.#e=t}else{let{styleElement:n,rootElement:t,iframeElement:r}=N(this.#t,this.#l);this.#n=n,this.#o=t,this.#e=r}};#l=()=>{_optionalChain([this, 'access', _59 => _59.#e, 'optionalAccess', _60 => _60.contentWindow, 'optionalAccess', _61 => _61.postMessage, 'call', _62 => _62({event_id:"TRANSAK_WIDGET_CLOSE_REQUEST"},"*")])};#s=()=>{d.removeAllListeners(),window.removeEventListener("message",this.#a)}}, _class.__initStatic(), _class.__initStatic2(), _class.__initStatic3(), _class);exports.Transak = p; //# sourceMappingURL=index.cjs.map