@frak-labs/nexus-sdk 0.0.47-beta.473e9a7a → 0.0.47-beta.7dfd3480
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/bundle.js +2 -2
- package/package.json +2 -2
package/dist/bundle/bundle.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var NexusSDK=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=(e,t)=>()=>(e&&(t=e(e=0)),t);function n(e,{strict:t=!0}={}){return!e||typeof e!=`string`?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith(`0x`)}var r=t((()=>{}));function i(e){return n(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}var a=t((()=>{r()})),o,s=t((()=>{o=`2.47.16`}));function c(e,t){return t?.(e)?e:e&&typeof e==`object`&&`cause`in e&&e.cause!==void 0?c(e.cause,t):t?null:e}var l,u,d=t((()=>{s(),l={getDocsUrl:({docsBaseUrl:e,docsPath:t=``,docsSlug:n})=>t?`${e??`https://viem.sh`}${t}${n?`#${n}`:``}`:void 0,version:`viem@${o}`},u=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=l.getDocsUrl?.({...n,docsPath:i}),s=[t||`An error occurred.`,``,...n.metaMessages?[...n.metaMessages,``]:[],...a?[`Docs: ${a}`]:[],...r?[`Details: ${r}`]:[],...l.version?[`Version: ${l.version}`]:[]].join(`
|
|
2
|
-
`);super(s,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=o}walk(e){return c(this,e)}}})),f,p=t((()=>{d(),f=class extends u{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 m(e,{dir:t,size:n=32}={}){return typeof e==`string`?h(e,{dir:t,size:n}):ee(e,{dir:t,size:n})}function h(e,{dir:t,size:n=32}={}){if(n===null)return e;let r=e.replace(`0x`,``);if(r.length>n*2)throw new f({size:Math.ceil(r.length/2),targetSize:n,type:`hex`});return`0x${r[t===`right`?`padEnd`:`padStart`](n*2,`0`)}`}function ee(e,{dir:t,size:n=32}={}){if(n===null)return e;if(e.length>n)throw new f({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 te=t((()=>{p()})),g,ne,re=t((()=>{d(),g=class extends u{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`})}},ne=class extends u{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:`SizeOverflowError`})}}}));function _(e,{size:t}){if(i(e)>t)throw new ne({givenSize:i(e),maxSize:t})}var ie=t((()=>{re(),a()}));function ae(e,t={}){return typeof e==`number`||typeof e==`bigint`?se(e,t):typeof e==`string`?ce(e,t):typeof e==`boolean`?oe(e,t):v(e,t)}function oe(e,t={}){let n=`0x${Number(e)}`;return typeof t.size==`number`?(_(n,{size:t.size}),m(n,{size:t.size})):n}function v(e,t={}){let n=``;for(let t=0;t<e.length;t++)n+=le[e[t]];let r=`0x${n}`;return typeof t.size==`number`?(_(r,{size:t.size}),m(r,{dir:`right`,size:t.size})):r}function se(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 g({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?m(s,{size:r}):s}function ce(e,t={}){return v(ue.encode(e),t)}var le,ue;function de(e,t={}){return typeof e==`number`||typeof e==`bigint`?me(e,t):typeof e==`boolean`?fe(e,t):n(e)?y(e,t):he(e,t)}function fe(e,t={}){let n=new Uint8Array(1);return n[0]=Number(e),typeof t.size==`number`?(_(n,{size:t.size}),m(n,{size:t.size})):n}function pe(e){if(e>=b.zero&&e<=b.nine)return e-b.zero;if(e>=b.A&&e<=b.F)return e-(b.A-10);if(e>=b.a&&e<=b.f)return e-(b.a-10)}function y(e,t={}){let n=e;t.size&&(_(n,{size:t.size}),n=m(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=pe(r.charCodeAt(t++)),i=pe(r.charCodeAt(t++));if(n===void 0||i===void 0)throw new u(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);a[e]=n*16+i}return a}function me(e,t){return y(se(e,t))}function he(e,t={}){let n=ge.encode(e);return typeof t.size==`number`?(_(n,{size:t.size}),m(n,{dir:`right`,size:t.size})):n}var ge,b,_e,ve;function ye(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function be(e,...t){if(!ye(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 xe(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function Se(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}var Ce,we;function Te(e,t){let r=t||`hex`,i=we(n(e,{strict:!1})?de(e):e);return r===`bytes`?i:ae(i)}var Ee;function De(e,t){if(Oe.has(`${e}.${t}`))return Oe.get(`${e}.${t}`);let n=t?`${t}${e.toLowerCase()}`:e.substring(2).toLowerCase(),r=Te(he(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 Oe.set(`${e}.${t}`,a),a}var Oe;function x(e,t){let{strict:n=!0}=t??{},r=`${e}.${n}`;if(Ae.has(r))return Ae.get(r);let i=ke.test(e)?e.toLowerCase()===e?!0:n?De(e)===e:!0:!1;return Ae.set(r,i),i}var ke,Ae;function je(e,t){if(!x(e,{strict:!1}))throw new Ee({address:e});if(!x(t,{strict:!1}))throw new Ee({address:t});return e.toLowerCase()===t.toLowerCase()}let S=256,C;function Me(e=11){if(!C||S+e>256*2){C=``,S=0;for(let e=0;e<256;e++)C+=(256+Math.random()*256|0).toString(16).substring(1)}return C.substring(S,S+++e)}let Ne={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 w=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}}},T=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 Pe(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 ee(e){let t=h(),n=new T;return o.set(t,e=>{e.error?n.reject(new w(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 te(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 g(){n.removeEventListener(`message`,f),o.clear()}return{request:ee,listen:te,sendLifecycle:m,cleanup:g}}function Fe(e){return new TextEncoder().encode(JSON.stringify(e))}function Ie(e){try{return JSON.parse(new TextDecoder().decode(e))}catch{return null}}let Le=`frak-client-id`;function Re(){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 E(){if(typeof window>`u`||!window.localStorage)return console.warn(`[Frak SDK] No Window / localStorage available to save the clientId`),Re();let e=localStorage.getItem(Le);return e||(e=Re(),localStorage.setItem(Le,e)),e}function ze({domain:e}={}){return Te(ae((e??window.location.host).replace(`www.`,``)))}function D(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function O(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 Be(e){return D(Fe(e))}function Ve(e,t,n,r,i,a){let o=Be(He({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 He(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 Ue=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,We=`frak-sso`;async function Ge(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??Ve(i??`https://wallet.frak.id`,t,ze(),n.name,E(),r?.css),o=window.open(a,We,Ue);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]})??{}}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)}}let Ke=`https://backend.frak.id`;function qe(e){return e.includes(`localhost:3000`)||e.includes(`localhost:3010`)}function Je(e){return qe(e)?`https://localhost:3030`:e.includes(`wallet-dev.frak.id`)||e.includes(`wallet.gcp-dev.frak.id`)?`https://backend.gcp-dev.frak.id`:Ke}function A(e){if(e)return Je(e);if(typeof window<`u`){let e=window.FrakSetup?.client?.config?.walletUrl;if(e)return Je(e)}return Ke}var Ye=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 j=new Ye(1024),M=new Ye(1024),Xe=3e4,N=new Ye(1024);async function P(e,{cacheKey:t,cacheTime:n=Xe}){if(n>0){let e=M.get(t);if(e&&Date.now()-e.created<n)return e.data}let r=N.get(t);if(r&&Date.now()-r<1e3)throw Error(`Cache: ${t} recently failed, backing off`);let i=j.get(t);i||(i=e(),j.set(t,i));try{let e=await i;return M.set(t,{data:e,created:Date.now()}),N.delete(t),e}catch(e){throw N.set(t,Date.now()),e}finally{j.delete(t)}}function Ze(e){return{clear:()=>{j.delete(e),M.delete(e)},has:(t=Xe)=>{let n=M.get(e);return n?Date.now()-n.created<t:!1}}}function F(){j.clear(),M.clear(),N.clear()}function I(e){return`r`in e&&!(`v`in e)}function L(e){return`v`in e&&e.v===2}let Qe=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function $e(e){return typeof e==`string`&&Qe.test(e)}function et(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 tt(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 nt(e){if(!$e(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`&&x(e.w);if(!t&&!n||t&&!$e(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(et(e.m),a),a+=16,i.setUint32(a,e.t,!1),a+=4,t&&(r.set(et(e.c),a),a+=16),n&&(r.set(y(e.w),a),a+=20),r}function rt(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=tt(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=tt(e.subarray(a,a+16)),a+=16),r){let t=v(e.subarray(a,a+20),{size:20});if(!x(t))return null;c.w=t,a+=20}return c}let R=`fCtx`;function it(e){if(e)try{if(L(e)){let t=nt(e);return t?D(t):void 0}return D(y(e.r))}catch(t){console.error(`Error compressing Frak context`,{e:t,context:e})}}function at(e){if(!(!e||e.length===0))try{let t=O(e);if(t.length!==20)return rt(t)||void 0;let n=v(t,{size:20});if(x(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(R);return t?at(t):null}let st=`frak`;function ct(e,t){let n=L(e);return{utm_source:t.utmSource??st,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??st,ref:t.ref??(n?e.c:void 0)}}function lt(e,t,n){let r=ct(t,n??{});for(let[t,n]of Object.entries(r))n===void 0||n===``||e.searchParams.has(t)||e.searchParams.set(t,n)}function ut({url:e,context:t,attribution:n}){if(!e)return null;let r=it(t);if(!r)return null;let i=new URL(e);return i.searchParams.set(R,r),lt(i,t,n),i.toString()}function dt(e){let t=new URL(e);return t.searchParams.delete(R),t.toString()}function ft({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?dt(n):ut({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}let z={compress:it,decompress:at,parse:ot,update:ut,remove:dt,replaceUrl:ft},B=`__frakSdkConfig`,pt=`frak-config-cache`,V=`frak-merchant-id`,H={key:pt},U=typeof window<`u`;function W(){return{isResolved:!1,merchantId:``}}let G=null;function mt(){if(!U)return null;try{let e=localStorage.getItem(H.key);if(!e)return null;let t=JSON.parse(e);return t.config?.isResolved?(G=t,t):null}catch{return null}}function ht(){return(G??mt())?.config}function gt(){let e=G??mt();return e?Date.now()-e.timestamp<3e4:!1}function _t(e){if(!(!U||!e.isResolved))try{let t={config:e,timestamp:Date.now()};localStorage.setItem(H.key,JSON.stringify(t)),G=t}catch{}}function vt(){if(U){G=null;try{localStorage.removeItem(H.key)}catch{}}}function yt(){U&&(window[B]||(window[B]=ht()??W()))}yt();function K(){return U?window[B]??W():W()}function bt(e){U&&window.dispatchEvent(new CustomEvent(`frak:config`,{detail:e}))}function xt(e){return e??(U?window.location.hostname:``)}async function St(e,t,n){try{let r=A(t),i=n?`&lang=${encodeURIComponent(n)}`:``,a=await fetch(`${r}/user/merchant/resolve?domain=${encodeURIComponent(e)}${i}`);if(!a.ok){console.warn(`[Frak SDK] Merchant lookup failed for domain ${e}: ${a.status}`);return}let o=await a.json();if(U)try{sessionStorage.setItem(V,o.merchantId)}catch{}return o}catch(e){console.warn(`[Frak SDK] Failed to fetch merchant config:`,e);return}}let q={getConfig:K,get isResolved(){return K().isResolved},get isCacheFresh(){return gt()},setCacheScope(e,t){H.key=`${pt}:${`${e}:${t??``}`}`,G=null},setConfig(e){if(U&&(window[B]=e),_t(e),bt(e),U&&e.merchantId)try{sessionStorage.setItem(V,e.merchantId)}catch{}},reset(){let e=ht()??W();U&&(window[B]=e),bt(e)},clearCache(){if(vt(),F(),U)try{sessionStorage.removeItem(V)}catch{}},resolve(e,t,n){let r=xt(e);return r?P(async()=>{let e=await St(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=K();if(e.isResolved&&e.merchantId)return e.merchantId;if(U)try{return sessionStorage.getItem(V)??void 0}catch{}},async resolveMerchantId(e,t){return q.getMerchantId()||(await q.resolve(e,t))?.merchantId}};function Ct(){return()=>{}}var wt=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)}},Tt=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 wt({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)}},Et=Object.defineProperty,Dt=(e,t)=>()=>(e&&(t=e(e=0)),t),Ot=(e,t)=>{for(var n in t)Et(e,n,{get:t[n],enumerable:!0})};function kt(e,t){if(typeof document>`u`||typeof window>`u`)return;J&&J();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=Ct({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),J=()=>{a.length>0&&c(a.some(e=>e.type===2)),s&&=(clearInterval(s),null),document.removeEventListener(`visibilitychange`,p),window.removeEventListener(`pagehide`,m),f?.(),J=null}}function At(){J&&J()}var J,jt=Dt(()=>{"use strict";J=null}),Mt={};Ot(Mt,{startReplayRecorder:()=>kt,stopReplayRecorder:()=>At});var Nt=Dt(()=>{"use strict";jt()}),Pt=typeof document<`u`?document.currentScript:null;function Ft(e){return e.replace(/([-_][a-z])/gi,e=>e.toUpperCase().replace(`-`,``).replace(`_`,``))}var It=class extends Tt{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=Pt,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(()=>(Nt(),Mt))}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[Ft(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 Lt(e){return Ie(O(e))}let Y=`nexus-wallet-backup`,Rt=`frakwallet://`;function zt(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}function Bt(e){return`intent://${e.slice(13)}#Intent;scheme=frakwallet;end`}function Vt(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=zt()&&Ht(e)?Bt(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function Ht(e){return e.startsWith(Rt)}let X={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function Ut(e){return e&&e in X?e:`eur`}function Wt(e){return e?X[e]??X.eur:X.eur}function Gt(e,t){let n=Wt(t),r=Ut(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function Kt(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 qt({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(),Jt({iframe:r,isVisible:!1});let i=t?.walletUrl??e??`https://wallet.frak.id`,a=E();return Xt(i),Xt(A(i)),r.src=`${i}/listener?clientId=${encodeURIComponent(a)}`,new Promise(e=>{r.addEventListener(`load`,()=>e(r)),document.body.appendChild(r)})}function Jt({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 Yt(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 Xt(e){if(!(typeof document>`u`))try{let t=new URL(e).origin,n=`link[rel="preconnect"][data-frak-preconnect="${t}"]`;if(document.head.querySelector(n))return;let r=document.createElement(`link`);r.rel=`preconnect`,r.href=t,r.crossOrigin=``,r.dataset.frakPreconnect=t,document.head.appendChild(r)}catch{}}function Zt(){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 Qt=Zt();function $t(){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 en=$t();function tn(e){Qt&&e.startsWith(`https://`)?window.location.href=`x-safari-https://${e.slice(8)}`:Qt&&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 nn({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}function rn(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 an=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 w?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`
|
|
2
|
+
`);super(s,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=o}walk(e){return c(this,e)}}})),f,p=t((()=>{d(),f=class extends u{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 m(e,{dir:t,size:n=32}={}){return typeof e==`string`?h(e,{dir:t,size:n}):ee(e,{dir:t,size:n})}function h(e,{dir:t,size:n=32}={}){if(n===null)return e;let r=e.replace(`0x`,``);if(r.length>n*2)throw new f({size:Math.ceil(r.length/2),targetSize:n,type:`hex`});return`0x${r[t===`right`?`padEnd`:`padStart`](n*2,`0`)}`}function ee(e,{dir:t,size:n=32}={}){if(n===null)return e;if(e.length>n)throw new f({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 te=t((()=>{p()})),ne,re,ie=t((()=>{d(),ne=class extends u{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`})}},re=class extends u{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:`SizeOverflowError`})}}}));function g(e,{size:t}){if(i(e)>t)throw new re({givenSize:i(e),maxSize:t})}var ae=t((()=>{ie(),a()}));function oe(e,t={}){return typeof e==`number`||typeof e==`bigint`?ce(e,t):typeof e==`string`?le(e,t):typeof e==`boolean`?se(e,t):_(e,t)}function se(e,t={}){let n=`0x${Number(e)}`;return typeof t.size==`number`?(g(n,{size:t.size}),m(n,{size:t.size})):n}function _(e,t={}){let n=``;for(let t=0;t<e.length;t++)n+=ue[e[t]];let r=`0x${n}`;return typeof t.size==`number`?(g(r,{size:t.size}),m(r,{dir:`right`,size:t.size})):r}function ce(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 ne({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?m(s,{size:r}):s}function le(e,t={}){return _(de.encode(e),t)}var ue,de;function fe(e,t={}){return typeof e==`number`||typeof e==`bigint`?he(e,t):typeof e==`boolean`?pe(e,t):n(e)?v(e,t):ge(e,t)}function pe(e,t={}){let n=new Uint8Array(1);return n[0]=Number(e),typeof t.size==`number`?(g(n,{size:t.size}),m(n,{size:t.size})):n}function me(e){if(e>=y.zero&&e<=y.nine)return e-y.zero;if(e>=y.A&&e<=y.F)return e-(y.A-10);if(e>=y.a&&e<=y.f)return e-(y.a-10)}function v(e,t={}){let n=e;t.size&&(g(n,{size:t.size}),n=m(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=me(r.charCodeAt(t++)),i=me(r.charCodeAt(t++));if(n===void 0||i===void 0)throw new u(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);a[e]=n*16+i}return a}function he(e,t){return v(ce(e,t))}function ge(e,t={}){let n=_e.encode(e);return typeof t.size==`number`?(g(n,{size:t.size}),m(n,{dir:`right`,size:t.size})):n}var _e,y,ve,ye;function be(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function xe(e,...t){if(!be(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 Se(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function Ce(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}var we,Te;function Ee(e,t){let r=t||`hex`,i=Te(n(e,{strict:!1})?fe(e):e);return r===`bytes`?i:oe(i)}var De;function Oe(e,t){if(b.has(`${e}.${t}`))return b.get(`${e}.${t}`);let n=t?`${t}${e.toLowerCase()}`:e.substring(2).toLowerCase(),r=Ee(ge(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 b.set(`${e}.${t}`,a),a}var b;function x(e,t){let{strict:n=!0}=t??{},r=`${e}.${n}`;if(S.has(r))return S.get(r);let i=ke.test(e)?e.toLowerCase()===e?!0:n?Oe(e)===e:!0:!1;return S.set(r,i),i}var ke,S;function Ae(e,t){if(!x(e,{strict:!1}))throw new De({address:e});if(!x(t,{strict:!1}))throw new De({address:t});return e.toLowerCase()===t.toLowerCase()}let C=256,w;function je(e=11){if(!w||C+e>256*2){w=``,C=0;for(let e=0;e<256;e++)w+=(256+Math.random()*256|0).toString(16).substring(1)}return w.substring(C,C+++e)}let Me={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 T=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}}},E=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 Ne(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 ee(e){let t=h(),n=new E;return o.set(t,e=>{e.error?n.reject(new T(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 te(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 ne(){n.removeEventListener(`message`,f),o.clear()}return{request:ee,listen:te,sendLifecycle:m,cleanup:ne}}function Pe(e){return new TextEncoder().encode(JSON.stringify(e))}function Fe(e){try{return JSON.parse(new TextDecoder().decode(e))}catch{return null}}let Ie=`frak-client-id`;function Le(){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 console.warn(`[Frak SDK] No Window / localStorage available to save the clientId`),Le();let e=localStorage.getItem(Ie);return e||(e=Le(),localStorage.setItem(Ie,e)),e}function Re({domain:e}={}){return Ee(oe((e??window.location.host).replace(`www.`,``)))}function O(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function ze(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 Be(e){return O(Pe(e))}function Ve(e,t,n,r,i,a){let o=Be(He({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 He(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 Ue=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,We=`frak-sso`;async function Ge(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??Ve(i??`https://wallet.frak.id`,t,Re(),n.name,D(),r?.css),o=window.open(a,We,Ue);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]})??{}}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)}}let Ke=`https://backend.frak.id`;function qe(e){return e.includes(`localhost:3000`)||e.includes(`localhost:3010`)}function Je(e){return qe(e)?`https://localhost:3030`:e.includes(`wallet-dev.frak.id`)||e.includes(`wallet.gcp-dev.frak.id`)?`https://backend.gcp-dev.frak.id`:Ke}function A(e){if(e)return Je(e);if(typeof window<`u`){let e=window.FrakSetup?.client?.config?.walletUrl;if(e)return Je(e)}return Ke}var j=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 M=new j(1024),N=new j(1024),Ye=3e4,P=new j(1024);async function F(e,{cacheKey:t,cacheTime:n=Ye}){if(n>0){let e=N.get(t);if(e&&Date.now()-e.created<n)return e.data}let r=P.get(t);if(r&&Date.now()-r<1e3)throw Error(`Cache: ${t} recently failed, backing off`);let i=M.get(t);i||(i=e(),M.set(t,i));try{let e=await i;return N.set(t,{data:e,created:Date.now()}),P.delete(t),e}catch(e){throw P.set(t,Date.now()),e}finally{M.delete(t)}}function Xe(e){return{clear:()=>{M.delete(e),N.delete(e)},has:(t=Ye)=>{let n=N.get(e);return n?Date.now()-n.created<t:!1}}}function I(){M.clear(),N.clear(),P.clear()}function L(e){return`r`in e&&!(`v`in e)}function R(e){return`v`in e&&e.v===2}let Ze=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Qe(e){return typeof e==`string`&&Ze.test(e)}function $e(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 et(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 tt(e){if(!Qe(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`&&x(e.w);if(!t&&!n||t&&!Qe(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($e(e.m),a),a+=16,i.setUint32(a,e.t,!1),a+=4,t&&(r.set($e(e.c),a),a+=16),n&&(r.set(v(e.w),a),a+=20),r}function nt(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=et(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=et(e.subarray(a,a+16)),a+=16),r){let t=_(e.subarray(a,a+20),{size:20});if(!x(t))return null;c.w=t,a+=20}return c}let rt=`fCtx`;function it(e){if(e)try{if(R(e)){let t=tt(e);return t?O(t):void 0}return O(v(e.r))}catch(t){console.error(`Error compressing Frak context`,{e:t,context:e})}}function at(e){if(!(!e||e.length===0))try{let t=ze(e);if(t.length!==20)return nt(t)||void 0;let n=_(t,{size:20});if(x(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(rt);return t?at(t):null}let st=`frak`;function ct(e,t){let n=R(e);return{utm_source:t.utmSource??st,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??st,ref:t.ref??(n?e.c:void 0)}}function lt(e,t,n){let r=ct(t,n??{});for(let[t,n]of Object.entries(r))n===void 0||n===``||e.searchParams.has(t)||e.searchParams.set(t,n)}function ut({url:e,context:t,attribution:n}){if(!e)return null;let r=it(t);if(!r)return null;let i=new URL(e);return i.searchParams.set(rt,r),lt(i,t,n),i.toString()}function dt(e){let t=new URL(e);return t.searchParams.delete(rt),t.toString()}function ft({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?dt(n):ut({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}let pt={compress:it,decompress:at,parse:ot,update:ut,remove:dt,replaceUrl:ft},z=`__frakSdkConfig`,mt=`frak-config-cache`,B=`frak-merchant-id`,V={key:mt},H=typeof window<`u`;function U(){return{isResolved:!1,merchantId:``}}let W=null;function ht(){if(!H)return null;try{let e=localStorage.getItem(V.key);if(!e)return null;let t=JSON.parse(e);return t.config?.isResolved?(W=t,t):null}catch{return null}}function gt(){return(W??ht())?.config}function _t(){let e=W??ht();return e?Date.now()-e.timestamp<3e4:!1}function vt(e){if(!(!H||!e.isResolved))try{let t={config:e,timestamp:Date.now()};localStorage.setItem(V.key,JSON.stringify(t)),W=t}catch{}}function yt(){if(H){W=null;try{localStorage.removeItem(V.key)}catch{}}}function bt(){H&&(window[z]||(window[z]=gt()??U()))}bt();function xt(){return H?window[z]??U():U()}function St(e){H&&window.dispatchEvent(new CustomEvent(`frak:config`,{detail:e}))}function Ct(e){return e??(H?window.location.hostname:``)}async function wt(e,t,n){try{let r=A(t),i=n?`&lang=${encodeURIComponent(n)}`:``,a=await fetch(`${r}/user/merchant/resolve?domain=${encodeURIComponent(e)}${i}`);if(!a.ok){console.warn(`[Frak SDK] Merchant lookup failed for domain ${e}: ${a.status}`);return}let o=await a.json();if(H)try{sessionStorage.setItem(B,o.merchantId)}catch{}return o}catch(e){console.warn(`[Frak SDK] Failed to fetch merchant config:`,e);return}}let G={getConfig:xt,get isResolved(){return xt().isResolved},get isCacheFresh(){return _t()},setCacheScope(e,t){V.key=`${mt}:${`${e}:${t??``}`}`,W=null},setConfig(e){if(H&&(window[z]=e),vt(e),St(e),H&&e.merchantId)try{sessionStorage.setItem(B,e.merchantId)}catch{}},reset(){let e=gt()??U();H&&(window[z]=e),St(e)},clearCache(){if(yt(),I(),H)try{sessionStorage.removeItem(B)}catch{}},resolve(e,t,n){let r=Ct(e);return r?F(async()=>{let e=await wt(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=xt();if(e.isResolved&&e.merchantId)return e.merchantId;if(H)try{return sessionStorage.getItem(B)??void 0}catch{}},async resolveMerchantId(e,t){return G.getMerchantId()||(await G.resolve(e,t))?.merchantId}};function Tt(){return()=>{}}var Et=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)}},Dt=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 Et({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)}},Ot=Object.defineProperty,kt=(e,t)=>()=>(e&&(t=e(e=0)),t),At=(e,t)=>{for(var n in t)Ot(e,n,{get:t[n],enumerable:!0})};function jt(e,t){if(typeof document>`u`||typeof window>`u`)return;K&&K();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=Tt({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),K=()=>{a.length>0&&c(a.some(e=>e.type===2)),s&&=(clearInterval(s),null),document.removeEventListener(`visibilitychange`,p),window.removeEventListener(`pagehide`,m),f?.(),K=null}}function Mt(){K&&K()}var K,Nt=kt(()=>{"use strict";K=null}),Pt={};At(Pt,{startReplayRecorder:()=>jt,stopReplayRecorder:()=>Mt});var Ft=kt(()=>{"use strict";Nt()}),It=typeof document<`u`?document.currentScript:null;function Lt(e){return e.replace(/([-_][a-z])/gi,e=>e.toUpperCase().replace(`-`,``).replace(`_`,``))}var Rt=class extends Dt{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=It,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(()=>(Ft(),Pt))}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[Lt(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 zt(e){return Fe(ze(e))}let q=`nexus-wallet-backup`,Bt=`frakwallet://`;function Vt(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}let Ht=Bt.replace(`://`,``);function Ut(e){return`intent://${e.slice(13)}#Intent;scheme=${Ht};end`}function Wt(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=Vt()&&Gt(e)?Ut(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function Gt(e){return e.startsWith(Bt)}let J={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function Kt(e){return e&&e in J?e:`eur`}function qt(e){return e?J[e]??J.eur:J.eur}function Jt(e,t){let n=qt(t),r=Kt(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function Yt(e){return e?`${e}Amount`:`eurAmount`}let Y={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 Xt({walletBaseUrl:e,config:t}){let n=document.querySelector(`#frak-wallet`);n&&n.remove();let r=document.createElement(`iframe`);r.id=Y.id,r.name=Y.name,r.allow=Y.allow,r.style.zIndex=Y.style.zIndex.toString(),Zt({iframe:r,isVisible:!1});let i=t?.walletUrl??e??`https://wallet.frak.id`,a=D();return $t(i),$t(A(i)),r.src=`${i}/listener?clientId=${encodeURIComponent(a)}`,new Promise(e=>{r.addEventListener(`load`,()=>e(r)),document.body.appendChild(r)})}function Zt({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 Qt(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 $t(e){if(!(typeof document>`u`))try{let t=new URL(e).origin,n=`link[rel="preconnect"][data-frak-preconnect="${t}"]`;if(document.head.querySelector(n))return;let r=document.createElement(`link`);r.rel=`preconnect`,r.href=t,r.crossOrigin=``,r.dataset.frakPreconnect=t,document.head.appendChild(r)}catch{}}function en(){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 tn=en();function nn(){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 rn=nn();function an(e){tn&&e.startsWith(`https://`)?window.location.href=`x-safari-https://${e.slice(8)}`:tn&&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 on({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}function sn(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 cn=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 T?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 NexusSDK=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Mod
|
|
|
11
11
|
Last Response: ${t.lastResponse}
|
|
12
12
|
Client Status: ${t.clientStatus}
|
|
13
13
|
Error: ${t.error}
|
|
14
|
-
`.trim()}};let on=(()=>{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 sn(e){e?localStorage.setItem(Y,e):localStorage.removeItem(Y)}function cn(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=dn(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function ln(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 un(e){return e.includes(`/common/social`)}function dn(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 fn(e,t,n,r,i){if(i){let e=cn(t,r);window.open(e,`_blank`);return}if(Ht(t)){let i=cn(t,r);Vt(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(on&&un(t))ln(r);else{let e=cn(t,r);window.location.href=e}}function pn({iframe:e,targetOrigin:t}){let n=new T;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`:sn(a.backup);break;case`remove-backup`:localStorage.removeItem(Y);break;case`show`:case`hide`:Jt({iframe:e,isVisible:i===`show`});break;case`redirect`:fn(e,a.baseRedirectUrl,t,a.mergeToken,a.openInNewTab);break}},isConnected:n.promise}}function mn({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:``);q.setCacheScope(a,i),q.reset();let o=q.isCacheFresh?void 0:q.resolve(e.domain,e.walletUrl,i),s=pn({iframe:t,targetOrigin:n}),c=new T,l=Date.now(),u=new an(e,t);if(!t.contentWindow)throw new w(Ne.configError,`The iframe does not have a content window`);let d=Pe({emittingTransport:t.contentWindow,listeningTransport:window,targetOrigin:n,middleware:[{async onRequest(e,t){if(!await s.isConnected)throw new w(Ne.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)}}}),f=hn(d,s),p=async()=>{f(),d.cleanup(),t.remove(),F(),q.clearCache(),q.reset()},m;{console.log(`[Frak SDK] Initializing OpenPanel`),m=new It({apiUrl:`https://op-api.gcp.frak.id`,clientId:`6eacc8d7-49ac-4936-95e9-81ef29449570`,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.2`,userAnonymousClientId:E()}),!0)}),m.setGlobalProperties({sdkVersion:`1.0.2`,userAnonymousClientId:E()}),m.init(),m.track(`sdk_initialized`,{sdkVersion:`1.0.2`});let e=!1,t=setTimeout(()=>{e||(e=!0,m?.track(`sdk_iframe_handshake_failed`,{reason:`timeout`}))},3e4);s.isConnected.then(()=>{e||(e=!0,clearTimeout(t),m?.track(`sdk_iframe_connected`,{handshake_duration_ms:Date.now()-l}))}).catch(()=>{e||(e=!0,clearTimeout(t),m?.track(`sdk_iframe_handshake_failed`,{reason:`unknown`}))})}let h=gn({config:e,rpcClient:d,lifecycleManager:s,configPromise:o,contextSent:c,openPanel:m}).then(()=>u.updateSetupStatus(!0)).catch(e=>{throw c.reject(e),e});return{config:e,debugInfo:u,waitForConnection:s.isConnected,waitForSetup:h,request:d.request,listenerRequest:d.listen,destroy:p,openPanel:m}}function hn(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,250),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 gn({config:e,rpcClient:t,lifecycleManager:n,configPromise:r,contextSent:i,openPanel:a}){await n.isConnected,rn(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;q.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=E();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}}})};q.isResolved&&(u(q.getConfig()),i.resolve()),r&&(c(await r),u(q.getConfig()),i.resolve());async function d(){let n=e.customizations?.css;n&&t.sendLifecycle({clientLifecycle:`modal-css`,data:{cssLink:n}})}async function f(){let n=e.customizations?.i18n;n&&t.sendLifecycle({clientLifecycle:`modal-i18n`,data:{i18n:n}})}async function p(){if(typeof window>`u`)return;let e=window.localStorage.getItem(Y);e&&t.sendLifecycle({clientLifecycle:`restore-backup`,data:{backup:e}})}(await Promise.allSettled([d(),f(),p()])).some(e=>e.status===`rejected`)&&a?.track(`sdk_iframe_handshake_failed`,{reason:`asset_push`})}async function _n({config:e}){let t=vn(e),n=await qt({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=mn({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function vn(e){let t=Ut(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}async function yn(e,t,n=`text/javascript`){return document.getElementById(e)?Promise.resolve(!0):new Promise((r,i)=>{let a=document.createElement(`script`);a.id=e,a.src=t,a.defer=!0,a.type=n,a.onload=()=>r(!0),a.onerror=()=>i(Error(`Script load error for ${t}`)),document.head.appendChild(a)})}function bn(){xn(),Sn()}function xn(){window.FrakSetup.config={walletUrl:`https://wallet.frak.id`,metadata:{name:`Gapianne`,lang:`fr`,currency:`eur`,logoUrl:`https://gapianne.com/cdn/shop/files/logo-gapianne_7a65f4c4-54e8-4831-afa2-0849e4c5f8de.png`,homepageLink:`https://gapianne.com/`},customizations:{i18n:{"sharing.title":`Prêt(e) à révéler un secret bien-être ?`,"sharing.text":`Découvre ce produit chez Gapianne`,"sdk.wallet.login.text":`Créez votre porte-monnaie avec **{{ productName }}** et recevez **{{ estimatedReward }}** par ami(e) parrainé(e)`}},domain:window.location.host},window.FrakSetup.modalWalletConfig={metadata:{position:`left`}}}function Sn(){let e=document.querySelectorAll(`#nexus-share-button > button`);for(let t of Array.from(e)){let e=document.createElement(`frak-button-share`);e.setAttribute(`text`,`PARTAGE ET GAGNE {REWARD} !`),e.setAttribute(`no-reward-text`,`PARTAGE ET GAGNE`),e.setAttribute(`use-reward`,`true`),e.setAttribute(`classname`,`button w-full`),t.replaceWith(e)}}let Cn={"gapianne.com":bn};function wn(){let e=Cn[window.location.host];e&&(e(),yn(`frak-components`,`https://cdn.jsdelivr.net/npm/@frak-labs/components@beta/cdn/components.js`,`module`))}function Tn(e){document.readyState===`complete`||document.readyState===`interactive`?setTimeout(e,1):document.addEventListener(`DOMContentLoaded`,e)}function En(){return Me(96)}async function Dn(e,t,n){return await e.request({method:`frak_displayEmbeddedWallet`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function Q(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 On(e,t,n){return await e.request({method:`frak_displaySharingPage`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function kn(e){if(typeof window>`u`)return;let t=E();if(!t)return;let n=await q.resolveMerchantId();if(!n)return;let r=`frak-identity-ensured-${n}`;if(!window.sessionStorage.getItem(r))try{let i=A();(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 An(e,t){return P(()=>e.request({method:`frak_getMerchantInformation`}),{cacheKey:`frak_getMerchantInformation`,cacheTime:t?.cacheTime})}async function jn(e,t){return P(()=>e.request({method:`frak_getMergeToken`}),{cacheKey:`frak_getMergeToken`,cacheTime:t?.cacheTime})}async function Mn(e,t){return P(()=>e.request({method:`frak_getUserReferralStatus`}),{cacheKey:`frak_getUserReferralStatus`,cacheTime:t?.cacheTime})}async function Nn(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function Pn(e,t){try{await e.request({method:`frak_sendInteraction`,params:[t,{clientId:E()}]})}catch{console.warn(`[Frak SDK] Failed to send interaction:`,t.type)}}function Fn(e,t,n){return L(t)?(k(e,`user_referred_started`,{referrerClientId:t.c,referrerWallet:t.w,walletStatus:n?.key}),Pn(e,{type:`arrival`,referrerClientId:t.c,referrerMerchantId:t.m,referrerWallet:t.w,referralTimestamp:t.t}),!0):I(t)?(k(e,`user_referred_started`,{referrer:t.r,walletStatus:n?.key}),Pn(e,{type:`arrival`,referrerWallet:t.r}),!0):!1}function In(e,t){let n=E();return!n&&!t?null:{v:2,m:e,t:Math.floor(Date.now()/1e3),...n?{c:n}:{},...t?{w:t}:{}}}function Ln(e,t){return L(e)?e.w&&t?.wallet?je(e.w,t.wallet):e.c?E()===e.c:!1:I(e)&&t?.wallet?je(e.r,t.wallet):!1}function Rn(e,{walletStatus:t,frakContext:n,options:r}){if(!n)return`no-referrer`;if(Ln(n,t))return`self-referral`;if(!Fn(e,n,t))return`no-referrer`;let i=L(n)?n.m:r?.merchantId,a=r?.alwaysAppendUrl&&i?In(i,t?.wallet):null;return z.replaceUrl({url:window.location?.href,context:a}),k(e,`user_referred_completed`,{status:`success`}),`success`}async function zn(e,{options:t}={}){let n=z.parse({url:window.location.href}),r=await Un(e);try{return Rn(e,{walletStatus:r,frakContext:n,options:t})}catch(e){console.warn(`Error processing referral`,{error:e})}}let Bn=`frak:referral-success`;async function Vn(e){try{await zn(e)===`success`&&window.dispatchEvent(new Event(Bn))}catch(e){console.warn(`[Frak] Referral setup failed`,e)}}async function Hn(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=E();if(!t&&!n){console.warn(`[Frak] No identity found, skipping purchase check`);return}let r=e.merchantId??await q.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=A();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 Un(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(Wn(e,t),t));let n=new T,r=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},i=>{Wn(e,i),t(i),r||=(n.resolve(i),!0)}),n.promise}function Wn(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?(window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken),kn(t.interactionToken)):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function Gn(e,{metadata:t,login:n}){return $(e,{steps:{login:n??{}},metadata:t})}function $(e,t){function n(n){return $(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return $(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return $(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function a(n,r){return n&&(t.metadata=n(t.metadata??{})),await Q(e,t,r)}return{params:t,sendTx:n,reward:r,sharing:i,display:a}}async function Kn(e,{tx:t,metadata:n}){return(await Q(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}async function qn(e,{siwe:t,metadata:n}){let r=e.config?.domain??window.location.host,i=t?.statement??`I confirm that I want to use my Frak wallet on: ${e.config.metadata.name}`;return(await Q(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:i,nonce:t?.nonce??En(),uri:t?.uri??`https://${r}`,version:t?.version??`1`,domain:r}}}})).siweAuthenticate}let Jn=mn;return Tn(wn),e.DEEP_LINK_SCHEME=Rt,e.DebugInfoGatherer=an,e.FrakContextManager=z,e.REFERRAL_SUCCESS_EVENT=Bn,e.base64urlDecode=O,e.base64urlEncode=D,e.baseIframeProps=Z,e.clearAllCache=F,e.compressJsonToB64=Be,e.computeLegacyProductId=ze,e.createIFrameFrakClient=mn,e.createIFrameNexusClient=Jn,e.createIframe=qt,e.decompressJsonFromB64=Lt,e.displayEmbeddedWallet=Dn,e.displayModal=Q,e.displaySharingPage=On,e.ensureIdentity=kn,e.findIframeInOpener=Yt,e.formatAmount=Gt,e.generateSsoUrl=Ve,e.getBackendUrl=A,e.getCache=Ze,e.getClientId=E,e.getCurrencyAmountKey=Kt,e.getMerchantInformation=An,e.getMergeToken=jn,e.getSupportedCurrency=Ut,e.getSupportedLocale=Wt,e.getUserReferralStatus=Mn,e.isChromiumAndroid=zt,e.isFrakDeepLink=Ht,e.isIOS=Qt,e.isInAppBrowser=en,e.isV1Context=I,e.isV2Context=L,e.locales=X,e.mergeAttribution=nn,e.modalBuilder=Gn,e.openSso=Ge,e.prepareSso=Nn,e.processReferral=Rn,e.redirectToExternalBrowser=tn,e.referralInteraction=zn,e.sdkConfigStore=q,e.sendInteraction=Pn,e.sendTransaction=Kn,e.setupClient=_n,e.setupReferral=Vn,e.siweAuthenticate=qn,e.ssoPopupFeatures=Ue,e.ssoPopupName=We,e.toAndroidIntentUrl=Bt,e.trackEvent=k,e.trackPurchaseStatus=Hn,e.triggerDeepLinkWithFallback=Vt,e.watchWalletStatus=Un,e.withCache=P,e})({});
|
|
14
|
+
`.trim()}};let ln=(()=>{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 un(e){e?localStorage.setItem(q,e):localStorage.removeItem(q)}function dn(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 fn(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 pn(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 hn(e,t,n,r,i){if(i){let e=dn(t,r);window.open(e,`_blank`);return}if(Gt(t)){let i=dn(t,r);Wt(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(ln&&pn(t))fn(r);else{let e=dn(t,r);window.location.href=e}}function gn({iframe:e,targetOrigin:t}){let n=new E;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`:un(a.backup);break;case`remove-backup`:localStorage.removeItem(q);break;case`show`:case`hide`:Zt({iframe:e,isVisible:i===`show`});break;case`redirect`:hn(e,a.baseRedirectUrl,t,a.mergeToken,a.openInNewTab);break}},isConnected:n.promise}}function X({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:``);G.setCacheScope(a,i),G.reset();let o=G.isCacheFresh?void 0:G.resolve(e.domain,e.walletUrl,i),s=gn({iframe:t,targetOrigin:n}),c=new E,l=Date.now(),u=new cn(e,t);if(!t.contentWindow)throw new T(Me.configError,`The iframe does not have a content window`);let d=Ne({emittingTransport:t.contentWindow,listeningTransport:window,targetOrigin:n,middleware:[{async onRequest(e,t){if(!await s.isConnected)throw new T(Me.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)}}}),f=_n(d,s),p=async()=>{f(),d.cleanup(),t.remove(),I(),G.clearCache(),G.reset()},m;{console.log(`[Frak SDK] Initializing OpenPanel`),m=new Rt({apiUrl:`https://op-api.gcp.frak.id`,clientId:`6eacc8d7-49ac-4936-95e9-81ef29449570`,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.2`,userAnonymousClientId:D()}),!0)}),m.setGlobalProperties({sdkVersion:`1.0.2`,userAnonymousClientId:D()}),m.init(),m.track(`sdk_initialized`,{sdkVersion:`1.0.2`});let e=!1,t=setTimeout(()=>{e||(e=!0,m?.track(`sdk_iframe_handshake_failed`,{reason:`timeout`}))},3e4);s.isConnected.then(()=>{e||(e=!0,clearTimeout(t),m?.track(`sdk_iframe_connected`,{handshake_duration_ms:Date.now()-l}))}).catch(()=>{e||(e=!0,clearTimeout(t),m?.track(`sdk_iframe_handshake_failed`,{reason:`unknown`}))})}let h=vn({config:e,rpcClient:d,lifecycleManager:s,configPromise:o,contextSent:c,openPanel:m}).then(()=>u.updateSetupStatus(!0)).catch(e=>{throw c.reject(e),e});return{config:e,debugInfo:u,waitForConnection:s.isConnected,waitForSetup:h,request:d.request,listenerRequest:d.listen,destroy:p,openPanel:m}}function _n(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,250),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 vn({config:e,rpcClient:t,lifecycleManager:n,configPromise:r,contextSent:i,openPanel:a}){await n.isConnected,sn(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;G.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}}})};G.isResolved&&(u(G.getConfig()),i.resolve()),r&&(c(await r),u(G.getConfig()),i.resolve());async function d(){let n=e.customizations?.css;n&&t.sendLifecycle({clientLifecycle:`modal-css`,data:{cssLink:n}})}async function f(){let n=e.customizations?.i18n;n&&t.sendLifecycle({clientLifecycle:`modal-i18n`,data:{i18n:n}})}async function p(){if(typeof window>`u`)return;let e=window.localStorage.getItem(q);e&&t.sendLifecycle({clientLifecycle:`restore-backup`,data:{backup:e}})}(await Promise.allSettled([d(),f(),p()])).some(e=>e.status===`rejected`)&&a?.track(`sdk_iframe_handshake_failed`,{reason:`asset_push`})}async function yn({config:e}){let t=bn(e),n=await Xt({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=X({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function bn(e){let t=Kt(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}async function xn(e,t,n=`text/javascript`){return document.getElementById(e)?Promise.resolve(!0):new Promise((r,i)=>{let a=document.createElement(`script`);a.id=e,a.src=t,a.defer=!0,a.type=n,a.onload=()=>r(!0),a.onerror=()=>i(Error(`Script load error for ${t}`)),document.head.appendChild(a)})}function Sn(){Cn(),wn()}function Cn(){window.FrakSetup.config={walletUrl:`https://wallet.frak.id`,metadata:{name:`Gapianne`,lang:`fr`,currency:`eur`,logoUrl:`https://gapianne.com/cdn/shop/files/logo-gapianne_7a65f4c4-54e8-4831-afa2-0849e4c5f8de.png`,homepageLink:`https://gapianne.com/`},customizations:{i18n:{"sharing.title":`Prêt(e) à révéler un secret bien-être ?`,"sharing.text":`Découvre ce produit chez Gapianne`,"sdk.wallet.login.text":`Créez votre porte-monnaie avec **{{ productName }}** et recevez **{{ estimatedReward }}** par ami(e) parrainé(e)`}},domain:window.location.host},window.FrakSetup.modalWalletConfig={metadata:{position:`left`}}}function wn(){let e=document.querySelectorAll(`#nexus-share-button > button`);for(let t of Array.from(e)){let e=document.createElement(`frak-button-share`);e.setAttribute(`text`,`PARTAGE ET GAGNE {REWARD} !`),e.setAttribute(`no-reward-text`,`PARTAGE ET GAGNE`),e.setAttribute(`use-reward`,`true`),e.setAttribute(`classname`,`button w-full`),t.replaceWith(e)}}let Tn={"gapianne.com":Sn};function En(){let e=Tn[window.location.host];e&&(e(),xn(`frak-components`,`https://cdn.jsdelivr.net/npm/@frak-labs/components@beta/cdn/components.js`,`module`))}function Dn(e){document.readyState===`complete`||document.readyState===`interactive`?setTimeout(e,1):document.addEventListener(`DOMContentLoaded`,e)}function On(){return je(96)}async function kn(e,t,n){return await e.request({method:`frak_displayEmbeddedWallet`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function Z(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 An(e,t,n){return await e.request({method:`frak_displaySharingPage`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function jn(e){if(typeof window>`u`)return;let t=D();if(!t)return;let n=await G.resolveMerchantId();if(!n)return;let r=`frak-identity-ensured-${n}`;if(!window.sessionStorage.getItem(r))try{let i=A();(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 Mn(e,t){return F(()=>e.request({method:`frak_getMerchantInformation`}),{cacheKey:`frak_getMerchantInformation`,cacheTime:t?.cacheTime})}async function Nn(e,t){return F(()=>e.request({method:`frak_getMergeToken`}),{cacheKey:`frak_getMergeToken`,cacheTime:t?.cacheTime})}async function Pn(e,t){return F(()=>e.request({method:`frak_getUserReferralStatus`}),{cacheKey:`frak_getUserReferralStatus`,cacheTime:t?.cacheTime})}async function Fn(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function Q(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 In(e,t,n){return R(t)?(k(e,`user_referred_started`,{referrerClientId:t.c,referrerWallet:t.w,walletStatus:n?.key}),Q(e,{type:`arrival`,referrerClientId:t.c,referrerMerchantId:t.m,referrerWallet:t.w,referralTimestamp:t.t}),!0):L(t)?(k(e,`user_referred_started`,{referrer:t.r,walletStatus:n?.key}),Q(e,{type:`arrival`,referrerWallet:t.r}),!0):!1}function Ln(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 Rn(e,t){return R(e)?e.w&&t?.wallet?Ae(e.w,t.wallet):e.c?D()===e.c:!1:L(e)&&t?.wallet?Ae(e.r,t.wallet):!1}function zn(e,{walletStatus:t,frakContext:n,options:r}){if(!n)return`no-referrer`;if(Rn(n,t))return`self-referral`;if(!In(e,n,t))return`no-referrer`;let i=R(n)?n.m:r?.merchantId,a=r?.alwaysAppendUrl&&i?Ln(i,t?.wallet):null;return pt.replaceUrl({url:window.location?.href,context:a}),k(e,`user_referred_completed`,{status:`success`}),`success`}async function Bn(e,{options:t}={}){let n=pt.parse({url:window.location.href}),r=await Wn(e);try{return zn(e,{walletStatus:r,frakContext:n,options:t})}catch(e){console.warn(`Error processing referral`,{error:e})}}let Vn=`frak:referral-success`;async function Hn(e){try{await Bn(e)===`success`&&window.dispatchEvent(new Event(Vn))}catch(e){console.warn(`[Frak] Referral setup failed`,e)}}async function Un(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 G.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=A();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 Wn(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(Gn(e,t),t));let n=new E,r=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},i=>{Gn(e,i),t(i),r||=(n.resolve(i),!0)}),n.promise}function Gn(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?(window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken),jn(t.interactionToken)):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function Kn(e,{metadata:t,login:n}){return $(e,{steps:{login:n??{}},metadata:t})}function $(e,t){function n(n){return $(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return $(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return $(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function a(n,r){return n&&(t.metadata=n(t.metadata??{})),await Z(e,t,r)}return{params:t,sendTx:n,reward:r,sharing:i,display:a}}async function qn(e,{tx:t,metadata:n}){return(await Z(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}async function Jn(e,{siwe:t,metadata:n}){let r=e.config?.domain??window.location.host,i=t?.statement??`I confirm that I want to use my Frak wallet on: ${e.config.metadata.name}`;return(await Z(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:i,nonce:t?.nonce??On(),uri:t?.uri??`https://${r}`,version:t?.version??`1`,domain:r}}}})).siweAuthenticate}let Yn=X;return Dn(En),e.DEEP_LINK_SCHEME=Bt,e.DebugInfoGatherer=cn,e.FrakContextManager=pt,e.REFERRAL_SUCCESS_EVENT=Vn,e.base64urlDecode=ze,e.base64urlEncode=O,e.baseIframeProps=Y,e.clearAllCache=I,e.compressJsonToB64=Be,e.computeLegacyProductId=Re,e.createIFrameFrakClient=X,e.createIFrameNexusClient=Yn,e.createIframe=Xt,e.decompressJsonFromB64=zt,e.displayEmbeddedWallet=kn,e.displayModal=Z,e.displaySharingPage=An,e.ensureIdentity=jn,e.findIframeInOpener=Qt,e.formatAmount=Jt,e.generateSsoUrl=Ve,e.getBackendUrl=A,e.getCache=Xe,e.getClientId=D,e.getCurrencyAmountKey=Yt,e.getMerchantInformation=Mn,e.getMergeToken=Nn,e.getSupportedCurrency=Kt,e.getSupportedLocale=qt,e.getUserReferralStatus=Pn,e.isChromiumAndroid=Vt,e.isFrakDeepLink=Gt,e.isIOS=tn,e.isInAppBrowser=rn,e.isV1Context=L,e.isV2Context=R,e.locales=J,e.mergeAttribution=on,e.modalBuilder=Kn,e.openSso=Ge,e.prepareSso=Fn,e.processReferral=zn,e.redirectToExternalBrowser=an,e.referralInteraction=Bn,e.sdkConfigStore=G,e.sendInteraction=Q,e.sendTransaction=qn,e.setupClient=yn,e.setupReferral=Hn,e.siweAuthenticate=Jn,e.ssoPopupFeatures=Ue,e.ssoPopupName=We,e.toAndroidIntentUrl=Ut,e.trackEvent=k,e.trackPurchaseStatus=Un,e.triggerDeepLinkWithFallback=Wt,e.watchWalletStatus=Wn,e.withCache=F,e})({});
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "https://twitter.com/QNivelais"
|
|
12
12
|
}
|
|
13
13
|
],
|
|
14
|
-
"version": "0.0.47-beta.
|
|
14
|
+
"version": "0.0.47-beta.7dfd3480",
|
|
15
15
|
"description": "Legacy SDK, only used here to provide nice wrapper and redirection for older implementation, to not break anything and keep them updated with latest security updates.",
|
|
16
16
|
"repository": {
|
|
17
17
|
"url": "https://github.com/frak-id/wallet",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"publish": "echo 'Publishing legacy...'"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@frak-labs/core-sdk": "1.0.2-beta.
|
|
51
|
+
"@frak-labs/core-sdk": "1.0.2-beta.7dfd3480"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@frak-labs/dev-tooling": "0.0.0",
|