@frak-labs/core-sdk 1.0.1-beta.7f000c0f → 1.0.1
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/cdn/bundle.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var FrakSDK=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=(e,t)=>()=>(e&&(t=e(e=0)),t);async function n(e,t,n){return await e.request({method:`frak_displayEmbeddedWallet`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function r(e,{steps:t,metadata:n},r){return await e.request({method:`frak_displayModal`,params:r?[t,n,e.config.metadata,r]:[t,n,e.config.metadata]})}async function i(e,t,n){return await e.request({method:`frak_displaySharingPage`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}let a=`https://backend.frak.id`;function o(e){return e.includes(`localhost:3000`)||e.includes(`localhost:3010`)}function s(e){return o(e)?`https://localhost:3030`:e.includes(`wallet-dev.frak.id`)||e.includes(`wallet.gcp-dev.frak.id`)?`https://backend.gcp-dev.frak.id`:a}function c(e){if(e)return s(e);if(typeof window<`u`){let e=window.FrakSetup?.client?.config?.walletUrl;if(e)return s(e)}return a}let l=`frak-client-id`;function u(){return typeof crypto<`u`&&crypto.randomUUID?crypto.randomUUID():`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)})}function d(){if(typeof window>`u`||!window.localStorage)return
|
|
2
|
-
`);super(o,n.cause?{cause:n.cause}:void 0),Object.defineProperty(this,`details`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`docsPath`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`metaMessages`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`shortMessage`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`version`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`name`,{enumerable:!0,configurable:!0,writable:!0,value:`BaseError`}),this.details=r,this.docsPath=i,this.metaMessages=n.metaMessages,this.name=n.name??this.name,this.shortMessage=t,this.version=D}walk(e){return be(this,e)}}})),Se,Ce=t((()=>{xe(),Se=class extends k{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`,{name:`SizeExceedsPaddingSizeError`})}}}));function A(e,{dir:t,size:n=32}={}){return typeof e==`string`?we(e,{dir:t,size:n}):Te(e,{dir:t,size:n})}function we(e,{dir:t,size:n=32}={}){if(n===null)return e;let r=e.replace(`0x`,``);if(r.length>n*2)throw new Se({size:Math.ceil(r.length/2),targetSize:n,type:`hex`});return`0x${r[t===`right`?`padEnd`:`padStart`](n*2,`0`)}`}function Te(e,{dir:t,size:n=32}={}){if(n===null)return e;if(e.length>n)throw new Se({size:e.length,targetSize:n,type:`bytes`});let r=new Uint8Array(n);for(let i=0;i<n;i++){let a=t===`right`;r[a?i:n-i-1]=e[a?i:e.length-i-1]}return r}var Ee=t((()=>{Ce()})),De,Oe,ke=t((()=>{xe(),De=class extends k{constructor({max:e,min:t,signed:n,size:r,value:i}){super(`Number "${i}" is not in safe ${r?`${r*8}-bit ${n?`signed`:`unsigned`} `:``}integer range ${e?`(${t} to ${e})`:`(above ${t})`}`,{name:`IntegerOutOfRangeError`})}},Oe=class extends k{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:`SizeOverflowError`})}}}));function j(e,{size:t}){if(_e(e)>t)throw new Oe({givenSize:_e(e),maxSize:t})}var Ae=t((()=>{ke(),ve()}));function je(e,t={}){return typeof e==`number`||typeof e==`bigint`?Ne(e,t):typeof e==`string`?Pe(e,t):typeof e==`boolean`?Me(e,t):M(e,t)}function Me(e,t={}){let n=`0x${Number(e)}`;return typeof t.size==`number`?(j(n,{size:t.size}),A(n,{size:t.size})):n}function M(e,t={}){let n=``;for(let t=0;t<e.length;t++)n+=Fe[e[t]];let r=`0x${n}`;return typeof t.size==`number`?(j(r,{size:t.size}),A(r,{dir:`right`,size:t.size})):r}function Ne(e,t={}){let{signed:n,size:r}=t,i=BigInt(e),a;r?a=n?(1n<<BigInt(r)*8n-1n)-1n:2n**(BigInt(r)*8n)-1n:typeof e==`number`&&(a=BigInt(2**53-1));let o=typeof a==`bigint`&&n?-a-1n:0;if(a&&i>a||i<o){let t=typeof e==`bigint`?`n`:``;throw new De({max:a?`${a}${t}`:void 0,min:`${o}${t}`,signed:n,size:r,value:`${e}${t}`})}let s=`0x${(n&&i<0?(1n<<BigInt(r*8))+BigInt(i):i).toString(16)}`;return r?A(s,{size:r}):s}function Pe(e,t={}){return M(Ie.encode(e),t)}var Fe,Ie;function Le(e,t={}){return typeof e==`number`||typeof e==`bigint`?Be(e,t):typeof e==`boolean`?Re(e,t):E(e)?N(e,t):Ve(e,t)}function Re(e,t={}){let n=new Uint8Array(1);return n[0]=Number(e),typeof t.size==`number`?(j(n,{size:t.size}),A(n,{size:t.size})):n}function ze(e){if(e>=P.zero&&e<=P.nine)return e-P.zero;if(e>=P.A&&e<=P.F)return e-(P.A-10);if(e>=P.a&&e<=P.f)return e-(P.a-10)}function N(e,t={}){let n=e;t.size&&(j(n,{size:t.size}),n=A(n,{dir:`right`,size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);let i=r.length/2,a=new Uint8Array(i);for(let e=0,t=0;e<i;e++){let n=ze(r.charCodeAt(t++)),i=ze(r.charCodeAt(t++));if(n===void 0||i===void 0)throw new k(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);a[e]=n*16+i}return a}function Be(e,t){return N(Ne(e,t))}function Ve(e,t={}){let n=He.encode(e);return typeof t.size==`number`?(j(n,{size:t.size}),A(n,{dir:`right`,size:t.size})):n}var He,P,Ue,We;function Ge(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function Ke(e,...t){if(!Ge(e))throw Error(`Uint8Array expected`);if(t.length>0&&!t.includes(e.length))throw Error(`Uint8Array expected of length `+t+`, got length=`+e.length)}function qe(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function Je(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}var Ye,Xe;function Ze(e,t){let n=t||`hex`,r=Xe(E(e,{strict:!1})?Le(e):e);return n===`bytes`?r:je(r)}var Qe;function $e(e,t){if(F.has(`${e}.${t}`))return F.get(`${e}.${t}`);let n=t?`${t}${e.toLowerCase()}`:e.substring(2).toLowerCase(),r=Ze(Ve(n),`bytes`),i=(t?n.substring(`${t}0x`.length):n).split(``);for(let e=0;e<40;e+=2)r[e>>1]>>4>=8&&i[e]&&(i[e]=i[e].toUpperCase()),(r[e>>1]&15)>=8&&i[e+1]&&(i[e+1]=i[e+1].toUpperCase());let a=`0x${i.join(``)}`;return F.set(`${e}.${t}`,a),a}var F;function I(e,t){let{strict:n=!0}=t??{},r=`${e}.${n}`;if(L.has(r))return L.get(r);let i=et.test(e)?e.toLowerCase()===e?!0:n?$e(e)===e:!0:!1;return L.set(r,i),i}var et,L;function tt(e,t){if(!I(e,{strict:!1}))throw new Qe({address:e});if(!I(t,{strict:!1}))throw new Qe({address:t});return e.toLowerCase()===t.toLowerCase()}let R=256,z;function nt(e=11){if(!z||R+e>256*2){z=``,R=0;for(let e=0;e<256;e++)z+=(256+Math.random()*256|0).toString(16).substring(1)}return z.substring(R,R+++e)}function rt({domain:e}={}){return Ze(je((e??window.location.host).replace(`www.`,``)))}let it={parseError:-32700,invalidRequest:-32600,methodNotFound:-32601,invalidParams:-32602,internalError:-32603,serverError:-32e3,clientNotConnected:-32001,configError:-32002,corruptedResponse:-32003,clientAborted:-32004,walletNotConnected:-32005,serverErrorForInteractionDelegation:-32006,userRejected:-32007};var B=class extends Error{constructor(e,t,n){super(t),this.code=e,this.data=n}toJSON(){return{code:this.code,message:this.message,data:this.data}}},V=class{_promise;_resolve;_reject;constructor(){this._promise=new Promise((e,t)=>{this._resolve=e,this._reject=t})}get promise(){return this._promise}resolve=e=>{this._resolve?.(e)};reject=e=>{this._reject?.(e)}};function at(e){let{emittingTransport:t,listeningTransport:n,targetOrigin:r,middleware:i=[],lifecycleHandlers:a}=e,o=new Map;function s(e){return typeof e!=`object`||!e?!1:`clientLifecycle`in e||`iframeLifecycle`in e}function c(e){return typeof e!=`object`||!e?!1:`id`in e&&`topic`in e&&`data`in e}async function l(e){try{`clientLifecycle`in e&&a?.clientLifecycle?await a.clientLifecycle(e,{origin:r,source:null}):`iframeLifecycle`in e&&a?.iframeLifecycle&&await a.iframeLifecycle(e,{origin:r,source:null})}catch(e){console.error(`[RPC Client] Lifecycle handler error:`,e)}}async function u(e){let t={origin:r,source:null};for(let n of i)n.onRequest&&await n.onRequest(e,t);return e}async function d(e,t){let n={origin:r,source:null},a=t;for(let t of i)t.onResponse&&(a=await t.onResponse(e,a,n));return a}async function f(e){try{let t=new URL(e.origin).origin.toLowerCase(),n=new URL(r).origin.toLowerCase();if(t!==n){console.log(`Not expected origin`,t,n);return}}catch(e){console.error(`[RPC Client] Invalid origin`,e);return}if(s(e.data)){await l(e.data);return}if(!c(e.data))return;let t;try{let n=e.data.data,r=n instanceof Uint8Array||ArrayBuffer.isView(n)?{result:n}:n;t=await d(e.data,r)}catch(e){console.error(`[RPC Client] Middleware error on response:`,e);return}let n=o.get(e.data.id);n&&n(t)}async function p(e){let n=e;try{n=await u(e)}catch(e){throw console.error(`[RPC Client] Middleware error on request:`,e),e}t.postMessage(n,r)}function m(e){t.postMessage(e,r)}function h(){return`${Date.now()}-${Math.random().toString(36).substring(2,9)}`}n.addEventListener(`message`,f);function g(e){let t=h(),n=new V;return o.set(t,e=>{e.error?n.reject(new B(e.error.code,e.error.message,e.error.data)):n.resolve(e.result),o.delete(t)}),p({id:t,topic:e.method,data:{method:e.method,params:e.params}}).catch(e=>{o.delete(t),n.reject(e)}),n.promise}function _(e,t){let n=h();return o.set(n,e=>{e.error?(console.error(`[RPC Client] Listener error:`,e.error),o.delete(n)):t(e.result)}),p({id:n,topic:e.method,data:{method:e.method,params:e.params}}).catch(e=>{console.error(`[RPC Client] Failed to send listener request:`,e),o.delete(n)}),()=>{o.delete(n)}}function ee(){n.removeEventListener(`message`,f),o.clear()}return{request:g,listen:_,sendLifecycle:m,cleanup:ee}}function ot(e){return new TextEncoder().encode(JSON.stringify(e))}function st(e){try{return JSON.parse(new TextDecoder().decode(e))}catch{return null}}function H(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function U(e){let t=e.length%4;return Uint8Array.from(atob(e.replace(/-/g,`+`).replace(/_/g,`/`).padEnd(e.length+(t===0?0:4-t),`=`)),e=>e.charCodeAt(0))}function ct(e){return H(ot(e))}function lt(e,t,n,r,i,a){let o=ct(ut({redirectUrl:t.redirectUrl,directExit:t.directExit,lang:t.lang,merchantId:n,metadata:{name:r,css:a,logoUrl:t.metadata?.logoUrl,homepageLink:t.metadata?.homepageLink},clientId:i})),s=new URL(e);return s.pathname=`/sso`,s.searchParams.set(`p`,o),s.toString()}function ut(e){return{r:e.redirectUrl,cId:e.clientId,d:e.directExit,l:e.lang,m:e.merchantId,md:{n:e.metadata?.name,css:e.metadata?.css,l:e.metadata?.logoUrl,h:e.metadata?.homepageLink}}}let dt=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,ft=`frak-sso`;async function pt(e,t){let{metadata:n,customizations:r,walletUrl:i}=e.config;if(t.openInSameWindow??!!t.redirectUrl)return await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]});let a=t.ssoPopupUrl??lt(i??`https://wallet.frak.id`,t,rt(),n.name,d(),r?.css),o=window.open(a,ft,dt);if(!o)throw Error(`Popup was blocked. Please allow popups for this site.`);return o.focus(),await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]})??{}}async function mt(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}function W(e){return`r`in e&&!(`v`in e)}function G(e){return`v`in e&&e.v===2}function K(e,t,n){if(!e){console.debug(`[Frak] No client provided, skipping event tracking`);return}try{e.openPanel?.track(t,n)}catch(e){console.debug(`[Frak] Failed to track event:`,t,e)}}function ht(e){return st(U(e))}let q=`nexus-wallet-backup`,gt=`frakwallet://`;function _t(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}function vt(e){return`intent://${e.slice(13)}#Intent;scheme=frakwallet;end`}function yt(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=_t()&&J(e)?vt(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function J(e){return e.startsWith(gt)}let bt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function xt(e){return typeof e==`string`&&bt.test(e)}function St(e){let t=e.replace(/-/g,``),n=new Uint8Array(16);for(let e=0;e<16;e++)n[e]=Number.parseInt(t.substring(e*2,e*2+2),16);return n}function Ct(e){let t=``;for(let n=0;n<16;n++)t+=e[n].toString(16).padStart(2,`0`);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20,32)}`}function wt(e){if(!xt(e.m)||!Number.isInteger(e.t)||e.t<0||e.t>4294967295)return null;let t=typeof e.c==`string`&&e.c.length>0,n=typeof e.w==`string`&&I(e.w);if(!t&&!n||t&&!xt(e.c))return null;let r=new Uint8Array(21+(t?16:0)+(n?20:0)),i=new DataView(r.buffer,r.byteOffset,r.byteLength),a=0;return r[a++]=2|(t?16:0)|(n?32:0),r.set(St(e.m),a),a+=16,i.setUint32(a,e.t,!1),a+=4,t&&(r.set(St(e.c),a),a+=16),n&&(r.set(N(e.w),a),a+=20),r}function Tt(e){if(e.length<21)return null;let t=e[0];if((t&15)!=2||t&192)return null;let n=(t&16)!=0,r=(t&32)!=0;if(!n&&!r)return null;let i=21+(n?16:0)+(r?20:0);if(e.length!==i)return null;let a=1,o=Ct(e.subarray(a,a+16));a+=16;let s=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(a,!1);a+=4;let c={v:2,m:o,t:s};if(n&&(c.c=Ct(e.subarray(a,a+16)),a+=16),r){let t=M(e.subarray(a,a+20),{size:20});if(!I(t))return null;c.w=t,a+=20}return c}let Y=`fCtx`;function Et(e){if(e)try{if(G(e)){let t=wt(e);return t?H(t):void 0}return H(N(e.r))}catch(t){console.error(`Error compressing Frak context`,{e:t,context:e})}}function Dt(e){if(!(!e||e.length===0))try{let t=U(e);if(t.length!==20)return Tt(t)||void 0;let n=M(t,{size:20});if(I(n))return{r:n}}catch(t){console.error(`Error decompressing Frak context`,{e:t,context:e})}}function Ot({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(Y);return t?Dt(t):null}let kt=`frak`;function At(e,t){let n=G(e);return{utm_source:t.utmSource??kt,utm_medium:t.utmMedium??`referral`,utm_campaign:t.utmCampaign??(n?e.m:void 0),utm_content:t.utmContent,utm_term:t.utmTerm,via:t.via??kt,ref:t.ref??(n?e.c:void 0)}}function jt(e,t,n){let r=At(t,n??{});for(let[t,n]of Object.entries(r))n===void 0||n===``||e.searchParams.has(t)||e.searchParams.set(t,n)}function Mt({url:e,context:t,attribution:n}){if(!e)return null;let r=Et(t);if(!r)return null;let i=new URL(e);return i.searchParams.set(Y,r),jt(i,t,n),i.toString()}function Nt(e){let t=new URL(e);return t.searchParams.delete(Y),t.toString()}function Pt({url:e,context:t}){if(!window.location?.href||typeof window>`u`){console.error(`No window found, can't update context`);return}let n=e??window.location.href,r;r=t===null?Nt(n):Mt({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}let Ft={compress:Et,decompress:Dt,parse:Ot,update:Mt,remove:Nt,replaceUrl:Pt},X={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function It(e){return e&&e in X?e:`eur`}function Lt(e){return e?X[e]??X.eur:X.eur}function Rt(e,t){let n=Lt(t),r=It(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function zt(e){return e?`${e}Amount`:`eurAmount`}let Z={id:`frak-wallet`,name:`frak-wallet`,title:`Frak Wallet`,allow:`publickey-credentials-get *; clipboard-write; web-share *`,style:{width:`0`,height:`0`,border:`0`,position:`absolute`,zIndex:2000001,top:`-1000px`,left:`-1000px`,colorScheme:`auto`}};function Bt({walletBaseUrl:e,config:t}){let n=document.querySelector(`#frak-wallet`);n&&n.remove();let r=document.createElement(`iframe`);r.id=Z.id,r.name=Z.name,r.allow=Z.allow,r.style.zIndex=Z.style.zIndex.toString(),Vt({iframe:r,isVisible:!1});let i=t?.walletUrl??e??`https://wallet.frak.id`,a=d();return r.src=`${i}/listener?clientId=${encodeURIComponent(a)}`,new Promise(e=>{r.addEventListener(`load`,()=>e(r)),document.body.appendChild(r)})}function Vt({iframe:e,isVisible:t}){if(!t){e.style.width=`0`,e.style.height=`0`,e.style.border=`0`,e.style.position=`fixed`,e.style.top=`-1000px`,e.style.left=`-1000px`;return}e.style.position=`fixed`,e.style.top=`0`,e.style.left=`0`,e.style.width=`100%`,e.style.height=`100%`,e.style.pointerEvents=`auto`}function Ht(e=`/listener`){if(!window.opener)return null;let t=t=>{try{return t.location.origin===window.location.origin&&t.location.pathname===e}catch{return!1}};if(t(window.opener))return window.opener;try{let e=window.opener.frames;for(let n=0;n<e.length;n++)if(t(e[n]))return e[n];return null}catch(t){return console.error(`[findIframeInOpener] Error finding iframe with pathname ${e}:`,t),null}}function Ut(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent;return!!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1)}let Wt=Ut();function Gt(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent.toLowerCase();return e.includes(`instagram`)||e.includes(`fban`)||e.includes(`fbav`)||e.includes(`facebook`)}let Kt=Gt();function qt(e){Wt&&e.startsWith(`https://`)?window.location.href=`x-safari-https://${e.slice(8)}`:Wt&&e.startsWith(`http://`)?window.location.href=`x-safari-http://${e.slice(7)}`:window.location.href=`https://backend.frak.id/common/social?u=${encodeURIComponent(e)}`}function Jt({perCall:e,defaults:t,productUtmContent:n}){if(e===null)return;let r=e!==void 0,i=t!==void 0&&Object.keys(t).length>0;if(!r&&!i&&!(n!==void 0&&n!==``))return;let a={...t,...e??{}},o=n??e?.utmContent;return o!==void 0&&o!==``?a.utmContent=o:delete a.utmContent,a}async function Yt(e,t){try{await e.request({method:`frak_sendInteraction`,params:[t,{clientId:d()}]})}catch{console.warn(`[Frak SDK] Failed to send interaction:`,t.type)}}function Xt(e,t,n){let r=typeof window<`u`?window.location.href:void 0;return G(t)?(K(e,`user_referred_started`,{referrerClientId:t.c,referrerWallet:t.w,walletStatus:n?.key}),Yt(e,{type:`arrival`,referrerClientId:t.c,referrerMerchantId:t.m,referrerWallet:t.w,referralTimestamp:t.t,landingUrl:r}),!0):W(t)?(K(e,`user_referred_started`,{referrer:t.r,walletStatus:n?.key}),Yt(e,{type:`arrival`,referrerWallet:t.r,landingUrl:r}),!0):!1}function Zt(e,t){let n=d();return!n&&!t?null:{v:2,m:e,t:Math.floor(Date.now()/1e3),...n?{c:n}:{},...t?{w:t}:{}}}function Qt(e,t){return G(e)?e.w&&t?.wallet?tt(e.w,t.wallet):e.c?d()===e.c:!1:W(e)&&t?.wallet?tt(e.r,t.wallet):!1}function $t(e,{walletStatus:t,frakContext:n,options:r}){if(!n)return`no-referrer`;if(Qt(n,t))return`self-referral`;if(!Xt(e,n,t))return`no-referrer`;let i=G(n)?n.m:r?.merchantId,a=r?.alwaysAppendUrl&&i?Zt(i,t?.wallet):null;return Ft.replaceUrl({url:window.location?.href,context:a}),K(e,`user_referred_completed`,{status:`success`}),`success`}async function en(e,{options:t}={}){let n=Ft.parse({url:window.location.href}),r=await an(e);try{return $t(e,{walletStatus:r,frakContext:n,options:t})}catch(e){console.warn(`Error processing referral`,{error:e})}}let tn=`frak:referral-success`;async function nn(e){try{await en(e)===`success`&&window.dispatchEvent(new Event(tn))}catch(e){console.warn(`[Frak] Referral setup failed`,e)}}async function rn(e){if(typeof window>`u`){console.warn(`[Frak] No window found, can't track purchase`);return}let t=window.sessionStorage.getItem(`frak-wallet-interaction-token`),n=d();if(!t&&!n){console.warn(`[Frak] No identity found, skipping purchase check`);return}let r=e.merchantId??await T.resolveMerchantId();if(!r){console.warn(`[Frak] No merchant id found, skipping purchase check`);return}let i={Accept:`application/json`,"Content-Type":`application/json`};t&&(i[`x-wallet-sdk-auth`]=t),n&&(i[`x-frak-client-id`]=n);let a=c();await fetch(`${a}/user/track/purchase`,{method:`POST`,headers:i,body:JSON.stringify({customerId:e.customerId,orderId:e.orderId,token:e.token,merchantId:r})})}function an(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(on(e,t),t));let n=new V,r=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},i=>{on(e,i),t(i),r||=(n.resolve(i),!0)}),n.promise}function on(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?(window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken),fe(t.interactionToken)):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function sn(e,{metadata:t,login:n}){return Q(e,{steps:{login:n??{}},metadata:t})}function Q(e,t){function n(n){return Q(e,{...t,steps:{...t.steps,sendTransaction:n}})}function i(n){return Q(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function a(n,r){return Q(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function o(n,i){return n&&(t.metadata=n(t.metadata??{})),await r(e,t,i)}return{params:t,sendTx:n,reward:i,sharing:a,display:o}}async function cn(e,{tx:t,metadata:n}){return(await r(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}function ln(){return nt(96)}async function un(e,{siwe:t,metadata:n}){let i=e.config?.domain??window.location.host,a=t?.statement??`I confirm that I want to use my Frak wallet on: ${e.config.metadata.name}`;return(await r(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:a,nonce:t?.nonce??ln(),uri:t?.uri??`https://${i}`,version:t?.version??`1`,domain:i}}}})).siweAuthenticate}function dn(){return()=>{}}var fn=class{constructor(e){this.baseUrl=e.baseUrl,this.headers={"Content-Type":`application/json`,...e.defaultHeaders},this.maxRetries=e.maxRetries??3,this.initialRetryDelay=e.initialRetryDelay??500}async resolveHeaders(){let e={};for(let[t,n]of Object.entries(this.headers)){let r=await n;r!==null&&(e[t]=r)}return e}addHeader(e,t){this.headers[e]=t}async post(e,t,n,r){try{let r=await fetch(e,{method:`POST`,headers:await this.resolveHeaders(),body:t?JSON.stringify(t??{}):void 0,keepalive:!0,...n});if(r.status===401)return null;if(r.status!==200&&r.status!==202)throw Error(`HTTP error! status: ${r.status}`);let i=await r.text();return i?JSON.parse(i):null}catch(i){if(r<this.maxRetries){let i=this.initialRetryDelay*2**r;return await new Promise(e=>setTimeout(e,i)),this.post(e,t,n,r+1)}return console.error(`Max retries reached:`,i),null}}async fetch(e,t,n={}){let r=`${this.baseUrl}${e}`;return this.post(r,t,n,0)}},pn=class{constructor(e){this.groups=[],this.queue=[],this.options=e;let t={"openpanel-client-id":e.clientId};e.clientSecret&&(t[`openpanel-client-secret`]=e.clientSecret),t[`openpanel-sdk-name`]=e.sdk||`node`,t[`openpanel-sdk-version`]=e.sdkVersion||`1.3.0`,this.api=new fn({baseUrl:e.apiUrl||`https://api.openpanel.dev`,defaultHeaders:t})}init(){}ready(){this.options.disabled=!1,this.options.waitForProfile=!1,this.flush()}shouldQueue(e){return!!(this.options.disabled||this.options.waitForProfile&&!this.profileId||e.type===`replay`&&!this.sessionId)}addQueue(e){e.type===`track`&&(e.payload.properties={...e.payload.properties??{},__timestamp:new Date().toISOString()}),this.queue.push(e)}async send(e){if(this.options.filter&&!this.options.filter(e))return Promise.resolve();if(this.shouldQueue(e))return this.addQueue(e),Promise.resolve();let t=await this.api.fetch(`/track`,e,{keepalive:e.type!==`replay`});this.deviceId=t?.deviceId;let n=!!this.sessionId;return this.sessionId=t?.sessionId,!n&&this.sessionId&&this.flush(),t}setGlobalProperties(e){this.global={...this.global,...e}}track(e,t){this.log(`track event`,e,t);let{groups:n,profileId:r,...i}=t??{},a=[...new Set([...this.groups,...n??[]])];return this.send({type:`track`,payload:{name:e,profileId:r??this.profileId,groups:a.length>0?a:void 0,properties:{...this.global??{},...i}}})}identify(e){if(this.log(`identify user`,e),e.profileId&&(this.profileId=e.profileId,this.flush()),Object.keys(e).length>1)return this.send({type:`identify`,payload:{...e,properties:{...this.global,...e.properties}}})}upsertGroup(e){return this.log(`upsert group`,e),this.send({type:`group`,payload:e})}setGroup(e){return this.log(`set group`,e),this.groups.includes(e)||(this.groups=[...this.groups,e]),this.send({type:`assign_group`,payload:{groupIds:[e],profileId:this.profileId}})}setGroups(e){return this.log(`set groups`,e),this.groups=[...new Set([...this.groups,...e])],this.send({type:`assign_group`,payload:{groupIds:e,profileId:this.profileId}})}alias(e){}increment(e){return this.send({type:`increment`,payload:e})}decrement(e){return this.send({type:`decrement`,payload:e})}revenue(e,t){let n=t?.deviceId;return delete t?.deviceId,this.track(`revenue`,{...t??{},...n?{__deviceId:n}:{},__revenue:e})}getDeviceId(){return this.deviceId??``}getSessionId(){return this.sessionId??``}fetchDeviceId(){return Promise.resolve(this.deviceId??``)}clear(){this.profileId=void 0,this.groups=[],this.deviceId=void 0,this.sessionId=void 0}buildFlushPayload(e){if(e.type===`replay`)return e.payload;if(e.type===`track`){let t=`groups`in e.payload?e.payload.groups??[]:[],n=[...new Set([...this.groups,...t])];return{...e.payload,profileId:e.payload.profileId??this.profileId,groups:n.length>0?n:void 0}}return e.type===`identify`||e.type===`increment`||e.type===`decrement`||e.type===`assign_group`?{...e.payload,profileId:e.payload.profileId??this.profileId}:e.payload}flush(){let e=[];for(let t of this.queue){if(this.shouldQueue(t)){e.push(t);continue}let n=this.buildFlushPayload(t);this.send({...t,payload:n})}this.queue=e}log(...e){this.options.debug&&console.log(`[OpenPanel.dev]`,...e)}},mn=Object.defineProperty,hn=(e,t)=>()=>(e&&(t=e(e=0)),t),gn=(e,t)=>{for(var n in t)mn(e,n,{get:t[n],enumerable:!0})};function _n(e,t){if(typeof document>`u`||typeof window>`u`)return;$&&$();let n=e.maxEventsPerChunk??200,r=e.flushIntervalMs??1e4,i=e.maxPayloadBytes??1048576,a=[],o=0,s=null;function c(e){if(a.length===0)return;let n=JSON.stringify(a);if(new TextEncoder().encode(n).length>i){if(a.length>1){let t=Math.floor(a.length/2),n=a.slice(0,t),r=a.slice(t),i=e&&n.some(e=>e.type===2);a=n,c(i),a=r,c(!1);return}a=[];return}let r=a[0].timestamp,s=a[a.length-1].timestamp;try{t({chunk_index:o,events_count:a.length,is_full_snapshot:e,started_at:new Date(r).toISOString(),ended_at:new Date(s).toISOString(),payload:n}),o+=1,a=[]}catch(e){throw console.error(`[ReplayRecorder] sendChunk failed`,e),e}}function l(e){let t=e||a.some(e=>e.type===2);a.length>=n?c(t):e&&a.length>0&&c(!0)}let u=e.maskAllText!==!1,d=e.unmaskTextSelector,f=dn({emit(e,t){a.push(e),l(!!t)},checkoutEveryNms:r,maskAllInputs:e.maskAllInputs??!0,maskTextSelector:u?`*`:`[data-openpanel-replay-mask]`,maskTextFn:u&&d?(e,t)=>t?.closest(d)?e:e.replace(/\S/g,`*`):void 0,blockSelector:e.blockSelector??`[data-openpanel-replay-block]`,blockClass:e.blockClass,ignoreSelector:e.ignoreSelector});s=setInterval(()=>{a.length>0&&c(a.some(e=>e.type===2))},r);function p(){document.visibilityState===`hidden`&&a.length>0&&c(a.some(e=>e.type===2))}function m(){a.length>0&&c(a.some(e=>e.type===2))}document.addEventListener(`visibilitychange`,p),window.addEventListener(`pagehide`,m),$=()=>{a.length>0&&c(a.some(e=>e.type===2)),s&&=(clearInterval(s),null),document.removeEventListener(`visibilitychange`,p),window.removeEventListener(`pagehide`,m),f?.(),$=null}}function vn(){$&&$()}var $,yn=hn(()=>{"use strict";$=null}),bn={};gn(bn,{startReplayRecorder:()=>_n,stopReplayRecorder:()=>vn});var xn=hn(()=>{"use strict";yn()}),Sn=typeof document<`u`?document.currentScript:null;function Cn(e){return e.replace(/([-_][a-z])/gi,e=>e.toUpperCase().replace(`-`,``).replace(`_`,``))}var wn=class extends pn{constructor(e){if(super({sdk:`web`,sdkVersion:`1.3.0`,...e}),this.options=e,this.lastPath=``,this.pendingRevenues=[],!this.isServer()){try{let e=sessionStorage.getItem(`openpanel-pending-revenues`);if(e){let t=JSON.parse(e);Array.isArray(t)&&(this.pendingRevenues=t)}}catch{this.pendingRevenues=[]}if(this.setGlobalProperties({__referrer:document.referrer}),this.options.trackScreenViews&&(this.trackScreenViews(),setTimeout(()=>this.screenView(),0)),this.options.trackOutgoingLinks&&this.trackOutgoingLinks(),this.options.trackAttributes&&this.trackAttributes(),this.options.sessionReplay?.enabled){let e=this.options.sessionReplay.sampleRate??1;Math.random()<e&&this.loadReplayModule().then(e=>{e&&e.startReplayRecorder(this.options.sessionReplay,e=>{this.send({type:`replay`,payload:{...e}})})})}}}async loadReplayModule(){try{if(typeof __OPENPANEL_REPLAY_URL__<`u`){let e=Sn,t=this.options.sessionReplay?.scriptUrl||e?.src?.replace(`.js`,`-replay.js`)||`https://openpanel.dev/op1-replay.js`;return window.__openpanel_replay?window.__openpanel_replay:new Promise(e=>{let n=document.createElement(`script`);n.src=t,n.onload=()=>{e(window.__openpanel_replay??null)},n.onerror=()=>{console.warn(`[OpenPanel] Failed to load replay script from`,t),e(null)},document.head.appendChild(n)})}return await Promise.resolve().then(()=>(xn(),bn))}catch(e){return console.warn(`[OpenPanel] Failed to load replay module`,e),null}}debounce(e,t){clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(e,t)}isServer(){return typeof document>`u`}trackOutgoingLinks(){this.isServer()||document.addEventListener(`click`,e=>{let t=e.target,n=t.closest(`a`);if(n&&t){let e=n.getAttribute(`href`);if(e?.startsWith(`http`))try{let r=new URL(e),i=window.location.hostname;r.hostname!==i&&super.track(`link_out`,{href:e,text:n.innerText||n.getAttribute(`title`)||t.getAttribute(`alt`)||t.getAttribute(`title`)})}catch{}}})}trackScreenViews(){if(this.isServer())return;let e=history.pushState;history.pushState=function(...t){let n=e.apply(this,t);return window.dispatchEvent(new Event(`pushstate`)),window.dispatchEvent(new Event(`locationchange`)),n};let t=history.replaceState;history.replaceState=function(...e){let n=t.apply(this,e);return window.dispatchEvent(new Event(`replacestate`)),window.dispatchEvent(new Event(`locationchange`)),n},window.addEventListener(`popstate`,()=>{window.dispatchEvent(new Event(`locationchange`))});let n=()=>this.debounce(()=>this.screenView(),50);this.options.trackHashChanges?window.addEventListener(`hashchange`,n):window.addEventListener(`locationchange`,n)}trackAttributes(){this.isServer()||document.addEventListener(`click`,e=>{let t=e.target,n=t.closest(`button`),r=t.closest(`a`),i=n?.getAttribute(`data-track`)?n:r?.getAttribute(`data-track`)?r:null;if(i){let e={};for(let t of i.attributes)t.name.startsWith(`data-`)&&t.name!==`data-track`&&(e[Cn(t.name.replace(/^data-/,``))]=t.value);let t=i.getAttribute(`data-track`);t&&super.track(t,e)}})}track(e,t){return super.track(e,{...t,__path:this.lastPath})}screenView(e,t){if(this.isServer())return;let n,r;typeof e==`string`?(n=e,r=t):(n=window.location.href,r=e),this.lastPath!==n&&(this.lastPath=n,super.track(`screen_view`,{...r??{},__path:n,__title:document.title}))}async flushRevenue(){let e=this.pendingRevenues.map(e=>super.revenue(e.amount,e.properties));await Promise.all(e),this.clearRevenue()}clearRevenue(){if(this.pendingRevenues=[],!this.isServer())try{sessionStorage.removeItem(`openpanel-pending-revenues`)}catch{}}pendingRevenue(e,t){if(this.pendingRevenues.push({amount:e,properties:t}),!this.isServer())try{sessionStorage.setItem(`openpanel-pending-revenues`,JSON.stringify(this.pendingRevenues))}catch{}}};function Tn(e,t){if(typeof window>`u`)return;let n=new URL(window.location.href),r=n.searchParams.get(`sso`);r&&(t.then(()=>{e.sendLifecycle({clientLifecycle:`sso-redirect-complete`,data:{compressed:r}}),console.log(`[SSO URL Listener] Forwarded compressed SSO data to iframe`)}).catch(e=>{console.error(`[SSO URL Listener] Failed to forward SSO data:`,e)}),n.searchParams.delete(`sso`),window.history.replaceState({},``,n.toString()),console.log(`[SSO URL Listener] SSO parameter detected and URL cleaned`))}var En=class e{config;iframe;isSetupDone=!1;lastResponse=null;lastRequest=null;constructor(e,t){this.config=e,this.iframe=t,this.lastRequest=null,this.lastResponse=null}setLastResponse(e,t){this.lastResponse={message:e,response:t,timestamp:Date.now()}}setLastRequest(e){this.lastRequest={event:e,timestamp:Date.now()}}updateSetupStatus(e){this.isSetupDone=e}base64Encode(e){try{return btoa(JSON.stringify(e))}catch(e){return console.warn(`Failed to encode debug data`,e),btoa(`Failed to encode data`)}}getIframeStatus(){return this.iframe?{loading:this.iframe.hasAttribute(`loading`),url:this.iframe.src,readyState:this.iframe.contentDocument?.readyState?+(this.iframe.contentDocument.readyState===`complete`):-1,contentWindow:!!this.iframe.contentWindow,isConnected:this.iframe.isConnected}:null}getNavigatorInfo(){return navigator?{userAgent:navigator.userAgent,language:navigator.language,onLine:navigator.onLine,screenWidth:window.screen.width,screenHeight:window.screen.height,pixelRatio:window.devicePixelRatio}:null}gatherDebugInfo(e){let t=this.getIframeStatus(),n=this.getNavigatorInfo(),r=`Unknown`;return e instanceof B?r=`FrakRpcError: ${e.code} '${e.message}'`:e instanceof Error?r=e.message:typeof e==`string`&&(r=e),{timestamp:new Date().toISOString(),encodedUrl:btoa(window.location.href),encodedConfig:this.config?this.base64Encode(this.config):`no-config`,navigatorInfo:n?this.base64Encode(n):`no-navigator`,iframeStatus:t?this.base64Encode(t):`not-iframe`,lastRequest:this.lastRequest?this.base64Encode(this.lastRequest):`No Frak request logged`,lastResponse:this.lastResponse?this.base64Encode(this.lastResponse):`No Frak response logged`,clientStatus:this.isSetupDone?`setup`:`not-setup`,error:r}}static empty(){return new e}formatDebugInfo(e){let t=this.gatherDebugInfo(e);return`
|
|
1
|
+
var FrakSDK=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=(e,t)=>()=>(e&&(t=e(e=0)),t);async function n(e,t,n){return await e.request({method:`frak_displayEmbeddedWallet`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function r(e,{steps:t,metadata:n},r){return await e.request({method:`frak_displayModal`,params:r?[t,n,e.config.metadata,r]:[t,n,e.config.metadata]})}async function i(e,t,n){return await e.request({method:`frak_displaySharingPage`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}let a=`https://backend.frak.id`;function o(e){return e.includes(`localhost:3000`)||e.includes(`localhost:3010`)}function s(e){return o(e)?`https://localhost:3030`:e.includes(`wallet-dev.frak.id`)||e.includes(`wallet.gcp-dev.frak.id`)?`https://backend.gcp-dev.frak.id`:a}function c(e){if(e)return s(e);if(typeof window<`u`){let e=window.FrakSetup?.client?.config?.walletUrl;if(e)return s(e)}return a}let l=`frak-client-id`;function u(){return typeof crypto<`u`&&crypto.randomUUID?crypto.randomUUID():`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)})}function d(){if(typeof window>`u`||!window.localStorage)return u();let e=localStorage.getItem(l);return e||(e=u(),localStorage.setItem(l,e)),e}var f=class extends Map{maxSize;constructor(e){super(),this.maxSize=e}get(e){let t=super.get(e);return super.has(e)&&(super.delete(e),super.set(e,t)),t}set(e,t){if(super.has(e)&&super.delete(e),super.set(e,t),this.maxSize&&this.size>this.maxSize){let e=super.keys().next().value;e!==void 0&&super.delete(e)}return this}};let p=new f(1024),m=new f(1024),h=3e4,g=new f(1024);async function _(e,{cacheKey:t,cacheTime:n=h}){if(n>0){let e=m.get(t);if(e&&Date.now()-e.created<n)return e.data}let r=g.get(t);if(r&&Date.now()-r<1e3)throw Error(`Cache: ${t} recently failed, backing off`);let i=p.get(t);i||(i=e(),p.set(t,i));try{let e=await i;return m.set(t,{data:e,created:Date.now()}),g.delete(t),e}catch(e){throw g.set(t,Date.now()),e}finally{p.delete(t)}}function ee(e){return{clear:()=>{p.delete(e),m.delete(e)},has:(t=h)=>{let n=m.get(e);return n?Date.now()-n.created<t:!1}}}function te(){p.clear(),m.clear(),g.clear()}let v=`__frakSdkConfig`,ne=`frak-config-cache`,y=`frak-merchant-id`,b={key:ne},x=typeof window<`u`;function S(){return{isResolved:!1,merchantId:``}}let C=null;function re(){if(!x)return null;try{let e=localStorage.getItem(b.key);if(!e)return null;let t=JSON.parse(e);return t.config?.isResolved?(C=t,t):null}catch{return null}}function ie(){return(C??re())?.config}function ae(){let e=C??re();return e?Date.now()-e.timestamp<3e4:!1}function oe(e){if(!(!x||!e.isResolved))try{let t={config:e,timestamp:Date.now()};localStorage.setItem(b.key,JSON.stringify(t)),C=t}catch{}}function se(){if(x){C=null;try{localStorage.removeItem(b.key)}catch{}}}function ce(){x&&(window[v]||(window[v]=ie()??S()))}ce();function w(){return x?window[v]??S():S()}function le(e){x&&window.dispatchEvent(new CustomEvent(`frak:config`,{detail:e}))}function ue(e){return e??(x?window.location.hostname:``)}async function de(e,t,n){try{let r=c(t),i=n?`&lang=${encodeURIComponent(n)}`:``,a=await fetch(`${r}/user/merchant/resolve?domain=${encodeURIComponent(e)}${i}`);if(!a.ok)return;let o=await a.json();if(x)try{sessionStorage.setItem(y,o.merchantId)}catch{}return o}catch{return}}let T={getConfig:w,get isResolved(){return w().isResolved},get isCacheFresh(){return ae()},setCacheScope(e,t){b.key=`${ne}:${`${e}:${t??``}`}`,C=null},setConfig(e){if(x&&(window[v]=e),oe(e),le(e),x&&e.merchantId)try{sessionStorage.setItem(y,e.merchantId)}catch{}},reset(){let e=ie()??S();x&&(window[v]=e),le(e)},clearCache(){if(se(),te(),x)try{sessionStorage.removeItem(y)}catch{}},resolve(e,t,n){let r=ue(e);return r?_(async()=>{let e=await de(r,t,n);if(!e)throw Error(`Config resolution returned empty`);return e},{cacheKey:`sdkConfig:${r}:${n??``}`,cacheTime:1/0}).catch(()=>void 0):Promise.resolve(void 0)},getMerchantId(){let e=w();if(e.isResolved&&e.merchantId)return e.merchantId;if(x)try{return sessionStorage.getItem(y)??void 0}catch{}},async resolveMerchantId(e,t){return T.getMerchantId()||(await T.resolve(e,t))?.merchantId}};async function fe(e){if(typeof window>`u`)return;let t=d();if(!t)return;let n=await T.resolveMerchantId();if(!n)return;let r=`frak-identity-ensured-${n}`;if(!window.sessionStorage.getItem(r))try{let i=c();(await fetch(`${i}/user/identity/ensure`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`,"x-wallet-sdk-auth":e,"x-frak-client-id":t},body:JSON.stringify({merchantId:n})})).ok&&window.sessionStorage.setItem(r,`1`)}catch{}}async function pe(e,t){return _(()=>e.request({method:`frak_getMerchantInformation`}),{cacheKey:`frak_getMerchantInformation`,cacheTime:t?.cacheTime})}async function me(e,t){return _(()=>e.request({method:`frak_getMergeToken`}),{cacheKey:`frak_getMergeToken`,cacheTime:t?.cacheTime})}async function he(e,t){return _(()=>e.request({method:`frak_getUserReferralStatus`}),{cacheKey:`frak_getUserReferralStatus`,cacheTime:t?.cacheTime})}function E(e,{strict:t=!0}={}){return!e||typeof e!=`string`?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith(`0x`)}var ge=t((()=>{}));function _e(e){return E(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}var ve=t((()=>{ge()})),D,ye=t((()=>{D=`2.47.16`}));function be(e,t){return t?.(e)?e:e&&typeof e==`object`&&`cause`in e&&e.cause!==void 0?be(e.cause,t):t?null:e}var O,k,xe=t((()=>{ye(),O={getDocsUrl:({docsBaseUrl:e,docsPath:t=``,docsSlug:n})=>t?`${e??`https://viem.sh`}${t}${n?`#${n}`:``}`:void 0,version:`viem@${D}`},k=class e extends Error{constructor(t,n={}){let r=n.cause instanceof e?n.cause.details:n.cause?.message?n.cause.message:n.details,i=n.cause instanceof e&&n.cause.docsPath||n.docsPath,a=O.getDocsUrl?.({...n,docsPath:i}),o=[t||`An error occurred.`,``,...n.metaMessages?[...n.metaMessages,``]:[],...a?[`Docs: ${a}`]:[],...r?[`Details: ${r}`]:[],...O.version?[`Version: ${O.version}`]:[]].join(`
|
|
2
|
+
`);super(o,n.cause?{cause:n.cause}:void 0),Object.defineProperty(this,`details`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`docsPath`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`metaMessages`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`shortMessage`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`version`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`name`,{enumerable:!0,configurable:!0,writable:!0,value:`BaseError`}),this.details=r,this.docsPath=i,this.metaMessages=n.metaMessages,this.name=n.name??this.name,this.shortMessage=t,this.version=D}walk(e){return be(this,e)}}})),Se,Ce=t((()=>{xe(),Se=class extends k{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`,{name:`SizeExceedsPaddingSizeError`})}}}));function A(e,{dir:t,size:n=32}={}){return typeof e==`string`?we(e,{dir:t,size:n}):Te(e,{dir:t,size:n})}function we(e,{dir:t,size:n=32}={}){if(n===null)return e;let r=e.replace(`0x`,``);if(r.length>n*2)throw new Se({size:Math.ceil(r.length/2),targetSize:n,type:`hex`});return`0x${r[t===`right`?`padEnd`:`padStart`](n*2,`0`)}`}function Te(e,{dir:t,size:n=32}={}){if(n===null)return e;if(e.length>n)throw new Se({size:e.length,targetSize:n,type:`bytes`});let r=new Uint8Array(n);for(let i=0;i<n;i++){let a=t===`right`;r[a?i:n-i-1]=e[a?i:e.length-i-1]}return r}var Ee=t((()=>{Ce()})),De,Oe,ke=t((()=>{xe(),De=class extends k{constructor({max:e,min:t,signed:n,size:r,value:i}){super(`Number "${i}" is not in safe ${r?`${r*8}-bit ${n?`signed`:`unsigned`} `:``}integer range ${e?`(${t} to ${e})`:`(above ${t})`}`,{name:`IntegerOutOfRangeError`})}},Oe=class extends k{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:`SizeOverflowError`})}}}));function j(e,{size:t}){if(_e(e)>t)throw new Oe({givenSize:_e(e),maxSize:t})}var Ae=t((()=>{ke(),ve()}));function je(e,t={}){return typeof e==`number`||typeof e==`bigint`?Ne(e,t):typeof e==`string`?Pe(e,t):typeof e==`boolean`?Me(e,t):M(e,t)}function Me(e,t={}){let n=`0x${Number(e)}`;return typeof t.size==`number`?(j(n,{size:t.size}),A(n,{size:t.size})):n}function M(e,t={}){let n=``;for(let t=0;t<e.length;t++)n+=Fe[e[t]];let r=`0x${n}`;return typeof t.size==`number`?(j(r,{size:t.size}),A(r,{dir:`right`,size:t.size})):r}function Ne(e,t={}){let{signed:n,size:r}=t,i=BigInt(e),a;r?a=n?(1n<<BigInt(r)*8n-1n)-1n:2n**(BigInt(r)*8n)-1n:typeof e==`number`&&(a=BigInt(2**53-1));let o=typeof a==`bigint`&&n?-a-1n:0;if(a&&i>a||i<o){let t=typeof e==`bigint`?`n`:``;throw new De({max:a?`${a}${t}`:void 0,min:`${o}${t}`,signed:n,size:r,value:`${e}${t}`})}let s=`0x${(n&&i<0?(1n<<BigInt(r*8))+BigInt(i):i).toString(16)}`;return r?A(s,{size:r}):s}function Pe(e,t={}){return M(Ie.encode(e),t)}var Fe,Ie;function Le(e,t={}){return typeof e==`number`||typeof e==`bigint`?Be(e,t):typeof e==`boolean`?Re(e,t):E(e)?N(e,t):Ve(e,t)}function Re(e,t={}){let n=new Uint8Array(1);return n[0]=Number(e),typeof t.size==`number`?(j(n,{size:t.size}),A(n,{size:t.size})):n}function ze(e){if(e>=P.zero&&e<=P.nine)return e-P.zero;if(e>=P.A&&e<=P.F)return e-(P.A-10);if(e>=P.a&&e<=P.f)return e-(P.a-10)}function N(e,t={}){let n=e;t.size&&(j(n,{size:t.size}),n=A(n,{dir:`right`,size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);let i=r.length/2,a=new Uint8Array(i);for(let e=0,t=0;e<i;e++){let n=ze(r.charCodeAt(t++)),i=ze(r.charCodeAt(t++));if(n===void 0||i===void 0)throw new k(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);a[e]=n*16+i}return a}function Be(e,t){return N(Ne(e,t))}function Ve(e,t={}){let n=He.encode(e);return typeof t.size==`number`?(j(n,{size:t.size}),A(n,{dir:`right`,size:t.size})):n}var He,P,Ue,We;function Ge(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function Ke(e,...t){if(!Ge(e))throw Error(`Uint8Array expected`);if(t.length>0&&!t.includes(e.length))throw Error(`Uint8Array expected of length `+t+`, got length=`+e.length)}function qe(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function Je(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}var Ye,Xe;function Ze(e,t){let n=t||`hex`,r=Xe(E(e,{strict:!1})?Le(e):e);return n===`bytes`?r:je(r)}var Qe;function $e(e,t){if(F.has(`${e}.${t}`))return F.get(`${e}.${t}`);let n=t?`${t}${e.toLowerCase()}`:e.substring(2).toLowerCase(),r=Ze(Ve(n),`bytes`),i=(t?n.substring(`${t}0x`.length):n).split(``);for(let e=0;e<40;e+=2)r[e>>1]>>4>=8&&i[e]&&(i[e]=i[e].toUpperCase()),(r[e>>1]&15)>=8&&i[e+1]&&(i[e+1]=i[e+1].toUpperCase());let a=`0x${i.join(``)}`;return F.set(`${e}.${t}`,a),a}var F;function I(e,t){let{strict:n=!0}=t??{},r=`${e}.${n}`;if(L.has(r))return L.get(r);let i=et.test(e)?e.toLowerCase()===e?!0:n?$e(e)===e:!0:!1;return L.set(r,i),i}var et,L;function tt(e,t){if(!I(e,{strict:!1}))throw new Qe({address:e});if(!I(t,{strict:!1}))throw new Qe({address:t});return e.toLowerCase()===t.toLowerCase()}let R=256,z;function nt(e=11){if(!z||R+e>256*2){z=``,R=0;for(let e=0;e<256;e++)z+=(256+Math.random()*256|0).toString(16).substring(1)}return z.substring(R,R+++e)}function rt({domain:e}={}){return Ze(je((e??window.location.host).replace(`www.`,``)))}let it={parseError:-32700,invalidRequest:-32600,methodNotFound:-32601,invalidParams:-32602,internalError:-32603,serverError:-32e3,clientNotConnected:-32001,configError:-32002,corruptedResponse:-32003,clientAborted:-32004,walletNotConnected:-32005,serverErrorForInteractionDelegation:-32006,userRejected:-32007};var B=class extends Error{constructor(e,t,n){super(t),this.code=e,this.data=n}toJSON(){return{code:this.code,message:this.message,data:this.data}}},V=class{_promise;_resolve;_reject;constructor(){this._promise=new Promise((e,t)=>{this._resolve=e,this._reject=t})}get promise(){return this._promise}resolve=e=>{this._resolve?.(e)};reject=e=>{this._reject?.(e)}};function at(e){let{emittingTransport:t,listeningTransport:n,targetOrigin:r,middleware:i=[],lifecycleHandlers:a}=e,o=new Map;function s(e){return typeof e!=`object`||!e?!1:`clientLifecycle`in e||`iframeLifecycle`in e}function c(e){return typeof e!=`object`||!e?!1:`id`in e&&`topic`in e&&`data`in e}async function l(e){try{`clientLifecycle`in e&&a?.clientLifecycle?await a.clientLifecycle(e,{origin:r,source:null}):`iframeLifecycle`in e&&a?.iframeLifecycle&&await a.iframeLifecycle(e,{origin:r,source:null})}catch{}}async function u(e){let t={origin:r,source:null};for(let n of i)n.onRequest&&await n.onRequest(e,t);return e}async function d(e,t){let n={origin:r,source:null},a=t;for(let t of i)t.onResponse&&(a=await t.onResponse(e,a,n));return a}async function f(e){try{if(new URL(e.origin).origin.toLowerCase()!==new URL(r).origin.toLowerCase())return}catch{return}if(s(e.data)){await l(e.data);return}if(!c(e.data))return;let t;try{let n=e.data.data,r=n instanceof Uint8Array||ArrayBuffer.isView(n)?{result:n}:n;t=await d(e.data,r)}catch{return}let n=o.get(e.data.id);n&&n(t)}async function p(e){let n=e;try{n=await u(e)}catch(e){throw e}t.postMessage(n,r)}function m(e){t.postMessage(e,r)}function h(){return`${Date.now()}-${Math.random().toString(36).substring(2,9)}`}n.addEventListener(`message`,f);function g(e){let t=h(),n=new V;return o.set(t,e=>{e.error?n.reject(new B(e.error.code,e.error.message,e.error.data)):n.resolve(e.result),o.delete(t)}),p({id:t,topic:e.method,data:{method:e.method,params:e.params}}).catch(e=>{o.delete(t),n.reject(e)}),n.promise}function _(e,t){let n=h();return o.set(n,e=>{e.error?o.delete(n):t(e.result)}),p({id:n,topic:e.method,data:{method:e.method,params:e.params}}).catch(e=>{o.delete(n)}),()=>{o.delete(n)}}function ee(){n.removeEventListener(`message`,f),o.clear()}return{request:g,listen:_,sendLifecycle:m,cleanup:ee}}function ot(e){return new TextEncoder().encode(JSON.stringify(e))}function st(e){try{return JSON.parse(new TextDecoder().decode(e))}catch{return null}}function H(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function U(e){let t=e.length%4;return Uint8Array.from(atob(e.replace(/-/g,`+`).replace(/_/g,`/`).padEnd(e.length+(t===0?0:4-t),`=`)),e=>e.charCodeAt(0))}function ct(e){return H(ot(e))}function lt(e,t,n,r,i,a){let o=ct(ut({redirectUrl:t.redirectUrl,directExit:t.directExit,lang:t.lang,merchantId:n,metadata:{name:r,css:a,logoUrl:t.metadata?.logoUrl,homepageLink:t.metadata?.homepageLink},clientId:i})),s=new URL(e);return s.pathname=`/sso`,s.searchParams.set(`p`,o),s.toString()}function ut(e){return{r:e.redirectUrl,cId:e.clientId,d:e.directExit,l:e.lang,m:e.merchantId,md:{n:e.metadata?.name,css:e.metadata?.css,l:e.metadata?.logoUrl,h:e.metadata?.homepageLink}}}let dt=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,ft=`frak-sso`;async function pt(e,t){let{metadata:n,customizations:r,walletUrl:i}=e.config;if(t.openInSameWindow??!!t.redirectUrl)return await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]});let a=t.ssoPopupUrl??lt(i??`https://wallet.frak.id`,t,rt(),n.name,d(),r?.css),o=window.open(a,ft,dt);if(!o)throw Error(`Popup was blocked. Please allow popups for this site.`);return o.focus(),await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]})??{}}async function mt(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}function W(e){return`r`in e&&!(`v`in e)}function G(e){return`v`in e&&e.v===2}function K(e,t,n){if(e)try{e.openPanel?.track(t,n)}catch{}}function ht(e){return st(U(e))}let q=`nexus-wallet-backup`,gt=`frakwallet://`;function _t(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}function vt(e){return`intent://${e.slice(13)}#Intent;scheme=frakwallet;end`}function yt(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=_t()&&J(e)?vt(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function J(e){return e.startsWith(gt)}let bt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function xt(e){return typeof e==`string`&&bt.test(e)}function St(e){let t=e.replace(/-/g,``),n=new Uint8Array(16);for(let e=0;e<16;e++)n[e]=Number.parseInt(t.substring(e*2,e*2+2),16);return n}function Ct(e){let t=``;for(let n=0;n<16;n++)t+=e[n].toString(16).padStart(2,`0`);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20,32)}`}function wt(e){if(!xt(e.m)||!Number.isInteger(e.t)||e.t<0||e.t>4294967295)return null;let t=typeof e.c==`string`&&e.c.length>0,n=typeof e.w==`string`&&I(e.w);if(!t&&!n||t&&!xt(e.c))return null;let r=new Uint8Array(21+(t?16:0)+(n?20:0)),i=new DataView(r.buffer,r.byteOffset,r.byteLength),a=0;return r[a++]=2|(t?16:0)|(n?32:0),r.set(St(e.m),a),a+=16,i.setUint32(a,e.t,!1),a+=4,t&&(r.set(St(e.c),a),a+=16),n&&(r.set(N(e.w),a),a+=20),r}function Tt(e){if(e.length<21)return null;let t=e[0];if((t&15)!=2||t&192)return null;let n=(t&16)!=0,r=(t&32)!=0;if(!n&&!r)return null;let i=21+(n?16:0)+(r?20:0);if(e.length!==i)return null;let a=1,o=Ct(e.subarray(a,a+16));a+=16;let s=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(a,!1);a+=4;let c={v:2,m:o,t:s};if(n&&(c.c=Ct(e.subarray(a,a+16)),a+=16),r){let t=M(e.subarray(a,a+20),{size:20});if(!I(t))return null;c.w=t,a+=20}return c}let Y=`fCtx`;function Et(e){if(e)try{if(G(e)){let t=wt(e);return t?H(t):void 0}return H(N(e.r))}catch{}}function Dt(e){if(!(!e||e.length===0))try{let t=U(e);if(t.length!==20)return Tt(t)||void 0;let n=M(t,{size:20});if(I(n))return{r:n}}catch{}}function Ot({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(Y);return t?Dt(t):null}let kt=`frak`;function At(e,t){let n=G(e);return{utm_source:t.utmSource??kt,utm_medium:t.utmMedium??`referral`,utm_campaign:t.utmCampaign??(n?e.m:void 0),utm_content:t.utmContent,utm_term:t.utmTerm,via:t.via??kt,ref:t.ref??(n?e.c:void 0)}}function jt(e,t,n){let r=At(t,n??{});for(let[t,n]of Object.entries(r))n===void 0||n===``||e.searchParams.has(t)||e.searchParams.set(t,n)}function Mt({url:e,context:t,attribution:n}){if(!e)return null;let r=Et(t);if(!r)return null;let i=new URL(e);return i.searchParams.set(Y,r),jt(i,t,n),i.toString()}function Nt(e){let t=new URL(e);return t.searchParams.delete(Y),t.toString()}function Pt({url:e,context:t}){if(!window.location?.href||typeof window>`u`)return;let n=e??window.location.href,r;r=t===null?Nt(n):Mt({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}let Ft={compress:Et,decompress:Dt,parse:Ot,update:Mt,remove:Nt,replaceUrl:Pt},X={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function It(e){return e&&e in X?e:`eur`}function Lt(e){return e?X[e]??X.eur:X.eur}function Rt(e,t){let n=Lt(t),r=It(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function zt(e){return e?`${e}Amount`:`eurAmount`}let Z={id:`frak-wallet`,name:`frak-wallet`,title:`Frak Wallet`,allow:`publickey-credentials-get *; clipboard-write; web-share *`,style:{width:`0`,height:`0`,border:`0`,position:`absolute`,zIndex:2000001,top:`-1000px`,left:`-1000px`,colorScheme:`auto`}};function Bt({walletBaseUrl:e,config:t}){let n=document.querySelector(`#frak-wallet`);n&&n.remove();let r=document.createElement(`iframe`);r.id=Z.id,r.name=Z.name,r.allow=Z.allow,r.style.zIndex=Z.style.zIndex.toString(),Vt({iframe:r,isVisible:!1});let i=t?.walletUrl??e??`https://wallet.frak.id`,a=d();return r.src=`${i}/listener?clientId=${encodeURIComponent(a)}`,new Promise(e=>{r.addEventListener(`load`,()=>e(r)),document.body.appendChild(r)})}function Vt({iframe:e,isVisible:t}){if(!t){e.style.width=`0`,e.style.height=`0`,e.style.border=`0`,e.style.position=`fixed`,e.style.top=`-1000px`,e.style.left=`-1000px`;return}e.style.position=`fixed`,e.style.top=`0`,e.style.left=`0`,e.style.width=`100%`,e.style.height=`100%`,e.style.pointerEvents=`auto`}function Ht(e=`/listener`){if(!window.opener)return null;let t=t=>{try{return t.location.origin===window.location.origin&&t.location.pathname===e}catch{return!1}};if(t(window.opener))return window.opener;try{let e=window.opener.frames;for(let n=0;n<e.length;n++)if(t(e[n]))return e[n];return null}catch{return null}}function Ut(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent;return!!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1)}let Wt=Ut();function Gt(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent.toLowerCase();return e.includes(`instagram`)||e.includes(`fban`)||e.includes(`fbav`)||e.includes(`facebook`)}let Kt=Gt();function qt(e){Wt&&e.startsWith(`https://`)?window.location.href=`x-safari-https://${e.slice(8)}`:Wt&&e.startsWith(`http://`)?window.location.href=`x-safari-http://${e.slice(7)}`:window.location.href=`https://backend.frak.id/common/social?u=${encodeURIComponent(e)}`}function Jt({perCall:e,defaults:t,productUtmContent:n}){if(e===null)return;let r=e!==void 0,i=t!==void 0&&Object.keys(t).length>0;if(!r&&!i&&!(n!==void 0&&n!==``))return;let a={...t,...e??{}},o=n??e?.utmContent;return o!==void 0&&o!==``?a.utmContent=o:delete a.utmContent,a}async function Yt(e,t){try{await e.request({method:`frak_sendInteraction`,params:[t,{clientId:d()}]})}catch{}}function Xt(e,t,n){let r=typeof window<`u`?window.location.href:void 0;return G(t)?(K(e,`user_referred_started`,{referrerClientId:t.c,referrerWallet:t.w,walletStatus:n?.key}),Yt(e,{type:`arrival`,referrerClientId:t.c,referrerMerchantId:t.m,referrerWallet:t.w,referralTimestamp:t.t,landingUrl:r}),!0):W(t)?(K(e,`user_referred_started`,{referrer:t.r,walletStatus:n?.key}),Yt(e,{type:`arrival`,referrerWallet:t.r,landingUrl:r}),!0):!1}function Zt(e,t){let n=d();return!n&&!t?null:{v:2,m:e,t:Math.floor(Date.now()/1e3),...n?{c:n}:{},...t?{w:t}:{}}}function Qt(e,t){return G(e)?e.w&&t?.wallet?tt(e.w,t.wallet):e.c?d()===e.c:!1:W(e)&&t?.wallet?tt(e.r,t.wallet):!1}function $t(e,{walletStatus:t,frakContext:n,options:r}){if(!n)return`no-referrer`;if(Qt(n,t))return`self-referral`;if(!Xt(e,n,t))return`no-referrer`;let i=G(n)?n.m:r?.merchantId,a=r?.alwaysAppendUrl&&i?Zt(i,t?.wallet):null;return Ft.replaceUrl({url:window.location?.href,context:a}),K(e,`user_referred_completed`,{status:`success`}),`success`}async function en(e,{options:t}={}){let n=Ft.parse({url:window.location.href}),r=await an(e);try{return $t(e,{walletStatus:r,frakContext:n,options:t})}catch{}}let tn=`frak:referral-success`;async function nn(e){try{await en(e)===`success`&&window.dispatchEvent(new Event(tn))}catch{}}async function rn(e){if(typeof window>`u`)return;let t=window.sessionStorage.getItem(`frak-wallet-interaction-token`),n=d();if(!t&&!n)return;let r=e.merchantId??await T.resolveMerchantId();if(!r)return;let i={Accept:`application/json`,"Content-Type":`application/json`};t&&(i[`x-wallet-sdk-auth`]=t),n&&(i[`x-frak-client-id`]=n);let a=c();await fetch(`${a}/user/track/purchase`,{method:`POST`,headers:i,body:JSON.stringify({customerId:e.customerId,orderId:e.orderId,token:e.token,merchantId:r})})}function an(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(on(e,t),t));let n=new V,r=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},i=>{on(e,i),t(i),r||=(n.resolve(i),!0)}),n.promise}function on(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?(window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken),fe(t.interactionToken)):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function sn(e,{metadata:t,login:n}){return Q(e,{steps:{login:n??{}},metadata:t})}function Q(e,t){function n(n){return Q(e,{...t,steps:{...t.steps,sendTransaction:n}})}function i(n){return Q(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function a(n,r){return Q(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function o(n,i){return n&&(t.metadata=n(t.metadata??{})),await r(e,t,i)}return{params:t,sendTx:n,reward:i,sharing:a,display:o}}async function cn(e,{tx:t,metadata:n}){return(await r(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}function ln(){return nt(96)}async function un(e,{siwe:t,metadata:n}){let i=e.config?.domain??window.location.host,a=t?.statement??`I confirm that I want to use my Frak wallet on: ${e.config.metadata.name}`;return(await r(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:a,nonce:t?.nonce??ln(),uri:t?.uri??`https://${i}`,version:t?.version??`1`,domain:i}}}})).siweAuthenticate}function dn(){return()=>{}}var fn=class{constructor(e){this.baseUrl=e.baseUrl,this.headers={"Content-Type":`application/json`,...e.defaultHeaders},this.maxRetries=e.maxRetries??3,this.initialRetryDelay=e.initialRetryDelay??500}async resolveHeaders(){let e={};for(let[t,n]of Object.entries(this.headers)){let r=await n;r!==null&&(e[t]=r)}return e}addHeader(e,t){this.headers[e]=t}async post(e,t,n,r){try{let r=await fetch(e,{method:`POST`,headers:await this.resolveHeaders(),body:t?JSON.stringify(t??{}):void 0,keepalive:!0,...n});if(r.status===401)return null;if(r.status!==200&&r.status!==202)throw Error(`HTTP error! status: ${r.status}`);let i=await r.text();return i?JSON.parse(i):null}catch{if(r<this.maxRetries){let i=this.initialRetryDelay*2**r;return await new Promise(e=>setTimeout(e,i)),this.post(e,t,n,r+1)}return null}}async fetch(e,t,n={}){let r=`${this.baseUrl}${e}`;return this.post(r,t,n,0)}},pn=class{constructor(e){this.groups=[],this.queue=[],this.options=e;let t={"openpanel-client-id":e.clientId};e.clientSecret&&(t[`openpanel-client-secret`]=e.clientSecret),t[`openpanel-sdk-name`]=e.sdk||`node`,t[`openpanel-sdk-version`]=e.sdkVersion||`1.3.0`,this.api=new fn({baseUrl:e.apiUrl||`https://api.openpanel.dev`,defaultHeaders:t})}init(){}ready(){this.options.disabled=!1,this.options.waitForProfile=!1,this.flush()}shouldQueue(e){return!!(this.options.disabled||this.options.waitForProfile&&!this.profileId||e.type===`replay`&&!this.sessionId)}addQueue(e){e.type===`track`&&(e.payload.properties={...e.payload.properties??{},__timestamp:new Date().toISOString()}),this.queue.push(e)}async send(e){if(this.options.filter&&!this.options.filter(e))return Promise.resolve();if(this.shouldQueue(e))return this.addQueue(e),Promise.resolve();let t=await this.api.fetch(`/track`,e,{keepalive:e.type!==`replay`});this.deviceId=t?.deviceId;let n=!!this.sessionId;return this.sessionId=t?.sessionId,!n&&this.sessionId&&this.flush(),t}setGlobalProperties(e){this.global={...this.global,...e}}track(e,t){this.log(`track event`,e,t);let{groups:n,profileId:r,...i}=t??{},a=[...new Set([...this.groups,...n??[]])];return this.send({type:`track`,payload:{name:e,profileId:r??this.profileId,groups:a.length>0?a:void 0,properties:{...this.global??{},...i}}})}identify(e){if(this.log(`identify user`,e),e.profileId&&(this.profileId=e.profileId,this.flush()),Object.keys(e).length>1)return this.send({type:`identify`,payload:{...e,properties:{...this.global,...e.properties}}})}upsertGroup(e){return this.log(`upsert group`,e),this.send({type:`group`,payload:e})}setGroup(e){return this.log(`set group`,e),this.groups.includes(e)||(this.groups=[...this.groups,e]),this.send({type:`assign_group`,payload:{groupIds:[e],profileId:this.profileId}})}setGroups(e){return this.log(`set groups`,e),this.groups=[...new Set([...this.groups,...e])],this.send({type:`assign_group`,payload:{groupIds:e,profileId:this.profileId}})}alias(e){}increment(e){return this.send({type:`increment`,payload:e})}decrement(e){return this.send({type:`decrement`,payload:e})}revenue(e,t){let n=t?.deviceId;return delete t?.deviceId,this.track(`revenue`,{...t??{},...n?{__deviceId:n}:{},__revenue:e})}getDeviceId(){return this.deviceId??``}getSessionId(){return this.sessionId??``}fetchDeviceId(){return Promise.resolve(this.deviceId??``)}clear(){this.profileId=void 0,this.groups=[],this.deviceId=void 0,this.sessionId=void 0}buildFlushPayload(e){if(e.type===`replay`)return e.payload;if(e.type===`track`){let t=`groups`in e.payload?e.payload.groups??[]:[],n=[...new Set([...this.groups,...t])];return{...e.payload,profileId:e.payload.profileId??this.profileId,groups:n.length>0?n:void 0}}return e.type===`identify`||e.type===`increment`||e.type===`decrement`||e.type===`assign_group`?{...e.payload,profileId:e.payload.profileId??this.profileId}:e.payload}flush(){let e=[];for(let t of this.queue){if(this.shouldQueue(t)){e.push(t);continue}let n=this.buildFlushPayload(t);this.send({...t,payload:n})}this.queue=e}log(...e){this.options.debug}},mn=Object.defineProperty,hn=(e,t)=>()=>(e&&(t=e(e=0)),t),gn=(e,t)=>{for(var n in t)mn(e,n,{get:t[n],enumerable:!0})};function _n(e,t){if(typeof document>`u`||typeof window>`u`)return;$&&$();let n=e.maxEventsPerChunk??200,r=e.flushIntervalMs??1e4,i=e.maxPayloadBytes??1048576,a=[],o=0,s=null;function c(e){if(a.length===0)return;let n=JSON.stringify(a);if(new TextEncoder().encode(n).length>i){if(a.length>1){let t=Math.floor(a.length/2),n=a.slice(0,t),r=a.slice(t),i=e&&n.some(e=>e.type===2);a=n,c(i),a=r,c(!1);return}a=[];return}let r=a[0].timestamp,s=a[a.length-1].timestamp;try{t({chunk_index:o,events_count:a.length,is_full_snapshot:e,started_at:new Date(r).toISOString(),ended_at:new Date(s).toISOString(),payload:n}),o+=1,a=[]}catch(e){throw e}}function l(e){let t=e||a.some(e=>e.type===2);a.length>=n?c(t):e&&a.length>0&&c(!0)}let u=e.maskAllText!==!1,d=e.unmaskTextSelector,f=dn({emit(e,t){a.push(e),l(!!t)},checkoutEveryNms:r,maskAllInputs:e.maskAllInputs??!0,maskTextSelector:u?`*`:`[data-openpanel-replay-mask]`,maskTextFn:u&&d?(e,t)=>t?.closest(d)?e:e.replace(/\S/g,`*`):void 0,blockSelector:e.blockSelector??`[data-openpanel-replay-block]`,blockClass:e.blockClass,ignoreSelector:e.ignoreSelector});s=setInterval(()=>{a.length>0&&c(a.some(e=>e.type===2))},r);function p(){document.visibilityState===`hidden`&&a.length>0&&c(a.some(e=>e.type===2))}function m(){a.length>0&&c(a.some(e=>e.type===2))}document.addEventListener(`visibilitychange`,p),window.addEventListener(`pagehide`,m),$=()=>{a.length>0&&c(a.some(e=>e.type===2)),s&&=(clearInterval(s),null),document.removeEventListener(`visibilitychange`,p),window.removeEventListener(`pagehide`,m),f?.(),$=null}}function vn(){$&&$()}var $,yn=hn(()=>{"use strict";$=null}),bn={};gn(bn,{startReplayRecorder:()=>_n,stopReplayRecorder:()=>vn});var xn=hn(()=>{"use strict";yn()}),Sn=typeof document<`u`?document.currentScript:null;function Cn(e){return e.replace(/([-_][a-z])/gi,e=>e.toUpperCase().replace(`-`,``).replace(`_`,``))}var wn=class extends pn{constructor(e){if(super({sdk:`web`,sdkVersion:`1.3.0`,...e}),this.options=e,this.lastPath=``,this.pendingRevenues=[],!this.isServer()){try{let e=sessionStorage.getItem(`openpanel-pending-revenues`);if(e){let t=JSON.parse(e);Array.isArray(t)&&(this.pendingRevenues=t)}}catch{this.pendingRevenues=[]}if(this.setGlobalProperties({__referrer:document.referrer}),this.options.trackScreenViews&&(this.trackScreenViews(),setTimeout(()=>this.screenView(),0)),this.options.trackOutgoingLinks&&this.trackOutgoingLinks(),this.options.trackAttributes&&this.trackAttributes(),this.options.sessionReplay?.enabled){let e=this.options.sessionReplay.sampleRate??1;Math.random()<e&&this.loadReplayModule().then(e=>{e&&e.startReplayRecorder(this.options.sessionReplay,e=>{this.send({type:`replay`,payload:{...e}})})})}}}async loadReplayModule(){try{if(typeof __OPENPANEL_REPLAY_URL__<`u`){let e=Sn,t=this.options.sessionReplay?.scriptUrl||e?.src?.replace(`.js`,`-replay.js`)||`https://openpanel.dev/op1-replay.js`;return window.__openpanel_replay?window.__openpanel_replay:new Promise(e=>{let n=document.createElement(`script`);n.src=t,n.onload=()=>{e(window.__openpanel_replay??null)},n.onerror=()=>{e(null)},document.head.appendChild(n)})}return await Promise.resolve().then(()=>(xn(),bn))}catch{return null}}debounce(e,t){clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(e,t)}isServer(){return typeof document>`u`}trackOutgoingLinks(){this.isServer()||document.addEventListener(`click`,e=>{let t=e.target,n=t.closest(`a`);if(n&&t){let e=n.getAttribute(`href`);if(e?.startsWith(`http`))try{let r=new URL(e),i=window.location.hostname;r.hostname!==i&&super.track(`link_out`,{href:e,text:n.innerText||n.getAttribute(`title`)||t.getAttribute(`alt`)||t.getAttribute(`title`)})}catch{}}})}trackScreenViews(){if(this.isServer())return;let e=history.pushState;history.pushState=function(...t){let n=e.apply(this,t);return window.dispatchEvent(new Event(`pushstate`)),window.dispatchEvent(new Event(`locationchange`)),n};let t=history.replaceState;history.replaceState=function(...e){let n=t.apply(this,e);return window.dispatchEvent(new Event(`replacestate`)),window.dispatchEvent(new Event(`locationchange`)),n},window.addEventListener(`popstate`,()=>{window.dispatchEvent(new Event(`locationchange`))});let n=()=>this.debounce(()=>this.screenView(),50);this.options.trackHashChanges?window.addEventListener(`hashchange`,n):window.addEventListener(`locationchange`,n)}trackAttributes(){this.isServer()||document.addEventListener(`click`,e=>{let t=e.target,n=t.closest(`button`),r=t.closest(`a`),i=n?.getAttribute(`data-track`)?n:r?.getAttribute(`data-track`)?r:null;if(i){let e={};for(let t of i.attributes)t.name.startsWith(`data-`)&&t.name!==`data-track`&&(e[Cn(t.name.replace(/^data-/,``))]=t.value);let t=i.getAttribute(`data-track`);t&&super.track(t,e)}})}track(e,t){return super.track(e,{...t,__path:this.lastPath})}screenView(e,t){if(this.isServer())return;let n,r;typeof e==`string`?(n=e,r=t):(n=window.location.href,r=e),this.lastPath!==n&&(this.lastPath=n,super.track(`screen_view`,{...r??{},__path:n,__title:document.title}))}async flushRevenue(){let e=this.pendingRevenues.map(e=>super.revenue(e.amount,e.properties));await Promise.all(e),this.clearRevenue()}clearRevenue(){if(this.pendingRevenues=[],!this.isServer())try{sessionStorage.removeItem(`openpanel-pending-revenues`)}catch{}}pendingRevenue(e,t){if(this.pendingRevenues.push({amount:e,properties:t}),!this.isServer())try{sessionStorage.setItem(`openpanel-pending-revenues`,JSON.stringify(this.pendingRevenues))}catch{}}};function Tn(e,t){if(typeof window>`u`)return;let n=new URL(window.location.href),r=n.searchParams.get(`sso`);r&&(t.then(()=>{e.sendLifecycle({clientLifecycle:`sso-redirect-complete`,data:{compressed:r}})}).catch(e=>{}),n.searchParams.delete(`sso`),window.history.replaceState({},``,n.toString()))}var En=class e{config;iframe;isSetupDone=!1;lastResponse=null;lastRequest=null;constructor(e,t){this.config=e,this.iframe=t,this.lastRequest=null,this.lastResponse=null}setLastResponse(e,t){this.lastResponse={message:e,response:t,timestamp:Date.now()}}setLastRequest(e){this.lastRequest={event:e,timestamp:Date.now()}}updateSetupStatus(e){this.isSetupDone=e}base64Encode(e){try{return btoa(JSON.stringify(e))}catch{return btoa(`Failed to encode data`)}}getIframeStatus(){return this.iframe?{loading:this.iframe.hasAttribute(`loading`),url:this.iframe.src,readyState:this.iframe.contentDocument?.readyState?+(this.iframe.contentDocument.readyState===`complete`):-1,contentWindow:!!this.iframe.contentWindow,isConnected:this.iframe.isConnected}:null}getNavigatorInfo(){return navigator?{userAgent:navigator.userAgent,language:navigator.language,onLine:navigator.onLine,screenWidth:window.screen.width,screenHeight:window.screen.height,pixelRatio:window.devicePixelRatio}:null}gatherDebugInfo(e){let t=this.getIframeStatus(),n=this.getNavigatorInfo(),r=`Unknown`;return e instanceof B?r=`FrakRpcError: ${e.code} '${e.message}'`:e instanceof Error?r=e.message:typeof e==`string`&&(r=e),{timestamp:new Date().toISOString(),encodedUrl:btoa(window.location.href),encodedConfig:this.config?this.base64Encode(this.config):`no-config`,navigatorInfo:n?this.base64Encode(n):`no-navigator`,iframeStatus:t?this.base64Encode(t):`not-iframe`,lastRequest:this.lastRequest?this.base64Encode(this.lastRequest):`No Frak request logged`,lastResponse:this.lastResponse?this.base64Encode(this.lastResponse):`No Frak response logged`,clientStatus:this.isSetupDone?`setup`:`not-setup`,error:r}}static empty(){return new e}formatDebugInfo(e){let t=this.gatherDebugInfo(e);return`
|
|
3
3
|
Debug Information:
|
|
4
4
|
-----------------
|
|
5
5
|
Timestamp: ${t.timestamp}
|
|
@@ -11,4 +11,4 @@ var FrakSDK=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Modu
|
|
|
11
11
|
Last Response: ${t.lastResponse}
|
|
12
12
|
Client Status: ${t.clientStatus}
|
|
13
13
|
Error: ${t.error}
|
|
14
|
-
`.trim()}};let Dn=(()=>{if(typeof navigator>`u`)return!1;let e=navigator.userAgent;if(!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1))return!1;let t=e.toLowerCase();return t.includes(`instagram`)||t.includes(`fban`)||t.includes(`fbav`)||t.includes(`facebook`)})();function On(e){e?localStorage.setItem(q,e):localStorage.removeItem(q)}function kn(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=Mn(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function An(e){let t=new URL(window.location.href);e&&t.searchParams.set(`fmt`,e);let n=t.protocol===`http:`?`x-safari-http`:`x-safari-https`;window.location.href=`${n}://${t.host}${t.pathname}${t.search}${t.hash}`}function jn(e){return e.includes(`/common/social`)}function Mn(e,t){if(!t)return e;try{let n=new URL(e);return n.searchParams.set(`fmt`,t),n.toString()}catch{return`${e}${e.includes(`?`)?`&`:`?`}fmt=${encodeURIComponent(t)}`}}function Nn(e,t,n,r,i){if(i){let e=kn(t,r);window.open(e,`_blank`);return}if(J(t)){let i=kn(t,r);yt(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(Dn&&jn(t))An(r);else{let e=kn(t,r);window.location.href=e}}function Pn({iframe:e,targetOrigin:t}){let n=new V;return{handleEvent:r=>{if(!(`iframeLifecycle`in r))return;let{iframeLifecycle:i,data:a}=r;switch(i){case`connected`:n.resolve(!0);break;case`do-backup`:On(a.backup);break;case`remove-backup`:localStorage.removeItem(q);break;case`show`:case`hide`:Vt({iframe:e,isVisible:i===`show`});break;case`redirect`:Nn(e,a.baseRedirectUrl,t,a.mergeToken,a.openInNewTab);break}},isConnected:n.promise}}function Fn({config:e,iframe:t}){let n=e?.walletUrl??`https://wallet.frak.id`,r=typeof navigator<`u`?navigator.language?.split(`-`)[0]:void 0,i=e.metadata.lang??(r===`en`||r===`fr`?r:void 0),a=e.domain??(typeof window<`u`?window.location.hostname:``);T.setCacheScope(a,i),T.reset();let o=T.isCacheFresh?void 0:T.resolve(e.domain,e.walletUrl,i),s=Pn({iframe:t,targetOrigin:n}),c=new V,l=Date.now(),u=new En(e,t);if(!t.contentWindow)throw new B(it.configError,`The iframe does not have a content window`);let f=at({emittingTransport:t.contentWindow,listeningTransport:window,targetOrigin:n,middleware:[{async onRequest(e,t){if(!await s.isConnected)throw new B(it.clientNotConnected,`The iframe provider isn't connected yet`);return await c.promise,t}},{onRequest(e,t){return u.setLastRequest(e),t},onResponse(e,t){return u.setLastResponse(e,t),t}}],lifecycleHandlers:{iframeLifecycle:(e,t)=>{s.handleEvent(e)}}}),p=In(f,s),m=async()=>{p(),f.cleanup(),t.remove(),te(),T.clearCache(),T.reset()},h;{
|
|
14
|
+
`.trim()}};let Dn=(()=>{if(typeof navigator>`u`)return!1;let e=navigator.userAgent;if(!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1))return!1;let t=e.toLowerCase();return t.includes(`instagram`)||t.includes(`fban`)||t.includes(`fbav`)||t.includes(`facebook`)})();function On(e){e?localStorage.setItem(q,e):localStorage.removeItem(q)}function kn(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=Mn(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function An(e){let t=new URL(window.location.href);e&&t.searchParams.set(`fmt`,e);let n=t.protocol===`http:`?`x-safari-http`:`x-safari-https`;window.location.href=`${n}://${t.host}${t.pathname}${t.search}${t.hash}`}function jn(e){return e.includes(`/common/social`)}function Mn(e,t){if(!t)return e;try{let n=new URL(e);return n.searchParams.set(`fmt`,t),n.toString()}catch{return`${e}${e.includes(`?`)?`&`:`?`}fmt=${encodeURIComponent(t)}`}}function Nn(e,t,n,r,i){if(i){let e=kn(t,r);window.open(e,`_blank`);return}if(J(t)){let i=kn(t,r);yt(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(Dn&&jn(t))An(r);else{let e=kn(t,r);window.location.href=e}}function Pn({iframe:e,targetOrigin:t}){let n=new V;return{handleEvent:r=>{if(!(`iframeLifecycle`in r))return;let{iframeLifecycle:i,data:a}=r;switch(i){case`connected`:n.resolve(!0);break;case`do-backup`:On(a.backup);break;case`remove-backup`:localStorage.removeItem(q);break;case`show`:case`hide`:Vt({iframe:e,isVisible:i===`show`});break;case`redirect`:Nn(e,a.baseRedirectUrl,t,a.mergeToken,a.openInNewTab);break}},isConnected:n.promise}}function Fn({config:e,iframe:t}){let n=e?.walletUrl??`https://wallet.frak.id`,r=typeof navigator<`u`?navigator.language?.split(`-`)[0]:void 0,i=e.metadata.lang??(r===`en`||r===`fr`?r:void 0),a=e.domain??(typeof window<`u`?window.location.hostname:``);T.setCacheScope(a,i),T.reset();let o=T.isCacheFresh?void 0:T.resolve(e.domain,e.walletUrl,i),s=Pn({iframe:t,targetOrigin:n}),c=new V,l=Date.now(),u=new En(e,t);if(!t.contentWindow)throw new B(it.configError,`The iframe does not have a content window`);let f=at({emittingTransport:t.contentWindow,listeningTransport:window,targetOrigin:n,middleware:[{async onRequest(e,t){if(!await s.isConnected)throw new B(it.clientNotConnected,`The iframe provider isn't connected yet`);return await c.promise,t}},{onRequest(e,t){return u.setLastRequest(e),t},onResponse(e,t){return u.setLastResponse(e,t),t}}],lifecycleHandlers:{iframeLifecycle:(e,t)=>{s.handleEvent(e)}}}),p=In(f,s),m=async()=>{p(),f.cleanup(),t.remove(),te(),T.clearCache(),T.reset()},h;{h=new wn({apiUrl:`https://op-api.gcp.frak.id`,clientId:`f305d11d-b93b-487c-80d4-92deb7903e98`,trackScreenViews:!0,trackOutgoingLinks:!0,trackAttributes:!1,filter:({type:e,payload:t})=>(e!==`track`||!t?.properties||`sdkVersion`in t.properties||(t.properties={...t.properties,sdkVersion:`1.0.1`,userAnonymousClientId:d()}),!0)}),h.setGlobalProperties({sdkVersion:`1.0.1`,userAnonymousClientId:d()}),h.init(),h.track(`sdk_initialized`,{sdkVersion:`1.0.1`});let e=!1,t=setTimeout(()=>{e||(e=!0,h?.track(`sdk_iframe_handshake_failed`,{reason:`timeout`}))},3e4);s.isConnected.then(()=>{e||(e=!0,clearTimeout(t),h?.track(`sdk_iframe_connected`,{handshake_duration_ms:Date.now()-l}))}).catch(()=>{e||(e=!0,clearTimeout(t),h?.track(`sdk_iframe_handshake_failed`,{reason:`unknown`}))})}let g=Ln({config:e,rpcClient:f,lifecycleManager:s,configPromise:o,contextSent:c,openPanel:h}).then(()=>u.updateSetupStatus(!0)).catch(e=>{throw c.reject(e),e});return{config:e,debugInfo:u,waitForConnection:s.isConnected,waitForSetup:g,request:f.request,listenerRequest:f.listen,destroy:m,openPanel:h}}function In(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,1e3),r=setTimeout(()=>{o()},3e4),await t.isConnected,o()}function o(){n&&clearInterval(n),r&&clearTimeout(r)}return a(),o}async function Ln({config:e,rpcClient:t,lifecycleManager:n,configPromise:r,contextSent:i,openPanel:a}){await n.isConnected,Tn(t,n.isConnected);let o=new URL(window.location.href),s=o.searchParams.get(`fmt`)??void 0;s&&(o.searchParams.delete(`fmt`),window.history.replaceState({},``,o.toString()));let c=t=>{let n=t?.merchantId??e.metadata.merchantId??``,r=t?.domain??``,i=t?.allowedDomains??[],a=t?.sdkConfig,o=a?.attribution||e.attribution?{...e.attribution,...a?.attribution}:void 0;T.setConfig(a?{isResolved:!0,merchantId:n,domain:r,allowedDomains:i,hasRawSdkConfig:!0,name:a.name??e.metadata.name,logoUrl:a.logoUrl??e.metadata.logoUrl,homepageLink:a.homepageLink??e.metadata.homepageLink,lang:a.lang??e.metadata.lang,currency:a.currency??e.metadata.currency,hidden:a.hidden,css:a.css,translations:a.translations,placements:a.placements,components:a.components,attribution:o}:{isResolved:!0,merchantId:n,domain:r,allowedDomains:i,name:e.metadata.name,logoUrl:e.metadata.logoUrl,homepageLink:e.metadata.homepageLink,lang:e.metadata.lang,currency:e.metadata.currency,attribution:o})},l=!1,u=e=>{let n=l?void 0:s;l=!0;let r=e.hasRawSdkConfig?{name:e.name,logoUrl:e.logoUrl,homepageLink:e.homepageLink,lang:e.lang,currency:e.currency,hidden:e.hidden,css:e.css,translations:e.translations,placements:e.placements,attribution:e.attribution}:e.attribution?{attribution:e.attribution}:void 0,i=d();if(a){let t=a.global??{};a.setGlobalProperties({...t,merchantId:e.merchantId,domain:e.domain??``})}t.sendLifecycle({clientLifecycle:`resolved-config`,data:{merchantId:e.merchantId,domain:e.domain??``,allowedDomains:e.allowedDomains??[],sourceUrl:window.location.href,...i&&{sdkAnonymousId:i},...n&&{pendingMergeToken:n},...r&&{sdkConfig:r}}})};T.isResolved&&(u(T.getConfig()),i.resolve()),r&&(c(await r),u(T.getConfig()),i.resolve());async function f(){let n=e.customizations?.css;n&&t.sendLifecycle({clientLifecycle:`modal-css`,data:{cssLink:n}})}async function p(){let n=e.customizations?.i18n;n&&t.sendLifecycle({clientLifecycle:`modal-i18n`,data:{i18n:n}})}async function m(){if(typeof window>`u`)return;let e=window.localStorage.getItem(q);e&&t.sendLifecycle({clientLifecycle:`restore-backup`,data:{backup:e}})}(await Promise.allSettled([f(),p(),m()])).some(e=>e.status===`rejected`)&&a?.track(`sdk_iframe_handshake_failed`,{reason:`asset_push`})}async function Rn({config:e}){let t=zn(e),n=await Bt({config:t});if(!n)return;let r=Fn({config:t,iframe:n});if(await r.waitForSetup,await r.waitForConnection)return r}function zn(e){let t=It(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}return e.DEEP_LINK_SCHEME=gt,e.DebugInfoGatherer=En,e.FrakContextManager=Ft,e.REFERRAL_SUCCESS_EVENT=tn,e.base64urlDecode=U,e.base64urlEncode=H,e.baseIframeProps=Z,e.clearAllCache=te,e.compressJsonToB64=ct,e.computeLegacyProductId=rt,e.createIFrameFrakClient=Fn,e.createIframe=Bt,e.decompressJsonFromB64=ht,e.displayEmbeddedWallet=n,e.displayModal=r,e.displaySharingPage=i,e.ensureIdentity=fe,e.findIframeInOpener=Ht,e.formatAmount=Rt,e.generateSsoUrl=lt,e.getBackendUrl=c,e.getCache=ee,e.getClientId=d,e.getCurrencyAmountKey=zt,e.getMerchantInformation=pe,e.getMergeToken=me,e.getSupportedCurrency=It,e.getSupportedLocale=Lt,e.getUserReferralStatus=he,e.isChromiumAndroid=_t,e.isFrakDeepLink=J,e.isIOS=Wt,e.isInAppBrowser=Kt,e.isV1Context=W,e.isV2Context=G,e.locales=X,e.mergeAttribution=Jt,e.modalBuilder=sn,e.openSso=pt,e.prepareSso=mt,e.processReferral=$t,e.redirectToExternalBrowser=qt,e.referralInteraction=en,e.sdkConfigStore=T,e.sendInteraction=Yt,e.sendTransaction=cn,e.setupClient=Rn,e.setupReferral=nn,e.siweAuthenticate=un,e.ssoPopupFeatures=dt,e.ssoPopupName=ft,e.toAndroidIntentUrl=vt,e.trackEvent=K,e.trackPurchaseStatus=rn,e.triggerDeepLinkWithFallback=yt,e.watchWalletStatus=an,e.withCache=_,e})({});
|
package/dist/bundle.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./sdkConfigStore-DDL_fjYX.cjs`),t=require(`./src-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./sdkConfigStore-DDL_fjYX.cjs`),t=require(`./src-CqKED785.cjs`),n=require(`./actions-Bwj4zSdB.cjs`);exports.DEEP_LINK_SCHEME=t.b,exports.DebugInfoGatherer=t.r,exports.FrakContextManager=e.n,exports.REFERRAL_SUCCESS_EVENT=n.o,exports.base64urlDecode=e.h,exports.base64urlEncode=e.g,exports.baseIframeProps=t.c,exports.clearAllCache=e.a,exports.compressJsonToB64=e.m,exports.computeLegacyProductId=e._,exports.createIFrameFrakClient=t.n,exports.createIframe=t.l,exports.decompressJsonFromB64=t.x,exports.displayEmbeddedWallet=n.v,exports.displayModal=n._,exports.displaySharingPage=n.g,exports.ensureIdentity=n.h,exports.findIframeInOpener=t.u,exports.formatAmount=t.f,exports.generateSsoUrl=e.p,exports.getBackendUrl=e.c,exports.getCache=e.o,exports.getClientId=e.v,exports.getCurrencyAmountKey=t.d,exports.getMerchantInformation=n.m,exports.getMergeToken=n.p,exports.getSupportedCurrency=t.m,exports.getSupportedLocale=t.p,exports.getUserReferralStatus=n.f,exports.isChromiumAndroid=t.g,exports.isFrakDeepLink=t._,exports.isIOS=t.a,exports.isInAppBrowser=t.o,exports.isV1Context=e.r,exports.isV2Context=e.i,exports.locales=t.h,exports.mergeAttribution=t.i,exports.modalBuilder=n.r,exports.openSso=e.u,exports.prepareSso=n.d,exports.processReferral=n.l,exports.redirectToExternalBrowser=t.s,exports.referralInteraction=n.c,exports.sdkConfigStore=e.t,exports.sendInteraction=n.u,exports.sendTransaction=n.n,exports.setupClient=t.t,exports.setupReferral=n.s,exports.siweAuthenticate=n.t,exports.ssoPopupFeatures=e.d,exports.ssoPopupName=e.f,exports.toAndroidIntentUrl=t.v,exports.trackEvent=e.l,exports.trackPurchaseStatus=n.a,exports.triggerDeepLinkWithFallback=t.y,exports.watchWalletStatus=n.i,exports.withCache=e.s;
|
package/dist/bundle.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,u as g,v as _}from"./sdkConfigStore-BXzz5PlK.js";import{_ as v,a as y,b,c as x,d as S,f as C,g as w,h as T,i as E,l as D,m as O,n as k,o as A,p as j,r as M,s as N,t as P,u as F,v as I,x as L,y as R}from"./src-
|
|
1
|
+
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,u as g,v as _}from"./sdkConfigStore-BXzz5PlK.js";import{_ as v,a as y,b,c as x,d as S,f as C,g as w,h as T,i as E,l as D,m as O,n as k,o as A,p as j,r as M,s as N,t as P,u as F,v as I,x as L,y as R}from"./src-u4vW9qh0.js";import{_ as z,a as B,c as V,d as H,f as U,g as W,h as G,i as K,l as q,m as J,n as Y,o as X,p as Z,r as Q,s as $,t as ee,u as te,v as ne}from"./actions-BlCQVBQJ.js";export{b as DEEP_LINK_SCHEME,M as DebugInfoGatherer,u as FrakContextManager,X as REFERRAL_SUCCESS_EVENT,o as base64urlDecode,a as base64urlEncode,x as baseIframeProps,t as clearAllCache,l as compressJsonToB64,e as computeLegacyProductId,k as createIFrameFrakClient,D as createIframe,L as decompressJsonFromB64,ne as displayEmbeddedWallet,z as displayModal,W as displaySharingPage,G as ensureIdentity,F as findIframeInOpener,C as formatAmount,f as generateSsoUrl,n as getBackendUrl,d as getCache,_ as getClientId,S as getCurrencyAmountKey,J as getMerchantInformation,Z as getMergeToken,O as getSupportedCurrency,j as getSupportedLocale,U as getUserReferralStatus,w as isChromiumAndroid,v as isFrakDeepLink,y as isIOS,A as isInAppBrowser,p as isV1Context,s as isV2Context,T as locales,E as mergeAttribution,Q as modalBuilder,g as openSso,H as prepareSso,q as processReferral,N as redirectToExternalBrowser,V as referralInteraction,h as sdkConfigStore,te as sendInteraction,Y as sendTransaction,P as setupClient,$ as setupReferral,ee as siweAuthenticate,r as ssoPopupFeatures,i as ssoPopupName,I as toAndroidIntentUrl,c as trackEvent,B as trackPurchaseStatus,R as triggerDeepLinkWithFallback,K as watchWalletStatus,m as withCache};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./sdkConfigStore-DDL_fjYX.cjs`),t=require(`./src-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./sdkConfigStore-DDL_fjYX.cjs`),t=require(`./src-CqKED785.cjs`);exports.DEEP_LINK_SCHEME=t.b,exports.DebugInfoGatherer=t.r,exports.FrakContextManager=e.n,exports.base64urlDecode=e.h,exports.base64urlEncode=e.g,exports.baseIframeProps=t.c,exports.clearAllCache=e.a,exports.compressJsonToB64=e.m,exports.computeLegacyProductId=e._,exports.createIFrameFrakClient=t.n,exports.createIframe=t.l,exports.decompressJsonFromB64=t.x,exports.findIframeInOpener=t.u,exports.formatAmount=t.f,exports.generateSsoUrl=e.p,exports.getBackendUrl=e.c,exports.getCache=e.o,exports.getClientId=e.v,exports.getCurrencyAmountKey=t.d,exports.getSupportedCurrency=t.m,exports.getSupportedLocale=t.p,exports.isChromiumAndroid=t.g,exports.isFrakDeepLink=t._,exports.isIOS=t.a,exports.isInAppBrowser=t.o,exports.isV1Context=e.r,exports.isV2Context=e.i,exports.locales=t.h,exports.mergeAttribution=t.i,exports.redirectToExternalBrowser=t.s,exports.sdkConfigStore=e.t,exports.setupClient=t.t,exports.ssoPopupFeatures=e.d,exports.ssoPopupName=e.f,exports.toAndroidIntentUrl=t.v,exports.trackEvent=e.l,exports.triggerDeepLinkWithFallback=t.y,exports.withCache=e.s;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,v as g}from"./sdkConfigStore-BXzz5PlK.js";import{_,a as v,b as y,c as b,d as x,f as S,g as C,h as w,i as T,l as E,m as D,n as O,o as k,p as A,r as j,s as M,t as N,u as P,v as F,x as I,y as L}from"./src-
|
|
1
|
+
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,v as g}from"./sdkConfigStore-BXzz5PlK.js";import{_,a as v,b as y,c as b,d as x,f as S,g as C,h as w,i as T,l as E,m as D,n as O,o as k,p as A,r as j,s as M,t as N,u as P,v as F,x as I,y as L}from"./src-u4vW9qh0.js";export{y as DEEP_LINK_SCHEME,j as DebugInfoGatherer,u as FrakContextManager,o as base64urlDecode,a as base64urlEncode,b as baseIframeProps,t as clearAllCache,l as compressJsonToB64,e as computeLegacyProductId,O as createIFrameFrakClient,E as createIframe,I as decompressJsonFromB64,P as findIframeInOpener,S as formatAmount,f as generateSsoUrl,n as getBackendUrl,d as getCache,g as getClientId,x as getCurrencyAmountKey,D as getSupportedCurrency,A as getSupportedLocale,C as isChromiumAndroid,_ as isFrakDeepLink,v as isIOS,k as isInAppBrowser,p as isV1Context,s as isV2Context,w as locales,T as mergeAttribution,M as redirectToExternalBrowser,h as sdkConfigStore,N as setupClient,r as ssoPopupFeatures,i as ssoPopupName,F as toAndroidIntentUrl,c as trackEvent,L as triggerDeepLinkWithFallback,m as withCache};
|
|
@@ -10,4 +10,4 @@ const e=require(`./sdkConfigStore-DDL_fjYX.cjs`);let t=require(`@frak-labs/frame
|
|
|
10
10
|
Last Response: ${t.lastResponse}
|
|
11
11
|
Client Status: ${t.clientStatus}
|
|
12
12
|
Error: ${t.error}
|
|
13
|
-
`.trim()}};const D=(()=>{if(typeof navigator>`u`)return!1;let e=navigator.userAgent;if(!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1))return!1;let t=e.toLowerCase();return t.includes(`instagram`)||t.includes(`fban`)||t.includes(`fbav`)||t.includes(`facebook`)})();function O(e){e?localStorage.setItem(i,e):localStorage.removeItem(i)}function k(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=M(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function A(e){let t=new URL(window.location.href);e&&t.searchParams.set(`fmt`,e);let n=t.protocol===`http:`?`x-safari-http`:`x-safari-https`;window.location.href=`${n}://${t.host}${t.pathname}${t.search}${t.hash}`}function j(e){return e.includes(`/common/social`)}function M(e,t){if(!t)return e;try{let n=new URL(e);return n.searchParams.set(`fmt`,t),n.toString()}catch{return`${e}${e.includes(`?`)?`&`:`?`}fmt=${encodeURIComponent(t)}`}}function N(e,t,n,r,i){if(i){let e=k(t,r);window.open(e,`_blank`);return}if(l(t)){let i=k(t,r);c(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(D&&j(t))A(r);else{let e=k(t,r);window.location.href=e}}function P({iframe:e,targetOrigin:n}){let r=new t.Deferred;return{handleEvent:t=>{if(!(`iframeLifecycle`in t))return;let{iframeLifecycle:a,data:o}=t;switch(a){case`connected`:r.resolve(!0);break;case`do-backup`:O(o.backup);break;case`remove-backup`:localStorage.removeItem(i);break;case`show`:case`hide`:_({iframe:e,isVisible:a===`show`});break;case`redirect`:N(e,o.baseRedirectUrl,n,o.mergeToken,o.openInNewTab);break}},isConnected:r.promise}}function F({config:r,iframe:i}){let a=r?.walletUrl??`https://wallet.frak.id`,o=typeof navigator<`u`?navigator.language?.split(`-`)[0]:void 0,s=r.metadata.lang??(o===`en`||o===`fr`?o:void 0),c=r.domain??(typeof window<`u`?window.location.hostname:``);e.t.setCacheScope(c,s),e.t.reset();let l=e.t.isCacheFresh?void 0:e.t.resolve(r.domain,r.walletUrl,s),u=P({iframe:i,targetOrigin:a}),d=new t.Deferred,f=Date.now(),p=new E(r,i);if(!i.contentWindow)throw new t.FrakRpcError(t.RpcErrorCodes.configError,`The iframe does not have a content window`);let m=(0,t.createRpcClient)({emittingTransport:i.contentWindow,listeningTransport:window,targetOrigin:a,middleware:[{async onRequest(e,n){if(!await u.isConnected)throw new t.FrakRpcError(t.RpcErrorCodes.clientNotConnected,`The iframe provider isn't connected yet`);return await d.promise,n}},{onRequest(e,t){return p.setLastRequest(e),t},onResponse(e,t){return p.setLastResponse(e,t),t}}],lifecycleHandlers:{iframeLifecycle:(e,t)=>{u.handleEvent(e)}}}),h=I(m,u),g=async()=>{h(),m.cleanup(),i.remove(),e.a(),e.t.clearCache(),e.t.reset()},_;{console.log(`[Frak SDK] Initializing OpenPanel`),_=new n.OpenPanel({apiUrl:`https://op-api.gcp.frak.id`,clientId:`
|
|
13
|
+
`.trim()}};const D=(()=>{if(typeof navigator>`u`)return!1;let e=navigator.userAgent;if(!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1))return!1;let t=e.toLowerCase();return t.includes(`instagram`)||t.includes(`fban`)||t.includes(`fbav`)||t.includes(`facebook`)})();function O(e){e?localStorage.setItem(i,e):localStorage.removeItem(i)}function k(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=M(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function A(e){let t=new URL(window.location.href);e&&t.searchParams.set(`fmt`,e);let n=t.protocol===`http:`?`x-safari-http`:`x-safari-https`;window.location.href=`${n}://${t.host}${t.pathname}${t.search}${t.hash}`}function j(e){return e.includes(`/common/social`)}function M(e,t){if(!t)return e;try{let n=new URL(e);return n.searchParams.set(`fmt`,t),n.toString()}catch{return`${e}${e.includes(`?`)?`&`:`?`}fmt=${encodeURIComponent(t)}`}}function N(e,t,n,r,i){if(i){let e=k(t,r);window.open(e,`_blank`);return}if(l(t)){let i=k(t,r);c(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(D&&j(t))A(r);else{let e=k(t,r);window.location.href=e}}function P({iframe:e,targetOrigin:n}){let r=new t.Deferred;return{handleEvent:t=>{if(!(`iframeLifecycle`in t))return;let{iframeLifecycle:a,data:o}=t;switch(a){case`connected`:r.resolve(!0);break;case`do-backup`:O(o.backup);break;case`remove-backup`:localStorage.removeItem(i);break;case`show`:case`hide`:_({iframe:e,isVisible:a===`show`});break;case`redirect`:N(e,o.baseRedirectUrl,n,o.mergeToken,o.openInNewTab);break}},isConnected:r.promise}}function F({config:r,iframe:i}){let a=r?.walletUrl??`https://wallet.frak.id`,o=typeof navigator<`u`?navigator.language?.split(`-`)[0]:void 0,s=r.metadata.lang??(o===`en`||o===`fr`?o:void 0),c=r.domain??(typeof window<`u`?window.location.hostname:``);e.t.setCacheScope(c,s),e.t.reset();let l=e.t.isCacheFresh?void 0:e.t.resolve(r.domain,r.walletUrl,s),u=P({iframe:i,targetOrigin:a}),d=new t.Deferred,f=Date.now(),p=new E(r,i);if(!i.contentWindow)throw new t.FrakRpcError(t.RpcErrorCodes.configError,`The iframe does not have a content window`);let m=(0,t.createRpcClient)({emittingTransport:i.contentWindow,listeningTransport:window,targetOrigin:a,middleware:[{async onRequest(e,n){if(!await u.isConnected)throw new t.FrakRpcError(t.RpcErrorCodes.clientNotConnected,`The iframe provider isn't connected yet`);return await d.promise,n}},{onRequest(e,t){return p.setLastRequest(e),t},onResponse(e,t){return p.setLastResponse(e,t),t}}],lifecycleHandlers:{iframeLifecycle:(e,t)=>{u.handleEvent(e)}}}),h=I(m,u),g=async()=>{h(),m.cleanup(),i.remove(),e.a(),e.t.clearCache(),e.t.reset()},_;{console.log(`[Frak SDK] Initializing OpenPanel`),_=new n.OpenPanel({apiUrl:`https://op-api.gcp.frak.id`,clientId:`f305d11d-b93b-487c-80d4-92deb7903e98`,trackScreenViews:!0,trackOutgoingLinks:!0,trackAttributes:!1,filter:({type:t,payload:n})=>(t!==`track`||!n?.properties||`sdkVersion`in n.properties||(n.properties={...n.properties,sdkVersion:`1.0.1`,userAnonymousClientId:e.v()}),!0)}),_.setGlobalProperties({sdkVersion:`1.0.1`,userAnonymousClientId:e.v()}),_.init(),_.track(`sdk_initialized`,{sdkVersion:`1.0.1`});let t=!1,r=setTimeout(()=>{t||(t=!0,_?.track(`sdk_iframe_handshake_failed`,{reason:`timeout`}))},3e4);u.isConnected.then(()=>{t||(t=!0,clearTimeout(r),_?.track(`sdk_iframe_connected`,{handshake_duration_ms:Date.now()-f}))}).catch(()=>{t||(t=!0,clearTimeout(r),_?.track(`sdk_iframe_handshake_failed`,{reason:`unknown`}))})}let v=L({config:r,rpcClient:m,lifecycleManager:u,configPromise:l,contextSent:d,openPanel:_}).then(()=>p.updateSetupStatus(!0)).catch(e=>{throw d.reject(e),e});return{config:r,debugInfo:p,waitForConnection:u.isConnected,waitForSetup:v,request:m.request,listenerRequest:m.listen,destroy:g,openPanel:_}}function I(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,1e3),r=setTimeout(()=>{o(),console.log(`Heartbeat timeout: connection failed`)},3e4),await t.isConnected,o()}function o(){n&&clearInterval(n),r&&clearTimeout(r)}return a(),o}async function L({config:t,rpcClient:n,lifecycleManager:r,configPromise:a,contextSent:o,openPanel:s}){await r.isConnected,T(n,r.isConnected);let c=new URL(window.location.href),l=c.searchParams.get(`fmt`)??void 0;l&&(c.searchParams.delete(`fmt`),window.history.replaceState({},``,c.toString()));let u=n=>{let r=n?.merchantId??t.metadata.merchantId??``,i=n?.domain??``,a=n?.allowedDomains??[],o=n?.sdkConfig,s=o?.attribution||t.attribution?{...t.attribution,...o?.attribution}:void 0;e.t.setConfig(o?{isResolved:!0,merchantId:r,domain:i,allowedDomains:a,hasRawSdkConfig:!0,name:o.name??t.metadata.name,logoUrl:o.logoUrl??t.metadata.logoUrl,homepageLink:o.homepageLink??t.metadata.homepageLink,lang:o.lang??t.metadata.lang,currency:o.currency??t.metadata.currency,hidden:o.hidden,css:o.css,translations:o.translations,placements:o.placements,components:o.components,attribution:s}:{isResolved:!0,merchantId:r,domain:i,allowedDomains:a,name:t.metadata.name,logoUrl:t.metadata.logoUrl,homepageLink:t.metadata.homepageLink,lang:t.metadata.lang,currency:t.metadata.currency,attribution:s})},d=!1,f=t=>{let r=d?void 0:l;d=!0;let i=t.hasRawSdkConfig?{name:t.name,logoUrl:t.logoUrl,homepageLink:t.homepageLink,lang:t.lang,currency:t.currency,hidden:t.hidden,css:t.css,translations:t.translations,placements:t.placements,attribution:t.attribution}:t.attribution?{attribution:t.attribution}:void 0,a=e.v();if(s){let e=s.global??{};s.setGlobalProperties({...e,merchantId:t.merchantId,domain:t.domain??``})}n.sendLifecycle({clientLifecycle:`resolved-config`,data:{merchantId:t.merchantId,domain:t.domain??``,allowedDomains:t.allowedDomains??[],sourceUrl:window.location.href,...a&&{sdkAnonymousId:a},...r&&{pendingMergeToken:r},...i&&{sdkConfig:i}}})};e.t.isResolved&&(f(e.t.getConfig()),o.resolve()),a&&(u(await a),f(e.t.getConfig()),o.resolve());async function p(){let e=t.customizations?.css;e&&n.sendLifecycle({clientLifecycle:`modal-css`,data:{cssLink:e}})}async function m(){let e=t.customizations?.i18n;e&&n.sendLifecycle({clientLifecycle:`modal-i18n`,data:{i18n:e}})}async function h(){if(typeof window>`u`)return;let e=window.localStorage.getItem(i);e&&n.sendLifecycle({clientLifecycle:`restore-backup`,data:{backup:e}})}(await Promise.allSettled([p(),m(),h()])).some(e=>e.status===`rejected`)&&s?.track(`sdk_iframe_handshake_failed`,{reason:`asset_push`})}async function R({config:e}){let t=z(e),n=await g({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=F({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function z(e){let t=d(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return c}});
|
|
@@ -10,4 +10,4 @@ import{a as e,h as t,t as n,v as r}from"./sdkConfigStore-BXzz5PlK.js";import{Def
|
|
|
10
10
|
Last Response: ${t.lastResponse}
|
|
11
11
|
Client Status: ${t.clientStatus}
|
|
12
12
|
Error: ${t.error}
|
|
13
|
-
`.trim()}};const P=(()=>{if(typeof navigator>`u`)return!1;let e=navigator.userAgent;if(!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1))return!1;let t=e.toLowerCase();return t.includes(`instagram`)||t.includes(`fban`)||t.includes(`fbav`)||t.includes(`facebook`)})();function F(e){e?localStorage.setItem(d,e):localStorage.removeItem(d)}function I(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=z(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function L(e){let t=new URL(window.location.href);e&&t.searchParams.set(`fmt`,e);let n=t.protocol===`http:`?`x-safari-http`:`x-safari-https`;window.location.href=`${n}://${t.host}${t.pathname}${t.search}${t.hash}`}function R(e){return e.includes(`/common/social`)}function z(e,t){if(!t)return e;try{let n=new URL(e);return n.searchParams.set(`fmt`,t),n.toString()}catch{return`${e}${e.includes(`?`)?`&`:`?`}fmt=${encodeURIComponent(t)}`}}function B(e,t,n,r,i){if(i){let e=I(t,r);window.open(e,`_blank`);return}if(g(t)){let i=I(t,r);h(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(P&&R(t))L(r);else{let e=I(t,r);window.location.href=e}}function V({iframe:e,targetOrigin:t}){let n=new i;return{handleEvent:r=>{if(!(`iframeLifecycle`in r))return;let{iframeLifecycle:i,data:a}=r;switch(i){case`connected`:n.resolve(!0);break;case`do-backup`:F(a.backup);break;case`remove-backup`:localStorage.removeItem(d);break;case`show`:case`hide`:w({iframe:e,isVisible:i===`show`});break;case`redirect`:B(e,a.baseRedirectUrl,t,a.mergeToken,a.openInNewTab);break}},isConnected:n.promise}}function H({config:t,iframe:c}){let u=t?.walletUrl??`https://wallet.frak.id`,d=typeof navigator<`u`?navigator.language?.split(`-`)[0]:void 0,f=t.metadata.lang??(d===`en`||d===`fr`?d:void 0),p=t.domain??(typeof window<`u`?window.location.hostname:``);n.setCacheScope(p,f),n.reset();let m=n.isCacheFresh?void 0:n.resolve(t.domain,t.walletUrl,f),h=V({iframe:c,targetOrigin:u}),g=new i,_=Date.now(),v=new N(t,c);if(!c.contentWindow)throw new a(o.configError,`The iframe does not have a content window`);let y=s({emittingTransport:c.contentWindow,listeningTransport:window,targetOrigin:u,middleware:[{async onRequest(e,t){if(!await h.isConnected)throw new a(o.clientNotConnected,`The iframe provider isn't connected yet`);return await g.promise,t}},{onRequest(e,t){return v.setLastRequest(e),t},onResponse(e,t){return v.setLastResponse(e,t),t}}],lifecycleHandlers:{iframeLifecycle:(e,t)=>{h.handleEvent(e)}}}),b=U(y,h),x=async()=>{b(),y.cleanup(),c.remove(),e(),n.clearCache(),n.reset()},S;{console.log(`[Frak SDK] Initializing OpenPanel`),S=new l({apiUrl:`https://op-api.gcp.frak.id`,clientId:`
|
|
13
|
+
`.trim()}};const P=(()=>{if(typeof navigator>`u`)return!1;let e=navigator.userAgent;if(!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1))return!1;let t=e.toLowerCase();return t.includes(`instagram`)||t.includes(`fban`)||t.includes(`fbav`)||t.includes(`facebook`)})();function F(e){e?localStorage.setItem(d,e):localStorage.removeItem(d)}function I(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=z(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function L(e){let t=new URL(window.location.href);e&&t.searchParams.set(`fmt`,e);let n=t.protocol===`http:`?`x-safari-http`:`x-safari-https`;window.location.href=`${n}://${t.host}${t.pathname}${t.search}${t.hash}`}function R(e){return e.includes(`/common/social`)}function z(e,t){if(!t)return e;try{let n=new URL(e);return n.searchParams.set(`fmt`,t),n.toString()}catch{return`${e}${e.includes(`?`)?`&`:`?`}fmt=${encodeURIComponent(t)}`}}function B(e,t,n,r,i){if(i){let e=I(t,r);window.open(e,`_blank`);return}if(g(t)){let i=I(t,r);h(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(P&&R(t))L(r);else{let e=I(t,r);window.location.href=e}}function V({iframe:e,targetOrigin:t}){let n=new i;return{handleEvent:r=>{if(!(`iframeLifecycle`in r))return;let{iframeLifecycle:i,data:a}=r;switch(i){case`connected`:n.resolve(!0);break;case`do-backup`:F(a.backup);break;case`remove-backup`:localStorage.removeItem(d);break;case`show`:case`hide`:w({iframe:e,isVisible:i===`show`});break;case`redirect`:B(e,a.baseRedirectUrl,t,a.mergeToken,a.openInNewTab);break}},isConnected:n.promise}}function H({config:t,iframe:c}){let u=t?.walletUrl??`https://wallet.frak.id`,d=typeof navigator<`u`?navigator.language?.split(`-`)[0]:void 0,f=t.metadata.lang??(d===`en`||d===`fr`?d:void 0),p=t.domain??(typeof window<`u`?window.location.hostname:``);n.setCacheScope(p,f),n.reset();let m=n.isCacheFresh?void 0:n.resolve(t.domain,t.walletUrl,f),h=V({iframe:c,targetOrigin:u}),g=new i,_=Date.now(),v=new N(t,c);if(!c.contentWindow)throw new a(o.configError,`The iframe does not have a content window`);let y=s({emittingTransport:c.contentWindow,listeningTransport:window,targetOrigin:u,middleware:[{async onRequest(e,t){if(!await h.isConnected)throw new a(o.clientNotConnected,`The iframe provider isn't connected yet`);return await g.promise,t}},{onRequest(e,t){return v.setLastRequest(e),t},onResponse(e,t){return v.setLastResponse(e,t),t}}],lifecycleHandlers:{iframeLifecycle:(e,t)=>{h.handleEvent(e)}}}),b=U(y,h),x=async()=>{b(),y.cleanup(),c.remove(),e(),n.clearCache(),n.reset()},S;{console.log(`[Frak SDK] Initializing OpenPanel`),S=new l({apiUrl:`https://op-api.gcp.frak.id`,clientId:`f305d11d-b93b-487c-80d4-92deb7903e98`,trackScreenViews:!0,trackOutgoingLinks:!0,trackAttributes:!1,filter:({type:e,payload:t})=>(e!==`track`||!t?.properties||`sdkVersion`in t.properties||(t.properties={...t.properties,sdkVersion:`1.0.1`,userAnonymousClientId:r()}),!0)}),S.setGlobalProperties({sdkVersion:`1.0.1`,userAnonymousClientId:r()}),S.init(),S.track(`sdk_initialized`,{sdkVersion:`1.0.1`});let e=!1,t=setTimeout(()=>{e||(e=!0,S?.track(`sdk_iframe_handshake_failed`,{reason:`timeout`}))},3e4);h.isConnected.then(()=>{e||(e=!0,clearTimeout(t),S?.track(`sdk_iframe_connected`,{handshake_duration_ms:Date.now()-_}))}).catch(()=>{e||(e=!0,clearTimeout(t),S?.track(`sdk_iframe_handshake_failed`,{reason:`unknown`}))})}let C=W({config:t,rpcClient:y,lifecycleManager:h,configPromise:m,contextSent:g,openPanel:S}).then(()=>v.updateSetupStatus(!0)).catch(e=>{throw g.reject(e),e});return{config:t,debugInfo:v,waitForConnection:h.isConnected,waitForSetup:C,request:y.request,listenerRequest:y.listen,destroy:x,openPanel:S}}function U(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,1e3),r=setTimeout(()=>{o(),console.log(`Heartbeat timeout: connection failed`)},3e4),await t.isConnected,o()}function o(){n&&clearInterval(n),r&&clearTimeout(r)}return a(),o}async function W({config:e,rpcClient:t,lifecycleManager:i,configPromise:a,contextSent:o,openPanel:s}){await i.isConnected,M(t,i.isConnected);let c=new URL(window.location.href),l=c.searchParams.get(`fmt`)??void 0;l&&(c.searchParams.delete(`fmt`),window.history.replaceState({},``,c.toString()));let u=t=>{let r=t?.merchantId??e.metadata.merchantId??``,i=t?.domain??``,a=t?.allowedDomains??[],o=t?.sdkConfig,s=o?.attribution||e.attribution?{...e.attribution,...o?.attribution}:void 0;n.setConfig(o?{isResolved:!0,merchantId:r,domain:i,allowedDomains:a,hasRawSdkConfig:!0,name:o.name??e.metadata.name,logoUrl:o.logoUrl??e.metadata.logoUrl,homepageLink:o.homepageLink??e.metadata.homepageLink,lang:o.lang??e.metadata.lang,currency:o.currency??e.metadata.currency,hidden:o.hidden,css:o.css,translations:o.translations,placements:o.placements,components:o.components,attribution:s}:{isResolved:!0,merchantId:r,domain:i,allowedDomains:a,name:e.metadata.name,logoUrl:e.metadata.logoUrl,homepageLink:e.metadata.homepageLink,lang:e.metadata.lang,currency:e.metadata.currency,attribution:s})},f=!1,p=e=>{let n=f?void 0:l;f=!0;let i=e.hasRawSdkConfig?{name:e.name,logoUrl:e.logoUrl,homepageLink:e.homepageLink,lang:e.lang,currency:e.currency,hidden:e.hidden,css:e.css,translations:e.translations,placements:e.placements,attribution:e.attribution}:e.attribution?{attribution:e.attribution}:void 0,a=r();if(s){let t=s.global??{};s.setGlobalProperties({...t,merchantId:e.merchantId,domain:e.domain??``})}t.sendLifecycle({clientLifecycle:`resolved-config`,data:{merchantId:e.merchantId,domain:e.domain??``,allowedDomains:e.allowedDomains??[],sourceUrl:window.location.href,...a&&{sdkAnonymousId:a},...n&&{pendingMergeToken:n},...i&&{sdkConfig:i}}})};n.isResolved&&(p(n.getConfig()),o.resolve()),a&&(u(await a),p(n.getConfig()),o.resolve());async function m(){let n=e.customizations?.css;n&&t.sendLifecycle({clientLifecycle:`modal-css`,data:{cssLink:n}})}async function h(){let n=e.customizations?.i18n;n&&t.sendLifecycle({clientLifecycle:`modal-i18n`,data:{i18n:n}})}async function g(){if(typeof window>`u`)return;let e=window.localStorage.getItem(d);e&&t.sendLifecycle({clientLifecycle:`restore-backup`,data:{backup:e}})}(await Promise.allSettled([m(),h(),g()])).some(e=>e.status===`rejected`)&&s?.track(`sdk_iframe_handshake_failed`,{reason:`asset_push`})}async function G({config:e}){let t=K(e),n=await C({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=H({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function K(e){let t=v(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}export{g as _,D as a,f as b,S as c,x as d,b as f,p as g,_ as h,j as i,C as l,v as m,H as n,k as o,y as p,N as r,A as s,G as t,T as u,m as v,u as x,h as y};
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "https://twitter.com/QNivelais"
|
|
12
12
|
}
|
|
13
13
|
],
|
|
14
|
-
"version": "1.0.1
|
|
14
|
+
"version": "1.0.1",
|
|
15
15
|
"description": "Core SDK of the Frak wallet, low level library to interact directly with the frak ecosystem.",
|
|
16
16
|
"repository": {
|
|
17
17
|
"url": "https://github.com/frak-id/wallet",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"viem": "^2.x"
|
|
92
92
|
},
|
|
93
93
|
"dependencies": {
|
|
94
|
-
"@frak-labs/frame-connector": "0.2.0
|
|
94
|
+
"@frak-labs/frame-connector": "0.2.0",
|
|
95
95
|
"@openpanel/web": "^1.2.0"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|