"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=(i=>(i.DEVELOPMENT="DEVELOPMENT",i.STAGING="STAGING",i.PRODUCTION="PRODUCTION",i.STAGING_ORDERS="STAGING_ORDERS",i.PRODUCTION_ORDERS="PRODUCTION_ORDERS",i.STAGING_ORDERS_NOT_LOGGED_IN="STAGING_ORDERS_NOT_LOGGED_IN",i.PRODUCTION_ORDERS_NOT_LOGGED_IN="PRODUCTION_ORDERS_NOT_LOGGED_IN",i))(m||{});var l=(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))(l||{});var _querystring = require('query-string'); var _querystring2 = _interopRequireDefault(_querystring);var _pako = require('pako'); var _pako2 = _interopRequireDefault(_pako);var p={DEVELOPMENT:"https://localhost:5005/",STAGING:"https://global-stg.transak.com",PRODUCTION:"https://global.transak.com",STAGING_ORDERS:"https://global-stg.transak.com/user/orders",PRODUCTION_ORDERS:"https://global.transak.com/user/orders",STAGING_ORDERS_NOT_LOGGED_IN:"https://global-stg.transak.com/login/email",PRODUCTION_ORDERS_NOT_LOGGED_IN:"https://global.transak.com/login/email"};var _={name:"@scalingparrots/transak-sdk",version:"3.1.11",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 c(e){let{name:n,version:t}=_,{environment:a="STAGING"}=e,r={sdkName:n,sdkVersion:t},E="";return Object.keys(e).forEach(o=>{if(!["environment","widgetWidth","widgetHeight"].includes(o)){if(["walletAddressesData","userData"].includes(o)){try{r[o]=JSON.stringify(e[o])}catch (e2){}return}if(["nftData","sourceTokenData","cryptoCurrencyData","tokenData"].includes(o)){try{r[o]=btoa(JSON.stringify(e[o]))}catch (e3){}return}if(["calldata"].includes(o)){try{r[o]=btoa(String.fromCharCode.apply(null,_pako2.default.deflate(e[o])))}catch (e4){}return}r[o]=e[o]}}),E=_querystring2.default.stringify(r,{arrayFormat:"comma"}),`${p[a]}?${E}`}function d(e){let n=document.createElement("iframe");return Object.assign(n,{id:"transakIframe",allow:"camera;microphone;payment",src:e}),n}function A(){return` #transakIframe{ width: 100%; height: 100%; border: none; } `}function S(){let e=document.createElement("style");return e.innerHTML=A(),_optionalChain([document, 'access', _2 => _2.getElementsByTagName, 'call', _3 => _3("head"), 'access', _4 => _4[0], 'optionalAccess', _5 => _5.appendChild, 'call', _6 => _6(e)]),e}function I(e){let n=S(),t=d(c(e));if(e.containerId){let a=document.getElementById(e.containerId);if(a)a.appendChild(t);else throw new Error("[Transak SDK] => Please enter a valid containerId")}return{styleElement:n,iframeElement:t}}function N(e){return function(t){if(_optionalChain([t, 'optionalAccess', _7 => _7.data, 'optionalAccess', _8 => _8.event_id]))switch(console.log(JSON.stringify(t)),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 f=` `;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 u(e){let{themeColor:n="1461db",widgetWidth:t="480px",widgetHeight:a="650px"}=e,r=document.createElement("style");return r.innerHTML=g(n,t,a),_optionalChain([document, 'access', _9 => _9.getElementsByTagName, 'call', _10 => _10("head"), 'access', _11 => _11[0], 'optionalAccess', _12 => _12.appendChild, 'call', _13 => _13(r)]),r}function h(e,n){let t=u(e),a=document.createElement("div"),r=document.createElement("div"),E=d(c(e));return Object.assign(r,{id:"transakModal",innerHTML:f}),r.appendChild(E),Object.assign(a,{id:"transakRoot",onclick:()=>n()}),a.appendChild(r),document.getElementsByTagName("body")[0].appendChild(a),_optionalChain([document, 'access', _14 => _14.getElementById, 'call', _15 => _15("transakCloseIcon"), 'optionalAccess', _16 => _16.addEventListener, 'call', _17 => _17("click",()=>n())]),{styleElement:t,rootElement:a,iframeElement:E}}var T=new _events2.default.EventEmitter,R= exports.Transak = (_class =class{#t;#n;#o;#e;#r;#a=!1;static __initStatic() {this.ENVIRONMENTS=m}static __initStatic2() {this.EVENTS=l}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.#r=N(T)}static __initStatic3() {this.on=(n,t)=>{n==="*"?Object.keys(l).forEach(a=>{T.on(l[a],t)}):l[n]&&T.on(n,t)}}__init() {this.init=()=>{this.#a||(this.#i(),this.#a=!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.#a=!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.#a=!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.#r),this.#t.containerId){let{styleElement:n,iframeElement:t}=I(this.#t);this.#n=n,this.#e=t}else{let{styleElement:n,rootElement:t,iframeElement:a}=h(this.#t,this.#l);this.#n=n,this.#o=t,this.#e=a}};#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=()=>{T.removeAllListeners(),window.removeEventListener("message",this.#r)}}, _class.__initStatic(), _class.__initStatic2(), _class.__initStatic3(), _class);exports.Transak = R; //# sourceMappingURL=index.cjs.map