@frak-labs/core-sdk 1.1.3-beta.20a3d2fa → 1.1.4

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.
Files changed (41) hide show
  1. package/cdn/bundle.js +1 -1
  2. package/dist/actions-D5GbNcvt.cjs +1 -0
  3. package/dist/actions-DE2dHqtp.js +1 -0
  4. package/dist/actions.cjs +1 -1
  5. package/dist/actions.d.cts +1 -1
  6. package/dist/actions.d.ts +1 -1
  7. package/dist/actions.js +1 -1
  8. package/dist/bundle.cjs +1 -1
  9. package/dist/bundle.d.cts +2 -2
  10. package/dist/bundle.d.ts +2 -2
  11. package/dist/bundle.js +1 -1
  12. package/dist/frakContext-Bl17GGa3.cjs +1 -0
  13. package/dist/frakContext-DmI5CaSw.js +1 -0
  14. package/dist/{index-B5_aKV0q.d.ts → index-Cm1PNC9z.d.ts} +40 -5
  15. package/dist/{index-C135c5Ul.d.cts → index-Cumn_FNI.d.cts} +40 -5
  16. package/dist/index.cjs +1 -1
  17. package/dist/index.d.cts +2 -2
  18. package/dist/index.d.ts +2 -2
  19. package/dist/index.js +1 -1
  20. package/dist/src-5vpUuhfY.js +1 -0
  21. package/dist/src-BQsjMpvA.cjs +1 -0
  22. package/package.json +2 -4
  23. package/src/actions/referral/processReferral.test.ts +4 -4
  24. package/src/actions/referral/processReferral.ts +4 -4
  25. package/src/clients/createIFrameFrakClient.ts +7 -7
  26. package/src/context/frakContext.test.ts +55 -0
  27. package/src/context/frakContext.ts +13 -2
  28. package/src/index.ts +2 -0
  29. package/src/utils/analytics/events/lifecycle.ts +1 -1
  30. package/src/utils/analytics/events/referral.ts +3 -3
  31. package/src/utils/iframe/iframeHelper.test.ts +0 -39
  32. package/src/utils/iframe/iframeHelper.ts +2 -31
  33. package/src/utils/index.ts +5 -0
  34. package/src/utils/url/queryParams.test.ts +85 -0
  35. package/src/utils/url/queryParams.ts +57 -0
  36. package/dist/actions-BZhtIRpB.cjs +0 -1
  37. package/dist/actions-D5Lt3pG1.js +0 -1
  38. package/dist/frakContext-Cfp7sSid.cjs +0 -1
  39. package/dist/frakContext-UEOk9Bk4.js +0 -1
  40. package/dist/src-CB7gkP3D.js +0 -1
  41. package/dist/src-CxIEmNS7.cjs +0 -1
