@transak/transak-sdk
Advanced tools
Comparing version 2.0.2 to 2.1.0
declare enum Environments { | ||
DEVELOPMENT = "DEVELOPMENT", | ||
STAGING = "STAGING", | ||
@@ -37,2 +38,4 @@ PRODUCTION = "PRODUCTION" | ||
type ColorMode = 'LIGHT' | 'DARK'; | ||
type QueryParams = { | ||
@@ -81,2 +84,10 @@ apiKey: string; | ||
walletRedirection?: boolean; | ||
referrerDomain?: string; | ||
colorMode?: ColorMode; | ||
backgroundColors?: string | string[]; | ||
textColors?: string | string[]; | ||
borderColors?: string | string[]; | ||
isTransakOne?: boolean; | ||
sourceTokenData?: string; | ||
cryptoCurrencyData?: string; | ||
}; | ||
@@ -98,3 +109,6 @@ | ||
TRANSAK_WIDGET_CLOSE_REQUEST = "TRANSAK_WIDGET_CLOSE_REQUEST", | ||
TRANSAK_WIDGET_CLOSE = "TRANSAK_WIDGET_CLOSE" | ||
TRANSAK_WIDGET_CLOSE = "TRANSAK_WIDGET_CLOSE", | ||
TRANSAK_USER_INFO_RECEIVED = "TRANSAK_USER_INFO_RECEIVED", | ||
TRANSAK_GET_USER_REQUEST = "TRANSAK_GET_USER_REQUEST", | ||
TRANSAK_LOGOUT_USER_REQUEST = "TRANSAK_LOGOUT_USER_REQUEST" | ||
} | ||
@@ -111,4 +125,6 @@ | ||
close: () => void; | ||
getUser: () => void; | ||
logoutUser: () => void; | ||
} | ||
export { Transak, TransakConfig }; |
@@ -1,2 +0,2 @@ | ||
import N from"events";var i=(o=>(o.STAGING="STAGING",o.PRODUCTION="PRODUCTION",o))(i||{});var s=(n=>(n.TRANSAK_WIDGET_INITIALISED="TRANSAK_WIDGET_INITIALISED",n.TRANSAK_ORDER_CREATED="TRANSAK_ORDER_CREATED",n.TRANSAK_ORDER_SUCCESSFUL="TRANSAK_ORDER_SUCCESSFUL",n.TRANSAK_ORDER_CANCELLED="TRANSAK_ORDER_CANCELLED",n.TRANSAK_ORDER_FAILED="TRANSAK_ORDER_FAILED",n.TRANSAK_WALLET_REDIRECTION="TRANSAK_WALLET_REDIRECTION",n.TRANSAK_WIDGET_CLOSE_REQUEST="TRANSAK_WIDGET_CLOSE_REQUEST",n.TRANSAK_WIDGET_CLOSE="TRANSAK_WIDGET_CLOSE",n))(s||{});function d(e,a,o){return` | ||
import p from"events";var i=(t=>(t.DEVELOPMENT="DEVELOPMENT",t.STAGING="STAGING",t.PRODUCTION="PRODUCTION",t))(i||{});var s=(n=>(n.TRANSAK_WIDGET_INITIALISED="TRANSAK_WIDGET_INITIALISED",n.TRANSAK_ORDER_CREATED="TRANSAK_ORDER_CREATED",n.TRANSAK_ORDER_SUCCESSFUL="TRANSAK_ORDER_SUCCESSFUL",n.TRANSAK_ORDER_CANCELLED="TRANSAK_ORDER_CANCELLED",n.TRANSAK_ORDER_FAILED="TRANSAK_ORDER_FAILED",n.TRANSAK_WALLET_REDIRECTION="TRANSAK_WALLET_REDIRECTION",n.TRANSAK_WIDGET_CLOSE_REQUEST="TRANSAK_WIDGET_CLOSE_REQUEST",n.TRANSAK_WIDGET_CLOSE="TRANSAK_WIDGET_CLOSE",n.TRANSAK_USER_INFO_RECEIVED="TRANSAK_USER_INFO_RECEIVED",n.TRANSAK_GET_USER_REQUEST="TRANSAK_GET_USER_REQUEST",n.TRANSAK_LOGOUT_USER_REQUEST="TRANSAK_LOGOUT_USER_REQUEST",n))(s||{});function A(e,o,r){return` | ||
#transakRoot { | ||
@@ -15,4 +15,4 @@ z-index: 9997; | ||
position: fixed; | ||
width: ${a}; | ||
height: calc(${o} - 24px); | ||
width: ${o}; | ||
height: calc(${r} - 24px); | ||
top: 50%; | ||
@@ -62,3 +62,3 @@ left: 50%; | ||
} | ||
`}function A(e){let{themeColor:a="1461db",widgetWidth:o="480px",widgetHeight:t="650px"}=e,r=document.createElement("style");return r.innerHTML=d(a,o,t),document.getElementsByTagName("head")[0]?.appendChild(r),r}var T=` | ||
`}function c(e){let{themeColor:o="1461db",widgetWidth:r="480px",widgetHeight:t="650px"}=e,a=document.createElement("style");return a.innerHTML=A(o,r,t),document.getElementsByTagName("head")[0]?.appendChild(a),a}var _=` | ||
<svg id="transakCloseIcon" viewBox="0 0 612 612" fill="currentColor" xmlns="http://www.w3.org/2000/svg"> | ||
@@ -71,8 +71,8 @@ <path d="M306,0C136.992,0,0,136.992,0,306s136.992,306,306,306c168.988,0,306-137.012,306-306S475.008,0,306,0z M414.19,387.147 | ||
</svg> | ||
`;import I from"query-string";import p from"pako";var l={STAGING:"https://global-stg.transak.com",PRODUCTION:"https://global.transak.com"};function R(e){let{environment:a="STAGING"}=e,o={},t="";return Object.keys(e).forEach(r=>{if(!["environment","widgetWidth","widgetHeight"].includes(r)){if(["walletAddressesData","userData"].includes(r)){try{o[r]=JSON.stringify(e[r])}catch{}return}if(["nftData","sourceTokenData","cryptoCurrencyData"].includes(r)){try{o[r]=btoa(JSON.stringify(e[r]))}catch{}return}if(["calldata"].includes(r)){try{o[r]=btoa(String.fromCharCode.apply(null,p.deflate(e[r])))}catch{}return}o[r]=e[r]}}),t=I.stringify(o,{arrayFormat:"comma"}),`${l[a]}?${t}`}function S(e,a){let o=R(e),t=document.createElement("div");return t.id="transakRoot",t.innerHTML=` | ||
`;import N from"query-string";import I from"pako";var m={DEVELOPMENT:"https://localhost:5005/",STAGING:"https://global-stg.transak.com",PRODUCTION:"https://global.transak.com"};function d(e){let{environment:o="STAGING"}=e,r={},t="";return Object.keys(e).forEach(a=>{if(!["environment","widgetWidth","widgetHeight"].includes(a)){if(["walletAddressesData","userData"].includes(a)){try{r[a]=JSON.stringify(e[a])}catch{}return}if(["nftData","sourceTokenData","cryptoCurrencyData"].includes(a)){try{r[a]=btoa(JSON.stringify(e[a]))}catch{}return}if(["calldata"].includes(a)){try{r[a]=btoa(String.fromCharCode.apply(null,I.deflate(e[a])))}catch{}return}r[a]=e[a]}}),t=N.stringify(r,{arrayFormat:"comma"}),`${m[o]}?${t}`}function S(e,o){let r=d(e),t=document.createElement("div");return t.id="transakRoot",t.innerHTML=` | ||
<div class="transak-modal"> | ||
${T} | ||
<iframe id="transakIframe" allow="camera;microphone;payment" src="${o}"></iframe> | ||
${_} | ||
<iframe id="transakIframe" allow="camera;microphone;payment" src="${r}"></iframe> | ||
</div> | ||
`,t.onclick=()=>a(),document.getElementsByTagName("body")[0].appendChild(t),document.getElementById("transakCloseIcon")?.addEventListener("click",()=>a()),t}function _(e,a){return function(t){if(t?.data?.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}),a();break}}}}var E=new N.EventEmitter,m=class{#e;#a;#r;#n;#t;#o=!1;static ENVIRONMENTS=i;static EVENTS=s;constructor(a){if(!a?.apiKey)throw new Error("[Transak SDK] => Please enter your API Key");this.#e=a,this.#t=_(E,this.close)}static on=(a,o)=>{a==="*"?Object.keys(s).forEach(t=>{E.on(s[t],o)}):s[a]&&E.on(a,o)};init=()=>{this.#o||(this.openModal(),this.#o=!0)};openModal=()=>{window.addEventListener("message",this.#t),this.#a=A(this.#e),this.#r=S(this.#e,this.#s),this.#n=document.getElementById("transakIframe")};close=()=>{this.#a?.remove(),this.#r?.remove(),this.#i(),this.#o=!1};#s=()=>{this.#n?.contentWindow?.postMessage({event_id:"TRANSAK_WIDGET_CLOSE_REQUEST",data:!0},"*")};#i=()=>{E.removeAllListeners(),window.removeEventListener("message",this.#t)}};export{m as Transak}; | ||
`,t.onclick=()=>o(),document.getElementsByTagName("body")[0].appendChild(t),document.getElementById("transakCloseIcon")?.addEventListener("click",()=>o()),t}function l(e,o){return function(t){if(t?.data?.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}),o();break}case"TRANSAK_USER_INFO_RECEIVED":{e.emit("TRANSAK_USER_INFO_RECEIVED",{eventName:"TRANSAK_USER_INFO_RECEIVED",status:t.data.data});break}}}}var E=new p.EventEmitter,T=class{#e;#r;#n;#t;#o;#a=!1;static ENVIRONMENTS=i;static EVENTS=s;constructor(o){if(!o?.apiKey)throw new Error("[Transak SDK] => Please enter your API Key");this.#e=o,this.#o=l(E,this.close)}static on=(o,r)=>{o==="*"?Object.keys(s).forEach(t=>{E.on(s[t],r)}):s[o]&&E.on(o,r)};init=()=>{this.#a||(this.openModal(),this.#a=!0)};openModal=()=>{window.addEventListener("message",this.#o),this.#r=c(this.#e),this.#n=S(this.#e,this.#s),this.#t=document.getElementById("transakIframe")};close=()=>{this.#r?.remove(),this.#n?.remove(),this.#i(),this.#a=!1};getUser=()=>{this.#t?.contentWindow?.postMessage({event_id:"TRANSAK_GET_USER_REQUEST"},"*")};logoutUser=()=>{this.#t?.contentWindow?.postMessage({event_id:"TRANSAK_LOGOUT_USER_REQUEST"},"*")};#s=()=>{this.#t?.contentWindow?.postMessage({event_id:"TRANSAK_WIDGET_CLOSE_REQUEST"},"*")};#i=()=>{E.removeAllListeners(),window.removeEventListener("message",this.#o)}};export{T as Transak}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@transak/transak-sdk", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "Transak SDK that allows you to easily integrate fiat on/off ramp", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -31,3 +31,3 @@ # Transak SDK | ||
// To get all the events | ||
// To get all SDK events | ||
Transak.on('*', (data) => { | ||
@@ -34,0 +34,0 @@ console.log(data); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
57554
287