@@ -1 +0,0 @@
1
- import{_ as e,a as t,g as n,i as r,m as i,n as a,p as o,r as s,t as c}from"./frakContext-UEOk9Bk4.js";import{Deferred as l}from"@frak-labs/frame-connector";async function u(e,t,n){return await e.request({method:`frak_displayEmbeddedWallet`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function d(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 f(e,t,n){return await e.request({method:`frak_displaySharingPage`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function p(t){if(typeof window>`u`)return;let n=e();if(!n)return;let r=await o.resolveMerchantId();if(!r)return;let a=`frak-identity-ensured-${r}`;if(!window.sessionStorage.getItem(a))try{let e=i();(await fetch(`${e}/user/identity/ensure`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`,"x-wallet-sdk-auth":t,"x-frak-client-id":n},body:JSON.stringify({merchantId:r})})).ok&&window.sessionStorage.setItem(a,`1`)}catch{}}async function m(e,t){return n(()=>e.request({method:`frak_getMerchantInformation`}),{cacheKey:`frak_getMerchantInformation`,cacheTime:t?.cacheTime})}async function h(e,t){return n(()=>e.request({method:`frak_getMergeToken`}),{cacheKey:`frak_getMergeToken`,cacheTime:t?.cacheTime})}async function g(e,t){return n(()=>e.request({method:`frak_getUserReferralStatus`}),{cacheKey:`frak_getUserReferralStatus`,cacheTime:t?.cacheTime})}async function _(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function v(t,n){try{await t.request({method:`frak_sendInteraction`,params:[n,{clientId:e()}]})}catch{console.warn(`[Frak SDK] Failed to send interaction:`,n.type)}}function y(e,n,r){return s(n)?(t(e,`user_referred_started`,{referrer_client_id:n.c,referrer_wallet:n.w,wallet_status:r?.key}),v(e,{type:`arrival`,referrerClientId:n.c,referrerMerchantId:n.m,referrerWallet:n.w,referralTimestamp:n.t}),!0):a(n)?(t(e,`user_referred_started`,{referrer:n.r,wallet_status:r?.key}),v(e,{type:`arrival`,referrerWallet:n.r}),!0):!1}function b(t,n){let r=e();return!r&&!n?null:{v:2,m:t,t:Math.floor(Date.now()/1e3),...r?{c:r}:{},...n?{w:n}:{}}}function x(t,n){return s(t)?t.w&&n?.wallet?r(t.w,n.wallet):t.c?e()===t.c:!1:a(t)&&n?.wallet?r(t.r,n.wallet):!1}function S(e,{walletStatus:n,frakContext:r,options:i}){if(!r)return`no-referrer`;if(x(r,n))return`self-referral`;if(!y(e,r,n))return`no-referrer`;let a=s(r)?r.m:i?.merchantId,o=i?.alwaysAppendUrl&&a?b(a,n?.wallet):null;return c.replaceUrl({url:window.location?.href,context:o}),t(e,`user_referred_completed`,{status:`success`}),`success`}async function C(e,{options:t}={}){let n=c.parse({url:window.location.href}),r=await D(e);try{return S(e,{walletStatus:r,frakContext:n,options:t})}catch(e){console.warn(`Error processing referral`,{error:e})}}const w=`frak:referral-success`;async function T(e){try{await C(e)===`success`&&window.dispatchEvent(new Event(w))}catch(e){console.warn(`[Frak] Referral setup failed`,e)}}async function E(t){if(typeof window>`u`){console.warn(`[Frak] No window found, can't track purchase`);return}let n=window.sessionStorage.getItem(`frak-wallet-interaction-token`),r=e();if(!n&&!r){console.warn(`[Frak] No identity found, skipping purchase check`);return}let a=t.merchantId??await o.resolveMerchantId();if(!a){console.warn(`[Frak] No merchant id found, skipping purchase check`);return}let s={Accept:`application/json`,"Content-Type":`application/json`};n&&(s[`x-wallet-sdk-auth`]=n),r&&(s[`x-frak-client-id`]=r);let c=i();await fetch(`${c}/user/track/purchase`,{method:`POST`,headers:s,body:JSON.stringify({customerId:t.customerId,orderId:t.orderId,token:t.token,merchantId:a})})}function D(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(O(e,t),t));let n=new l,r=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},i=>{O(e,i),t(i),r||=(n.resolve(i),!0)}),n.promise}function O(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?(window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken),p(t.interactionToken)):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function k(e,{metadata:t,login:n}){return A(e,{steps:{login:n??{}},metadata:t})}function A(e,t){function n(n){return A(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return A(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return A(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 d(e,t,r)}return{params:t,sendTx:n,reward:r,sharing:i,display:a}}async function j(e,{tx:t,metadata:n}){return(await d(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}function M(e=96){let t=Math.ceil(e/2),n=``;if(typeof crypto<`u`&&crypto.getRandomValues){let e=new Uint8Array(t);crypto.getRandomValues(e);for(let t=0;t<e.length;t++)n+=e[t].toString(16).padStart(2,`0`)}else for(let e=0;e<t;e++)n+=(Math.random()*256|0).toString(16).padStart(2,`0`);return n.substring(0,e)}async function N(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 d(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:i,nonce:t?.nonce??M(),uri:t?.uri??`https://${r}`,version:t?.version??`1`,domain:r}}}})).siweAuthenticate}export{d as _,E as a,C as c,_ as d,g as f,f as g,p as h,D as i,S as l,m,j as n,w as o,h as p,k as r,T as s,N as t,v as u,u as v};
@@ -1 +0,0 @@
1
- let e=require(`@frak-labs/frame-connector`);const t=`frak-client-id`;function n(){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 r(){if(typeof window>`u`||!window.localStorage)return console.warn(`[Frak SDK] No Window / localStorage available to save the clientId`),n();let e=localStorage.getItem(t);return e||(e=n(),localStorage.setItem(t,e)),e}var i=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}};const a=new i(1024),o=new i(1024),s=new i(1024);async function c(e,{cacheKey:t,cacheTime:n=3e4}){if(n>0){let e=o.get(t);if(e&&Date.now()-e.created<n)return e.data}let r=s.get(t);if(r&&Date.now()-r<1e3)throw Error(`Cache: ${t} recently failed, backing off`);let i=a.get(t);i||(i=e(),a.set(t,i));try{let e=await i;return o.set(t,{data:e,created:Date.now()}),s.delete(t),e}catch(e){throw s.set(t,Date.now()),e}finally{a.delete(t)}}function l(){a.clear(),o.clear(),s.clear()}const u=`https://backend.frak.id`;function d(e){return e.includes(`localhost:3000`)||e.includes(`localhost:3010`)}function f(e){return d(e)?`https://localhost:3030`:e.includes(`wallet-dev.frak.id`)||e.includes(`wallet.gcp-dev.frak.id`)?`https://backend.gcp-dev.frak.id`:u}function p(e){if(e)return f(e);if(typeof window<`u`){let e=window.FrakSetup?.client?.config?.walletUrl;if(e)return f(e)}return u}const m=`__frakSdkConfig`,h=`frak-config-cache`,g=`frak-merchant-id`,_={key:h},v=typeof window<`u`;function y(){return{isResolved:!1,merchantId:``}}let b=null;function x(){if(!v)return null;try{let e=localStorage.getItem(_.key);if(!e)return null;let t=JSON.parse(e);return t.config?.isResolved?(b=t,t):null}catch{return null}}function S(){return(b??x())?.config}function C(){let e=b??x();return e?Date.now()-e.timestamp<3e4:!1}function ee(e){if(!(!v||!e.isResolved))try{let t={config:e,timestamp:Date.now()};localStorage.setItem(_.key,JSON.stringify(t)),b=t}catch{}}function w(){if(v){b=null;try{localStorage.removeItem(_.key)}catch{}}}function T(){v&&(window[m]||(window[m]=S()??y()))}T();function E(){return v?window[m]??y():y()}function D(e){v&&window.dispatchEvent(new CustomEvent(`frak:config`,{detail:e}))}function O(e){return e??(v?window.location.hostname:``)}async function te(e,t,n){try{let r=p(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(v)try{sessionStorage.setItem(g,o.merchantId)}catch{}return o}catch(e){console.warn(`[Frak SDK] Failed to fetch merchant config:`,e);return}}const k={getConfig:E,get isResolved(){return E().isResolved},get isCacheFresh(){return C()},setCacheScope(e,t){_.key=`${h}:${`${e}:${t??``}`}`,b=null},setConfig(e){if(v&&(window[m]=e),ee(e),D(e),v&&e.merchantId)try{sessionStorage.setItem(g,e.merchantId)}catch{}},reset(){let e=S()??y();v&&(window[m]=e),D(e)},clearCache(){if(w(),l(),v)try{sessionStorage.removeItem(g)}catch{}},resolve(e,t,n){let r=O(e);return r?c(async()=>{let e=await te(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=E();if(e.isResolved&&e.merchantId)return e.merchantId;if(v)try{return sessionStorage.getItem(g)??void 0}catch{}},async resolveMerchantId(e,t){return k.getMerchantId()||(await k.resolve(e,t))?.merchantId}};function A(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function j(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 M(t){return A((0,e.jsonEncode)(t))}function N(e,t,n,r,i,a){let o=M(P({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 P(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}}}const F=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,I=`frak-sso`;async function ne(e,t){let{metadata:n,customizations:i,walletUrl:a}=e.config,o={...t,directExit:t.directExit??!t.redirectUrl};if(o.openInSameWindow??!!o.redirectUrl)return await e.request({method:`frak_openSso`,params:[o,n.name,i?.css]});let s=o.ssoPopupUrl??N(a??`https://wallet.frak.id`,o,await k.resolveMerchantId()??``,n.name,r(),i?.css),c=window.open(s,I,F);if(!c)throw Error(`Popup was blocked. Please allow popups for this site.`);return c.focus(),await e.request({method:`frak_openSso`,params:[o,n.name,i?.css]})??{}}function re(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)}}const ie=/^0x[a-fA-F0-9]{40}$/;function L(e){return typeof e==`string`&&ie.test(e)}function ae(e,t){return e.toLowerCase()===t.toLowerCase()}function R(e){let t=new Uint8Array(20);for(let n=0;n<20;n++){let r=Number.parseInt(e.substring(2+n*2,4+n*2),16);if(Number.isNaN(r))throw Error(`Invalid address: ${e}`);t[n]=r}return t}const z=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function B(e){let t=`0x`;for(let n=0;n<20;n++)t+=z[e[n]];return t}function V(e){return`r`in e&&!(`v`in e)}function H(e){return`v`in e&&e.v===2}const U=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function W(e){return typeof e==`string`&&U.test(e)}function G(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 K(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 q(e){if(!W(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`&&L(e.w);if(!t&&!n||t&&!W(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(G(e.m),a),a+=16,i.setUint32(a,e.t,!1),a+=4,t&&(r.set(G(e.c),a),a+=16),n&&(r.set(R(e.w),a),a+=20),r}function oe(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=K(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=K(e.subarray(a,a+16)),a+=16),r){let t=B(e.subarray(a,a+20));if(!L(t))return null;c.w=t,a+=20}return c}const J=`fCtx`;function Y(e){if(e)try{if(H(e)){let t=q(e);return t?A(t):void 0}return A(R(e.r))}catch(t){console.error(`Error compressing Frak context`,{e:t,context:e})}}function X(e){if(!(!e||e.length===0))try{let t=j(e);if(t.length!==20)return oe(t)||void 0;let n=B(t);if(L(n))return{r:n}}catch(t){console.error(`Error decompressing Frak context`,{e:t,context:e})}}function se({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(J);return t?X(t):null}function ce(e){return{utm_source:e.utmSource??`frak`,utm_medium:e.utmMedium??void 0,utm_campaign:e.utmCampaign??void 0,utm_content:e.utmContent,utm_term:e.utmTerm,via:e.via??void 0,ref:e.ref??void 0}}function le(e,t){let n=ce(t??{});for(let[t,r]of Object.entries(n))r===void 0||r===``||e.searchParams.has(t)||e.searchParams.set(t,r)}function Z({url:e,context:t,attribution:n}){if(!e)return null;let r=Y(t);if(!r)return null;let i=new URL(e);return i.searchParams.set(J,r),le(i,n),i.toString()}function Q(e){let t=new URL(e);return t.searchParams.delete(J),t.toString()}function $({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?Q(n):Z({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}const ue={compress:Y,decompress:X,parse:se,update:Z,remove:Q,replaceUrl:$};Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return re}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return ae}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return ne}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return ue}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return M}});
@@ -1 +0,0 @@
1
- import{jsonEncode as e}from"@frak-labs/frame-connector";const t=`frak-client-id`;function n(){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 r(){if(typeof window>`u`||!window.localStorage)return console.warn(`[Frak SDK] No Window / localStorage available to save the clientId`),n();let e=localStorage.getItem(t);return e||(e=n(),localStorage.setItem(t,e)),e}var i=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}};const a=new i(1024),o=new i(1024),s=new i(1024);async function c(e,{cacheKey:t,cacheTime:n=3e4}){if(n>0){let e=o.get(t);if(e&&Date.now()-e.created<n)return e.data}let r=s.get(t);if(r&&Date.now()-r<1e3)throw Error(`Cache: ${t} recently failed, backing off`);let i=a.get(t);i||(i=e(),a.set(t,i));try{let e=await i;return o.set(t,{data:e,created:Date.now()}),s.delete(t),e}catch(e){throw s.set(t,Date.now()),e}finally{a.delete(t)}}function l(){a.clear(),o.clear(),s.clear()}const u=`https://backend.frak.id`;function d(e){return e.includes(`localhost:3000`)||e.includes(`localhost:3010`)}function f(e){return d(e)?`https://localhost:3030`:e.includes(`wallet-dev.frak.id`)||e.includes(`wallet.gcp-dev.frak.id`)?`https://backend.gcp-dev.frak.id`:u}function p(e){if(e)return f(e);if(typeof window<`u`){let e=window.FrakSetup?.client?.config?.walletUrl;if(e)return f(e)}return u}const m=`__frakSdkConfig`,h=`frak-config-cache`,g=`frak-merchant-id`,_={key:h},v=typeof window<`u`;function y(){return{isResolved:!1,merchantId:``}}let b=null;function x(){if(!v)return null;try{let e=localStorage.getItem(_.key);if(!e)return null;let t=JSON.parse(e);return t.config?.isResolved?(b=t,t):null}catch{return null}}function S(){return(b??x())?.config}function C(){let e=b??x();return e?Date.now()-e.timestamp<3e4:!1}function ee(e){if(!(!v||!e.isResolved))try{let t={config:e,timestamp:Date.now()};localStorage.setItem(_.key,JSON.stringify(t)),b=t}catch{}}function w(){if(v){b=null;try{localStorage.removeItem(_.key)}catch{}}}function T(){v&&(window[m]||(window[m]=S()??y()))}T();function E(){return v?window[m]??y():y()}function D(e){v&&window.dispatchEvent(new CustomEvent(`frak:config`,{detail:e}))}function O(e){return e??(v?window.location.hostname:``)}async function te(e,t,n){try{let r=p(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(v)try{sessionStorage.setItem(g,o.merchantId)}catch{}return o}catch(e){console.warn(`[Frak SDK] Failed to fetch merchant config:`,e);return}}const k={getConfig:E,get isResolved(){return E().isResolved},get isCacheFresh(){return C()},setCacheScope(e,t){_.key=`${h}:${`${e}:${t??``}`}`,b=null},setConfig(e){if(v&&(window[m]=e),ee(e),D(e),v&&e.merchantId)try{sessionStorage.setItem(g,e.merchantId)}catch{}},reset(){let e=S()??y();v&&(window[m]=e),D(e)},clearCache(){if(w(),l(),v)try{sessionStorage.removeItem(g)}catch{}},resolve(e,t,n){let r=O(e);return r?c(async()=>{let e=await te(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=E();if(e.isResolved&&e.merchantId)return e.merchantId;if(v)try{return sessionStorage.getItem(g)??void 0}catch{}},async resolveMerchantId(e,t){return k.getMerchantId()||(await k.resolve(e,t))?.merchantId}};function A(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function j(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 M(t){return A(e(t))}function N(e,t,n,r,i,a){let o=M(P({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 P(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}}}const F=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,I=`frak-sso`;async function ne(e,t){let{metadata:n,customizations:i,walletUrl:a}=e.config,o={...t,directExit:t.directExit??!t.redirectUrl};if(o.openInSameWindow??!!o.redirectUrl)return await e.request({method:`frak_openSso`,params:[o,n.name,i?.css]});let s=o.ssoPopupUrl??N(a??`https://wallet.frak.id`,o,await k.resolveMerchantId()??``,n.name,r(),i?.css),c=window.open(s,I,F);if(!c)throw Error(`Popup was blocked. Please allow popups for this site.`);return c.focus(),await e.request({method:`frak_openSso`,params:[o,n.name,i?.css]})??{}}function re(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)}}const ie=/^0x[a-fA-F0-9]{40}$/;function L(e){return typeof e==`string`&&ie.test(e)}function ae(e,t){return e.toLowerCase()===t.toLowerCase()}function R(e){let t=new Uint8Array(20);for(let n=0;n<20;n++){let r=Number.parseInt(e.substring(2+n*2,4+n*2),16);if(Number.isNaN(r))throw Error(`Invalid address: ${e}`);t[n]=r}return t}const z=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function B(e){let t=`0x`;for(let n=0;n<20;n++)t+=z[e[n]];return t}function V(e){return`r`in e&&!(`v`in e)}function H(e){return`v`in e&&e.v===2}const U=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function W(e){return typeof e==`string`&&U.test(e)}function G(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 K(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 q(e){if(!W(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`&&L(e.w);if(!t&&!n||t&&!W(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(G(e.m),a),a+=16,i.setUint32(a,e.t,!1),a+=4,t&&(r.set(G(e.c),a),a+=16),n&&(r.set(R(e.w),a),a+=20),r}function oe(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=K(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=K(e.subarray(a,a+16)),a+=16),r){let t=B(e.subarray(a,a+20));if(!L(t))return null;c.w=t,a+=20}return c}const J=`fCtx`;function Y(e){if(e)try{if(H(e)){let t=q(e);return t?A(t):void 0}return A(R(e.r))}catch(t){console.error(`Error compressing Frak context`,{e:t,context:e})}}function X(e){if(!(!e||e.length===0))try{let t=j(e);if(t.length!==20)return oe(t)||void 0;let n=B(t);if(L(n))return{r:n}}catch(t){console.error(`Error decompressing Frak context`,{e:t,context:e})}}function se({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(J);return t?X(t):null}function ce(e){return{utm_source:e.utmSource??`frak`,utm_medium:e.utmMedium??void 0,utm_campaign:e.utmCampaign??void 0,utm_content:e.utmContent,utm_term:e.utmTerm,via:e.via??void 0,ref:e.ref??void 0}}function le(e,t){let n=ce(t??{});for(let[t,r]of Object.entries(n))r===void 0||r===``||e.searchParams.has(t)||e.searchParams.set(t,r)}function Z({url:e,context:t,attribution:n}){if(!e)return null;let r=Y(t);if(!r)return null;let i=new URL(e);return i.searchParams.set(J,r),le(i,n),i.toString()}function Q(e){let t=new URL(e);return t.searchParams.delete(J),t.toString()}function $({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?Q(n):Z({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}const ue={compress:Y,decompress:X,parse:se,update:Z,remove:Q,replaceUrl:$};export{r as _,re as a,I as c,j as d,A as f,c as g,l as h,ae as i,N as l,p as m,V as n,ne as o,k as p,H as r,F as s,ue as t,M as u};
@@ -1 +0,0 @@
1
- import{_ as e,d as t,h as n,m as r,p as i}from"./frakContext-UEOk9Bk4.js";import{Deferred as a,FrakRpcError as o,RpcErrorCodes as s,createRpcClient as c,jsonDecode as l}from"@frak-labs/frame-connector";import{OpenPanel as u}from"@openpanel/web";const d=`nexus-wallet-backup`,f=`frakwallet://`;function p(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`))}function m(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}const h=f.replace(`://`,``);function g(e){return`intent://${e.slice(13)}#Intent;scheme=${h};end`}function _(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=m()&&v(e)?g(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function v(e){return e.startsWith(f)}const 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 b({walletBaseUrl:t,config:n}){let i=document.querySelector(`#frak-wallet`);i&&i.remove();let a=document.createElement(`iframe`);a.id=y.id,a.name=y.name,a.allow=y.allow,a.style.zIndex=y.style.zIndex.toString(),S({iframe:a,isVisible:!1});let o=n?.walletUrl??t??`https://wallet.frak.id`,s=e();return w(o),w(r(o)),a.src=x({walletUrl:o,clientId:s,preload:n?.preload}),new Promise(e=>{a.addEventListener(`load`,()=>e(a)),document.body.appendChild(a)})}function x({walletUrl:e,clientId:t,preload:n}){let r=`${e}/listener?clientId=${encodeURIComponent(t)}`;return!n||n.length===0?r:`${r}#preload=${n.join(`,`)}`}function S({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 C(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 w(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{}}const T=(()=>{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 E(e){e?localStorage.setItem(d,e):localStorage.removeItem(d)}function D(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=A(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function O(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 k(e){return e.includes(`/common/social`)}function A(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 j(e,t,n,r,i){if(i){let e=D(t,r);window.open(e,`_blank`);return}if(v(t)){let i=D(t,r);_(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(T&&k(t))O(r);else{let e=D(t,r);window.location.href=e}}function M({iframe:e,targetOrigin:t}){let n=new a;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`:E(a.backup);break;case`remove-backup`:localStorage.removeItem(d);break;case`show`:case`hide`:S({iframe:e,isVisible:i===`show`});break;case`redirect`:j(e,a.baseRedirectUrl,t,a.mergeToken,a.openInNewTab);break}},isConnected:n.promise}}function N({config:t,iframe:r}){let l=t?.walletUrl??`https://wallet.frak.id`,d=typeof navigator<`u`?navigator.language?.split(`-`)[0]:void 0,f=t.metadata.lang??(d===`en`||d===`fr`?d:void 0),p=t.domain??(typeof window<`u`?window.location.hostname:``);i.setCacheScope(p,f),i.reset();let m=i.isCacheFresh?void 0:i.resolve(t.domain,t.walletUrl,f),h=M({iframe:r,targetOrigin:l}),g=new a,_=Date.now();if(!r.contentWindow)throw new o(s.configError,`The iframe does not have a content window`);let v=c({emittingTransport:r.contentWindow,listeningTransport:window,targetOrigin:l,middleware:[{async onRequest(e,t){if(!await h.isConnected)throw new o(s.clientNotConnected,`The iframe provider isn't connected yet`);return await g.promise,t}}],lifecycleHandlers:{iframeLifecycle:(e,t)=>{h.handleEvent(e)}}}),y=P(v,h),b=async()=>{y(),v.cleanup(),r.remove(),n(),i.clearCache(),i.reset()},x;{console.log(`[Frak SDK] Initializing OpenPanel`),x=new u({apiUrl:`https://op-api.gcp.frak.id`,clientId:`6eacc8d7-49ac-4936-95e9-81ef29449570`,trackScreenViews:!0,trackOutgoingLinks:!0,trackAttributes:!1,filter:({type:t,payload:n})=>(t!==`track`||!n?.properties||`sdk_version`in n.properties||(n.properties={...n.properties,sdk_version:`1.1.3`,user_anonymous_client_id:e()}),!0)}),x.setGlobalProperties({sdk_version:`1.1.3`,user_anonymous_client_id:e()}),x.init(),x.track(`sdk_initialized`,{sdk_version:`1.1.3`});let t=!1,n=setTimeout(()=>{t||(t=!0,x?.track(`sdk_iframe_handshake_failed`,{reason:`timeout`}))},3e4);h.isConnected.then(()=>{t||(t=!0,clearTimeout(n),x?.track(`sdk_iframe_connected`,{handshake_duration_ms:Date.now()-_}))}).catch(()=>{t||(t=!0,clearTimeout(n),x?.track(`sdk_iframe_handshake_failed`,{reason:`unknown`}))})}let S=F({config:t,rpcClient:v,lifecycleManager:h,configPromise:m,contextSent:g,openPanel:x}).then(()=>{}).catch(e=>{throw g.reject(e),e});return{config:t,waitForConnection:h.isConnected,waitForSetup:S,request:v.request,listenerRequest:v.listen,destroy:b,openPanel:x}}function P(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 F({config:t,rpcClient:n,lifecycleManager:r,configPromise:a,contextSent:o,openPanel:s}){await r.isConnected,p(n,r.isConnected);let c=new URL(window.location.href),l=c.searchParams.get(`fmt`)??void 0;l&&(c.searchParams.delete(`fmt`),window.history.replaceState({},``,c.toString()));let u=e=>{let n=e?.merchantId??t.metadata.merchantId??``,r=e?.domain??``,a=e?.allowedDomains??[],o=e?.sdkConfig,s=o?.attribution||t.attribution?{...t.attribution,...o?.attribution}:void 0;i.setConfig(o?{isResolved:!0,merchantId:n,domain:r,allowedDomains:a,hasRawSdkConfig:!0,name:o.name??t.metadata.name,logoUrl:o.logoUrl??t.metadata.logoUrl,homepageLink:o.homepageLink??t.metadata.homepageLink,lang:o.lang??t.metadata.lang,currency:o.currency??t.metadata.currency,hidden:o.hidden,css:o.css,translations:o.translations,placements:o.placements,components:o.components,attribution:s}:{isResolved:!0,merchantId:n,domain:r,allowedDomains:a,name:t.metadata.name,logoUrl:t.metadata.logoUrl,homepageLink:t.metadata.homepageLink,lang:t.metadata.lang,currency:t.metadata.currency,attribution:s})},f=!1,m=t=>{let r=f?void 0:l;f=!0;let i=t.hasRawSdkConfig?{name:t.name,logoUrl:t.logoUrl,homepageLink:t.homepageLink,lang:t.lang,currency:t.currency,hidden:t.hidden,css:t.css,translations:t.translations,placements:t.placements,attribution:t.attribution}:t.attribution?{attribution:t.attribution}:void 0,a=e();if(s){let e=s.global??{};s.setGlobalProperties({...e,merchant_id:t.merchantId,domain:t.domain??``})}n.sendLifecycle({clientLifecycle:`resolved-config`,data:{merchantId:t.merchantId,domain:t.domain??``,allowedDomains:t.allowedDomains??[],sourceUrl:window.location.href,...a&&{sdkAnonymousId:a},...r&&{pendingMergeToken:r},...i&&{sdkConfig:i}}})};i.isResolved&&(m(i.getConfig()),o.resolve()),a&&(u(await a),m(i.getConfig()),o.resolve());async function h(){let e=t.customizations?.css;e&&n.sendLifecycle({clientLifecycle:`modal-css`,data:{cssLink:e}})}async function g(){let e=t.customizations?.i18n;e&&n.sendLifecycle({clientLifecycle:`modal-i18n`,data:{i18n:e}})}async function _(){if(typeof window>`u`)return;let e=window.localStorage.getItem(d);e&&n.sendLifecycle({clientLifecycle:`restore-backup`,data:{backup:e}})}(await Promise.allSettled([h(),g(),_()])).some(e=>e.status===`rejected`)&&s?.track(`sdk_iframe_handshake_failed`,{reason:`asset_push`})}function I(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent;return!!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1)}const L=I();function R(){return typeof navigator>`u`?!1:L?!0:/Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}function z(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent.toLowerCase();return e.includes(`instagram`)||e.includes(`fban`)||e.includes(`fbav`)||e.includes(`facebook`)}const B=z();function V(e){L&&e.startsWith(`https://`)?window.location.href=`x-safari-https://${e.slice(8)}`:L&&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 H(e){return l(t(e))}const U={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function W(e){return e&&e in U?e:`eur`}function G(e){return e?U[e]??U.eur:U.eur}function K(e,t){let n=G(t),r=W(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function q(e){return e?`${e}Amount`:`eurAmount`}async function J({config:e}){let t=Y(e),n=await b({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=N({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function Y(e){let t=W(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}function X({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}export{W as a,B as c,N as d,y as f,f as h,K as i,R as l,_ as m,J as n,H as o,C as p,q as r,L as s,X as t,V as u};
@@ -1 +0,0 @@
1
- const e=require(`./frakContext-Cfp7sSid.cjs`);let t=require(`@frak-labs/frame-connector`),n=require(`@openpanel/web`);const r=`nexus-wallet-backup`,i=`frakwallet://`;function a(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`))}function o(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}const s=i.replace(`://`,``);function c(e){return`intent://${e.slice(13)}#Intent;scheme=${s};end`}function l(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=o()&&u(e)?c(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function u(e){return e.startsWith(i)}const d={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 f({walletBaseUrl:t,config:n}){let r=document.querySelector(`#frak-wallet`);r&&r.remove();let i=document.createElement(`iframe`);i.id=d.id,i.name=d.name,i.allow=d.allow,i.style.zIndex=d.style.zIndex.toString(),m({iframe:i,isVisible:!1});let a=n?.walletUrl??t??`https://wallet.frak.id`,o=e._();return g(a),g(e.m(a)),i.src=p({walletUrl:a,clientId:o,preload:n?.preload}),new Promise(e=>{i.addEventListener(`load`,()=>e(i)),document.body.appendChild(i)})}function p({walletUrl:e,clientId:t,preload:n}){let r=`${e}/listener?clientId=${encodeURIComponent(t)}`;return!n||n.length===0?r:`${r}#preload=${n.join(`,`)}`}function m({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 h(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 g(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{}}const _=(()=>{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 v(e){e?localStorage.setItem(r,e):localStorage.removeItem(r)}function y(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=S(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function b(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 x(e){return e.includes(`/common/social`)}function S(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 C(e,t,n,r,i){if(i){let e=y(t,r);window.open(e,`_blank`);return}if(u(t)){let i=y(t,r);l(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(_&&x(t))b(r);else{let e=y(t,r);window.location.href=e}}function w({iframe:e,targetOrigin:n}){let i=new t.Deferred;return{handleEvent:t=>{if(!(`iframeLifecycle`in t))return;let{iframeLifecycle:a,data:o}=t;switch(a){case`connected`:i.resolve(!0);break;case`do-backup`:v(o.backup);break;case`remove-backup`:localStorage.removeItem(r);break;case`show`:case`hide`:m({iframe:e,isVisible:a===`show`});break;case`redirect`:C(e,o.baseRedirectUrl,n,o.mergeToken,o.openInNewTab);break}},isConnected:i.promise}}function T({config:r,iframe:i}){let a=r?.walletUrl??`https://wallet.frak.id`,o=typeof navigator<`u`?navigator.language?.split(`-`)[0]:void 0,s=r.metadata.lang??(o===`en`||o===`fr`?o:void 0),c=r.domain??(typeof window<`u`?window.location.hostname:``);e.p.setCacheScope(c,s),e.p.reset();let l=e.p.isCacheFresh?void 0:e.p.resolve(r.domain,r.walletUrl,s),u=w({iframe:i,targetOrigin:a}),d=new t.Deferred,f=Date.now();if(!i.contentWindow)throw new t.FrakRpcError(t.RpcErrorCodes.configError,`The iframe does not have a content window`);let p=(0,t.createRpcClient)({emittingTransport:i.contentWindow,listeningTransport:window,targetOrigin:a,middleware:[{async onRequest(e,n){if(!await u.isConnected)throw new t.FrakRpcError(t.RpcErrorCodes.clientNotConnected,`The iframe provider isn't connected yet`);return await d.promise,n}}],lifecycleHandlers:{iframeLifecycle:(e,t)=>{u.handleEvent(e)}}}),m=E(p,u),h=async()=>{m(),p.cleanup(),i.remove(),e.h(),e.p.clearCache(),e.p.reset()},g;{console.log(`[Frak SDK] Initializing OpenPanel`),g=new n.OpenPanel({apiUrl:`https://op-api.gcp.frak.id`,clientId:`6eacc8d7-49ac-4936-95e9-81ef29449570`,trackScreenViews:!0,trackOutgoingLinks:!0,trackAttributes:!1,filter:({type:t,payload:n})=>(t!==`track`||!n?.properties||`sdk_version`in n.properties||(n.properties={...n.properties,sdk_version:`1.1.3`,user_anonymous_client_id:e._()}),!0)}),g.setGlobalProperties({sdk_version:`1.1.3`,user_anonymous_client_id:e._()}),g.init(),g.track(`sdk_initialized`,{sdk_version:`1.1.3`});let t=!1,r=setTimeout(()=>{t||(t=!0,g?.track(`sdk_iframe_handshake_failed`,{reason:`timeout`}))},3e4);u.isConnected.then(()=>{t||(t=!0,clearTimeout(r),g?.track(`sdk_iframe_connected`,{handshake_duration_ms:Date.now()-f}))}).catch(()=>{t||(t=!0,clearTimeout(r),g?.track(`sdk_iframe_handshake_failed`,{reason:`unknown`}))})}let _=D({config:r,rpcClient:p,lifecycleManager:u,configPromise:l,contextSent:d,openPanel:g}).then(()=>{}).catch(e=>{throw d.reject(e),e});return{config:r,waitForConnection:u.isConnected,waitForSetup:_,request:p.request,listenerRequest:p.listen,destroy:h,openPanel:g}}function E(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 D({config:t,rpcClient:n,lifecycleManager:i,configPromise:o,contextSent:s,openPanel:c}){await i.isConnected,a(n,i.isConnected);let l=new URL(window.location.href),u=l.searchParams.get(`fmt`)??void 0;u&&(l.searchParams.delete(`fmt`),window.history.replaceState({},``,l.toString()));let d=n=>{let r=n?.merchantId??t.metadata.merchantId??``,i=n?.domain??``,a=n?.allowedDomains??[],o=n?.sdkConfig,s=o?.attribution||t.attribution?{...t.attribution,...o?.attribution}:void 0;e.p.setConfig(o?{isResolved:!0,merchantId:r,domain:i,allowedDomains:a,hasRawSdkConfig:!0,name:o.name??t.metadata.name,logoUrl:o.logoUrl??t.metadata.logoUrl,homepageLink:o.homepageLink??t.metadata.homepageLink,lang:o.lang??t.metadata.lang,currency:o.currency??t.metadata.currency,hidden:o.hidden,css:o.css,translations:o.translations,placements:o.placements,components:o.components,attribution:s}:{isResolved:!0,merchantId:r,domain:i,allowedDomains:a,name:t.metadata.name,logoUrl:t.metadata.logoUrl,homepageLink:t.metadata.homepageLink,lang:t.metadata.lang,currency:t.metadata.currency,attribution:s})},f=!1,p=t=>{let r=f?void 0:u;f=!0;let i=t.hasRawSdkConfig?{name:t.name,logoUrl:t.logoUrl,homepageLink:t.homepageLink,lang:t.lang,currency:t.currency,hidden:t.hidden,css:t.css,translations:t.translations,placements:t.placements,attribution:t.attribution}:t.attribution?{attribution:t.attribution}:void 0,a=e._();if(c){let e=c.global??{};c.setGlobalProperties({...e,merchant_id:t.merchantId,domain:t.domain??``})}n.sendLifecycle({clientLifecycle:`resolved-config`,data:{merchantId:t.merchantId,domain:t.domain??``,allowedDomains:t.allowedDomains??[],sourceUrl:window.location.href,...a&&{sdkAnonymousId:a},...r&&{pendingMergeToken:r},...i&&{sdkConfig:i}}})};e.p.isResolved&&(p(e.p.getConfig()),s.resolve()),o&&(d(await o),p(e.p.getConfig()),s.resolve());async function m(){let e=t.customizations?.css;e&&n.sendLifecycle({clientLifecycle:`modal-css`,data:{cssLink:e}})}async function h(){let e=t.customizations?.i18n;e&&n.sendLifecycle({clientLifecycle:`modal-i18n`,data:{i18n:e}})}async function g(){if(typeof window>`u`)return;let e=window.localStorage.getItem(r);e&&n.sendLifecycle({clientLifecycle:`restore-backup`,data:{backup:e}})}(await Promise.allSettled([m(),h(),g()])).some(e=>e.status===`rejected`)&&c?.track(`sdk_iframe_handshake_failed`,{reason:`asset_push`})}function O(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent;return!!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1)}const k=O();function A(){return typeof navigator>`u`?!1:k?!0:/Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}function j(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent.toLowerCase();return e.includes(`instagram`)||e.includes(`fban`)||e.includes(`fbav`)||e.includes(`facebook`)}const M=j();function N(e){k&&e.startsWith(`https://`)?window.location.href=`x-safari-https://${e.slice(8)}`:k&&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 P(n){return(0,t.jsonDecode)(e.d(n))}const F={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function I(e){return e&&e in F?e:`eur`}function L(e){return e?F[e]??F.eur:F.eur}function R(e,t){let n=L(t),r=I(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function z(e){return e?`${e}Amount`:`eurAmount`}async function B({config:e}){let t=V(e),n=await f({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=T({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function V(e){let t=I(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}function H({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}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return N}});