@frak-labs/core-sdk 0.1.0 → 0.1.1-beta.4dfea079
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/README.md +58 -0
- package/cdn/bundle.js +3 -8
- package/dist/actions.cjs +1 -1
- package/dist/actions.d.cts +3 -1400
- package/dist/actions.d.ts +3 -1400
- package/dist/actions.js +1 -1
- package/dist/bundle.cjs +1 -13
- package/dist/bundle.d.cts +4 -1927
- package/dist/bundle.d.ts +4 -1927
- package/dist/bundle.js +1 -13
- package/dist/computeLegacyProductId-CscYhyUi.d.cts +525 -0
- package/dist/computeLegacyProductId-WbD1gXV9.d.ts +525 -0
- package/dist/index.cjs +1 -13
- package/dist/index.d.cts +3 -1269
- package/dist/index.d.ts +3 -1269
- package/dist/index.js +1 -13
- package/dist/openSso-CC1-loUk.d.cts +1019 -0
- package/dist/openSso-tkqaDQLV.d.ts +1019 -0
- package/dist/setupClient-BjIbK6XJ.cjs +13 -0
- package/dist/setupClient-D_HId3e2.js +13 -0
- package/dist/siweAuthenticate-B_Z2OZmj.cjs +1 -0
- package/dist/siweAuthenticate-CQ4OfPuA.js +1 -0
- package/dist/siweAuthenticate-CR4Dpji6.d.cts +467 -0
- package/dist/siweAuthenticate-udoruuy9.d.ts +467 -0
- package/dist/trackEvent-CGIryq5h.cjs +1 -0
- package/dist/trackEvent-YfUh4jrx.js +1 -0
- package/package.json +24 -30
- package/src/actions/displayEmbeddedWallet.test.ts +194 -0
- package/src/actions/displayEmbeddedWallet.ts +20 -0
- package/src/actions/displayModal.test.ts +388 -0
- package/src/actions/displayModal.ts +120 -0
- package/src/actions/getMerchantInformation.test.ts +116 -0
- package/src/actions/getMerchantInformation.ts +9 -0
- package/src/actions/index.ts +29 -0
- package/src/actions/openSso.ts +116 -0
- package/src/actions/prepareSso.test.ts +223 -0
- package/src/actions/prepareSso.ts +48 -0
- package/src/actions/referral/processReferral.test.ts +248 -0
- package/src/actions/referral/processReferral.ts +232 -0
- package/src/actions/referral/referralInteraction.test.ts +147 -0
- package/src/actions/referral/referralInteraction.ts +52 -0
- package/src/actions/sendInteraction.ts +24 -0
- package/src/actions/trackPurchaseStatus.test.ts +287 -0
- package/src/actions/trackPurchaseStatus.ts +56 -0
- package/src/actions/watchWalletStatus.test.ts +372 -0
- package/src/actions/watchWalletStatus.ts +93 -0
- package/src/actions/wrapper/modalBuilder.test.ts +239 -0
- package/src/actions/wrapper/modalBuilder.ts +203 -0
- package/src/actions/wrapper/sendTransaction.test.ts +164 -0
- package/src/actions/wrapper/sendTransaction.ts +62 -0
- package/src/actions/wrapper/siweAuthenticate.test.ts +290 -0
- package/src/actions/wrapper/siweAuthenticate.ts +94 -0
- package/src/bundle.ts +2 -0
- package/src/clients/DebugInfo.test.ts +418 -0
- package/src/clients/DebugInfo.ts +182 -0
- package/src/clients/createIFrameFrakClient.ts +289 -0
- package/src/clients/index.ts +3 -0
- package/src/clients/setupClient.test.ts +343 -0
- package/src/clients/setupClient.ts +73 -0
- package/src/clients/transports/iframeLifecycleManager.test.ts +558 -0
- package/src/clients/transports/iframeLifecycleManager.ts +174 -0
- package/src/constants/interactionTypes.ts +15 -0
- package/src/constants/locales.ts +14 -0
- package/src/index.ts +110 -0
- package/src/types/client.ts +14 -0
- package/src/types/compression.ts +22 -0
- package/src/types/config.ts +117 -0
- package/src/types/context.ts +13 -0
- package/src/types/index.ts +75 -0
- package/src/types/lifecycle/client.ts +69 -0
- package/src/types/lifecycle/iframe.ts +41 -0
- package/src/types/lifecycle/index.ts +2 -0
- package/src/types/rpc/displayModal.ts +82 -0
- package/src/types/rpc/embedded/index.ts +68 -0
- package/src/types/rpc/embedded/loggedIn.ts +55 -0
- package/src/types/rpc/embedded/loggedOut.ts +28 -0
- package/src/types/rpc/interaction.ts +30 -0
- package/src/types/rpc/merchantInformation.ts +77 -0
- package/src/types/rpc/modal/final.ts +46 -0
- package/src/types/rpc/modal/generic.ts +46 -0
- package/src/types/rpc/modal/index.ts +16 -0
- package/src/types/rpc/modal/login.ts +36 -0
- package/src/types/rpc/modal/siweAuthenticate.ts +37 -0
- package/src/types/rpc/modal/transaction.ts +33 -0
- package/src/types/rpc/sso.ts +80 -0
- package/src/types/rpc/walletStatus.ts +29 -0
- package/src/types/rpc.ts +146 -0
- package/src/types/tracking.ts +60 -0
- package/src/types/transport.ts +34 -0
- package/src/utils/FrakContext.test.ts +407 -0
- package/src/utils/FrakContext.ts +158 -0
- package/src/utils/backendUrl.test.ts +83 -0
- package/src/utils/backendUrl.ts +62 -0
- package/src/utils/clientId.test.ts +41 -0
- package/src/utils/clientId.ts +40 -0
- package/src/utils/compression/b64.test.ts +181 -0
- package/src/utils/compression/b64.ts +29 -0
- package/src/utils/compression/compress.test.ts +123 -0
- package/src/utils/compression/compress.ts +11 -0
- package/src/utils/compression/decompress.test.ts +149 -0
- package/src/utils/compression/decompress.ts +11 -0
- package/src/utils/compression/index.ts +3 -0
- package/src/utils/computeLegacyProductId.ts +11 -0
- package/src/utils/constants.test.ts +23 -0
- package/src/utils/constants.ts +14 -0
- package/src/utils/deepLinkWithFallback.test.ts +243 -0
- package/src/utils/deepLinkWithFallback.ts +97 -0
- package/src/utils/formatAmount.test.ts +113 -0
- package/src/utils/formatAmount.ts +18 -0
- package/src/utils/getCurrencyAmountKey.test.ts +44 -0
- package/src/utils/getCurrencyAmountKey.ts +15 -0
- package/src/utils/getSupportedCurrency.test.ts +51 -0
- package/src/utils/getSupportedCurrency.ts +14 -0
- package/src/utils/getSupportedLocale.test.ts +64 -0
- package/src/utils/getSupportedLocale.ts +16 -0
- package/src/utils/iframeHelper.test.ts +450 -0
- package/src/utils/iframeHelper.ts +147 -0
- package/src/utils/index.ts +36 -0
- package/src/utils/merchantId.test.ts +564 -0
- package/src/utils/merchantId.ts +122 -0
- package/src/utils/sso.ts +126 -0
- package/src/utils/ssoUrlListener.test.ts +252 -0
- package/src/utils/ssoUrlListener.ts +60 -0
- package/src/utils/trackEvent.test.ts +180 -0
- package/src/utils/trackEvent.ts +31 -0
- package/cdn/bundle.js.LICENSE.txt +0 -10
- package/dist/interactions.cjs +0 -1
- package/dist/interactions.d.cts +0 -182
- package/dist/interactions.d.ts +0 -182
- package/dist/interactions.js +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const e=require(`./trackEvent-CGIryq5h.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`))}var o=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:0:-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 n=this.getIframeStatus(),r=this.getNavigatorInfo(),i=`Unknown`;return e instanceof t.FrakRpcError?i=`FrakRpcError: ${e.code} '${e.message}'`:e instanceof Error?i=e.message:typeof e==`string`&&(i=e),{timestamp:new Date().toISOString(),encodedUrl:btoa(window.location.href),encodedConfig:this.config?this.base64Encode(this.config):`no-config`,navigatorInfo:r?this.base64Encode(r):`no-navigator`,iframeStatus:n?this.base64Encode(n):`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:i}}static empty(){return new e}formatDebugInfo(e){let t=this.gatherDebugInfo(e);return`
|
|
2
|
+
Debug Information:
|
|
3
|
+
-----------------
|
|
4
|
+
Timestamp: ${t.timestamp}
|
|
5
|
+
URL: ${t.encodedUrl}
|
|
6
|
+
Config: ${t.encodedConfig}
|
|
7
|
+
Navigator Info: ${t.navigatorInfo}
|
|
8
|
+
IFrame Status: ${t.iframeStatus}
|
|
9
|
+
Last Request: ${t.lastRequest}
|
|
10
|
+
Last Response: ${t.lastResponse}
|
|
11
|
+
Client Status: ${t.clientStatus}
|
|
12
|
+
Error: ${t.error}
|
|
13
|
+
`.trim()}};function s(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}function c(e){return`intent://${e.slice(13)}#Intent;scheme=frakwallet;package=id.frak.wallet;end`}function l(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=s()&&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:e,config:t}){let n=document.querySelector(`#frak-wallet`);n&&n.remove();let r=document.createElement(`iframe`);return r.id=d.id,r.name=d.name,r.allow=d.allow,r.style.zIndex=d.style.zIndex.toString(),p({iframe:r,isVisible:!1}),r.src=`${t?.walletUrl??e??`https://wallet.frak.id`}/listener`,new Promise(e=>{r.addEventListener(`load`,()=>e(r)),document.body.appendChild(r)})}function p({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 m(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 h(e){e?localStorage.setItem(r,e):localStorage.removeItem(r)}function g(t,n,r,i){let a=new URL(window.location.href),o=a.searchParams.get(`fmt`)??void 0;t.contentWindow?.postMessage({clientLifecycle:`handshake-response`,data:{token:n,currentUrl:window.location.href,clientId:e.d(),pendingMergeToken:o,configDomain:i}},r),o&&(a.searchParams.delete(`fmt`),window.history.replaceState({},``,a.toString()))}function _(e,t){try{let n=new URL(e);return n.searchParams.has(`u`)?(n.searchParams.delete(`u`),n.searchParams.append(`u`,window.location.href),t&&n.searchParams.append(`fmt`,t),n.toString()):e}catch{return e}}function v(e,t,n,r){let i=_(t,r);u(t)?l(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}}):window.location.href=i}function y({iframe:e,targetOrigin:n,configDomain:i}){let a=new t.Deferred;return{handleEvent:async t=>{if(!(`iframeLifecycle`in t))return;let{iframeLifecycle:o,data:s}=t;switch(o){case`connected`:a.resolve(!0);break;case`do-backup`:h(s.backup);break;case`remove-backup`:localStorage.removeItem(r);break;case`show`:case`hide`:p({iframe:e,isVisible:o===`show`});break;case`handshake`:g(e,s.token,n,i);break;case`redirect`:v(e,s.baseRedirectUrl,n,s.mergeToken);break}},isConnected:a.promise}}function b({config:e,iframe:r}){let i=e?.walletUrl??`https://wallet.frak.id`,a=y({iframe:r,targetOrigin:i,configDomain:e.domain}),s=new o(e,r);if(!r.contentWindow)throw new t.FrakRpcError(t.RpcErrorCodes.configError,`The iframe does not have a content window`);let c=(0,t.createRpcClient)({emittingTransport:r.contentWindow,listeningTransport:window,targetOrigin:i,middleware:[{async onRequest(e,n){if(!await a.isConnected)throw new t.FrakRpcError(t.RpcErrorCodes.clientNotConnected,`The iframe provider isn't connected yet`);return n}},{onRequest(e,t){return s.setLastRequest(e),t},onResponse(e,t){return s.setLastResponse(e,t),t}}],lifecycleHandlers:{iframeLifecycle:async(e,t)=>{await a.handleEvent(e)}}}),l=x(c,a),u=async()=>{l(),c.cleanup(),r.remove()},d;console.log(`[Frak SDK] Initializing OpenPanel`),d=new n.OpenPanel({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:`0.1.1`}),!0)}),d.setGlobalProperties({sdkVersion:`0.1.1`}),d.init();let f=S({config:e,rpcClient:c,lifecycleManager:a}).then(()=>s.updateSetupStatus(!0));return{config:e,debugInfo:s,waitForConnection:a.isConnected,waitForSetup:f,request:c.request,listenerRequest:c.listen,destroy:u,openPanel:d}}function x(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,1e3),r=setTimeout(()=>{o(),console.log(`Heartbeat timeout: connection failed`)},3e4),await t.isConnected,o()}function o(){n&&clearInterval(n),r&&clearTimeout(r)}return a(),o}async function S({config:e,rpcClient:t,lifecycleManager:n}){await n.isConnected,a(t,n.isConnected);async function i(){let n=e.customizations?.css;if(!n)return;let r={clientLifecycle:`modal-css`,data:{cssLink:n}};t.sendLifecycle(r)}async function o(){let n=e.customizations?.i18n;if(!n)return;let r={clientLifecycle:`modal-i18n`,data:{i18n:n}};t.sendLifecycle(r)}async function s(){if(typeof window>`u`)return;let e=window.localStorage.getItem(r);if(!e)return;let n={clientLifecycle:`restore-backup`,data:{backup:e}};t.sendLifecycle(n)}await Promise.allSettled([i(),o(),s()])}function C(n){return(0,t.jsonDecode)(e.l(n))}const w={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function T(e){return e&&e in w?e:`eur`}function E(e){return e?w[e]??w.eur:w.eur}function D(e,t){let n=E(t),r=T(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function O(e){return e?`${e}Amount`:`eurAmount`}let k,A;async function j(e,t){if(k)return k;if(A)return A;A=M(e,t);let n=await A;return A=void 0,n}async function M(t,n){let r=t??(typeof window<`u`?window.location.hostname:``);if(r)try{let t=e.r(n),i=await fetch(`${t}/user/merchant/resolve?domain=${encodeURIComponent(r)}`);if(!i.ok){console.warn(`[Frak SDK] Merchant lookup failed for domain ${r}: ${i.status}`);return}return k=(await i.json()).merchantId,k}catch(e){console.warn(`[Frak SDK] Failed to fetch merchantId:`,e);return}}function N(){k=void 0,A=void 0}async function P(e,t){return e.metadata?.merchantId?e.metadata.merchantId:j(void 0,t)}async function F({config:e}){let t=I(e),n=await f({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=b({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function I(e){let t=T(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return o}});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import{d as e,l as t,r as n}from"./trackEvent-YfUh4jrx.js";import{Deferred as r,FrakRpcError as i,RpcErrorCodes as a,createRpcClient as o,jsonDecode as s}from"@frak-labs/frame-connector";import{OpenPanel as c}from"@openpanel/web";const l=`nexus-wallet-backup`,u=`frakwallet://`;function d(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 f=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:0:-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 i?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
|
+
Debug Information:
|
|
3
|
+
-----------------
|
|
4
|
+
Timestamp: ${t.timestamp}
|
|
5
|
+
URL: ${t.encodedUrl}
|
|
6
|
+
Config: ${t.encodedConfig}
|
|
7
|
+
Navigator Info: ${t.navigatorInfo}
|
|
8
|
+
IFrame Status: ${t.iframeStatus}
|
|
9
|
+
Last Request: ${t.lastRequest}
|
|
10
|
+
Last Response: ${t.lastResponse}
|
|
11
|
+
Client Status: ${t.clientStatus}
|
|
12
|
+
Error: ${t.error}
|
|
13
|
+
`.trim()}};function p(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}function m(e){return`intent://${e.slice(13)}#Intent;scheme=frakwallet;package=id.frak.wallet;end`}function h(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=p()&&g(e)?m(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function g(e){return e.startsWith(u)}const _={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 v({walletBaseUrl:e,config:t}){let n=document.querySelector(`#frak-wallet`);n&&n.remove();let r=document.createElement(`iframe`);return r.id=_.id,r.name=_.name,r.allow=_.allow,r.style.zIndex=_.style.zIndex.toString(),y({iframe:r,isVisible:!1}),r.src=`${t?.walletUrl??e??`https://wallet.frak.id`}/listener`,new Promise(e=>{r.addEventListener(`load`,()=>e(r)),document.body.appendChild(r)})}function y({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 b(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 x(e){e?localStorage.setItem(l,e):localStorage.removeItem(l)}function S(t,n,r,i){let a=new URL(window.location.href),o=a.searchParams.get(`fmt`)??void 0;t.contentWindow?.postMessage({clientLifecycle:`handshake-response`,data:{token:n,currentUrl:window.location.href,clientId:e(),pendingMergeToken:o,configDomain:i}},r),o&&(a.searchParams.delete(`fmt`),window.history.replaceState({},``,a.toString()))}function C(e,t){try{let n=new URL(e);return n.searchParams.has(`u`)?(n.searchParams.delete(`u`),n.searchParams.append(`u`,window.location.href),t&&n.searchParams.append(`fmt`,t),n.toString()):e}catch{return e}}function w(e,t,n,r){let i=C(t,r);g(t)?h(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}}):window.location.href=i}function T({iframe:e,targetOrigin:t,configDomain:n}){let i=new r;return{handleEvent:async r=>{if(!(`iframeLifecycle`in r))return;let{iframeLifecycle:a,data:o}=r;switch(a){case`connected`:i.resolve(!0);break;case`do-backup`:x(o.backup);break;case`remove-backup`:localStorage.removeItem(l);break;case`show`:case`hide`:y({iframe:e,isVisible:a===`show`});break;case`handshake`:S(e,o.token,t,n);break;case`redirect`:w(e,o.baseRedirectUrl,t,o.mergeToken);break}},isConnected:i.promise}}function E({config:e,iframe:t}){let n=e?.walletUrl??`https://wallet.frak.id`,r=T({iframe:t,targetOrigin:n,configDomain:e.domain}),s=new f(e,t);if(!t.contentWindow)throw new i(a.configError,`The iframe does not have a content window`);let l=o({emittingTransport:t.contentWindow,listeningTransport:window,targetOrigin:n,middleware:[{async onRequest(e,t){if(!await r.isConnected)throw new i(a.clientNotConnected,`The iframe provider isn't connected yet`);return t}},{onRequest(e,t){return s.setLastRequest(e),t},onResponse(e,t){return s.setLastResponse(e,t),t}}],lifecycleHandlers:{iframeLifecycle:async(e,t)=>{await r.handleEvent(e)}}}),u=D(l,r),d=async()=>{u(),l.cleanup(),t.remove()},p;console.log(`[Frak SDK] Initializing OpenPanel`),p=new c({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:`0.1.1`}),!0)}),p.setGlobalProperties({sdkVersion:`0.1.1`}),p.init();let m=O({config:e,rpcClient:l,lifecycleManager:r}).then(()=>s.updateSetupStatus(!0));return{config:e,debugInfo:s,waitForConnection:r.isConnected,waitForSetup:m,request:l.request,listenerRequest:l.listen,destroy:d,openPanel:p}}function D(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,1e3),r=setTimeout(()=>{o(),console.log(`Heartbeat timeout: connection failed`)},3e4),await t.isConnected,o()}function o(){n&&clearInterval(n),r&&clearTimeout(r)}return a(),o}async function O({config:e,rpcClient:t,lifecycleManager:n}){await n.isConnected,d(t,n.isConnected);async function r(){let n=e.customizations?.css;if(!n)return;let r={clientLifecycle:`modal-css`,data:{cssLink:n}};t.sendLifecycle(r)}async function i(){let n=e.customizations?.i18n;if(!n)return;let r={clientLifecycle:`modal-i18n`,data:{i18n:n}};t.sendLifecycle(r)}async function a(){if(typeof window>`u`)return;let e=window.localStorage.getItem(l);if(!e)return;let n={clientLifecycle:`restore-backup`,data:{backup:e}};t.sendLifecycle(n)}await Promise.allSettled([r(),i(),a()])}function k(e){return s(t(e))}const A={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function j(e){return e&&e in A?e:`eur`}function M(e){return e?A[e]??A.eur:A.eur}function N(e,t){let n=M(t),r=j(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function P(e){return e?`${e}Amount`:`eurAmount`}let F,I;async function L(e,t){if(F)return F;if(I)return I;I=R(e,t);let n=await I;return I=void 0,n}async function R(e,t){let r=e??(typeof window<`u`?window.location.hostname:``);if(r)try{let e=n(t),i=await fetch(`${e}/user/merchant/resolve?domain=${encodeURIComponent(r)}`);if(!i.ok){console.warn(`[Frak SDK] Merchant lookup failed for domain ${r}: ${i.status}`);return}return F=(await i.json()).merchantId,F}catch(e){console.warn(`[Frak SDK] Failed to fetch merchantId:`,e);return}}function z(){F=void 0,I=void 0}async function B(e,t){return e.metadata?.merchantId?e.metadata.merchantId:L(void 0,t)}async function V({config:e}){let t=H(e),n=await v({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=E({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function H(e){let t=j(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}export{m as _,P as a,u as b,j as c,E as d,_ as f,g,p as h,B as i,A as l,b as m,z as n,N as o,v as p,L as r,M as s,V as t,k as u,h as v,f as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./trackEvent-CGIryq5h.cjs`);let t=require(`viem`),n=require(`@frak-labs/frame-connector`),r=require(`viem/siwe`);async function i(e,t){return await e.request({method:`frak_displayEmbeddedWallet`,params:[t,e.config.metadata]})}async function a(e,{steps:t,metadata:n}){return await e.request({method:`frak_displayModal`,params:[t,n,e.config.metadata]})}async function o(e){return await e.request({method:`frak_getMerchantInformation`})}async function s(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function c(e,t){try{await e.request({method:`frak_sendInteraction`,params:[t]})}catch{console.warn(`[Frak SDK] Failed to send interaction:`,t.type)}}async function l(t,{walletStatus:r,frakContext:i,modalConfig:a,options:o}){if(!i?.r)return`no-referrer`;e.t(t,`user_referred_started`,{properties:{referrer:i?.r,walletStatus:r?.key}}),c(t,{type:`arrival`,referrerWallet:i.r,landingUrl:typeof window<`u`?window.location.href:void 0});let s=!1;async function l(){if(!s)return s=!0,d(t,{modalConfig:{...a,loggedIn:{action:{key:`referred`}}},walletStatus:r})}try{let{status:n,currentWallet:a}=await u({initialWalletStatus:r,getFreshWalletStatus:l,frakContext:i});return e.n.replaceUrl({url:window.location?.href,context:o?.alwaysAppendUrl?{r:a}:null}),e.t(t,`user_referred_completed`,{properties:{status:n,referrer:i?.r,wallet:a}}),n}catch(a){return console.log(`Error processing referral`,{error:a}),e.t(t,`user_referred_error`,{properties:{referrer:i?.r,error:a instanceof n.FrakRpcError?`[${a.code}] ${a.name} - ${a.message}`:a instanceof Error?a.message:`undefined`}}),e.n.replaceUrl({url:window.location?.href,context:o?.alwaysAppendUrl?{r:r?.wallet}:null}),f(a)}}async function u({initialWalletStatus:e,getFreshWalletStatus:n,frakContext:r}){let i=e?.wallet;return i||=await n(),i&&(0,t.isAddressEqual)(r.r,i)?{status:`self-referral`,currentWallet:i}:{status:`success`,currentWallet:i}}async function d(e,{modalConfig:t,walletStatus:n}){return n?.key===`connected`?n.wallet??void 0:(await i(e,t??{}))?.wallet??void 0}function f(e){if(e instanceof n.FrakRpcError)switch(e.code){case n.RpcErrorCodes.walletNotConnected:return`no-wallet`;default:return`error`}return`error`}async function p(t,{modalConfig:n,options:r}={}){let i=e.n.parse({url:window.location.href}),a=await h(t);try{return await l(t,{walletStatus:a,frakContext:i,modalConfig:n,options:r})}catch(e){console.warn(`Error processing referral`,{error:e})}}async function m(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`);if(!n){console.warn(`[Frak] No frak session found, skipping purchase check`);return}let r=e.r();await fetch(`${r}/interactions/listenForPurchase`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`,"x-wallet-sdk-auth":n},body:JSON.stringify(t)})}function h(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(g(e,t),t));let r=new n.Deferred,i=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},n=>{g(e,n),t(n),i||=(r.resolve(n),!0)}),r.promise}function g(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function _(e,{metadata:t,login:n}){return v(e,{steps:{login:n??{}},metadata:t})}function v(e,t){function n(n){return v(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return v(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return v(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function o(n){return n&&(t.metadata=n(t.metadata??{})),await a(e,t)}return{params:t,sendTx:n,reward:r,sharing:i,display:o}}async function y(e,{tx:t,metadata:n}){return(await a(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}async function b(e,{siwe:t,metadata:n}){let i=e.config?.domain??window.location.host,o=t?.statement??`I confirm that I want to use my Frak wallet on: ${e.config.metadata.name}`;return(await a(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:o,nonce:t?.nonce??(0,r.generateSiweNonce)(),uri:t?.uri??`https://${i}`,version:t?.version??`1`,domain:i}}}})).siweAuthenticate}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return o}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,r as t,t as n}from"./trackEvent-YfUh4jrx.js";import{isAddressEqual as r}from"viem";import{Deferred as i,FrakRpcError as a,RpcErrorCodes as o}from"@frak-labs/frame-connector";import{generateSiweNonce as s}from"viem/siwe";async function c(e,t){return await e.request({method:`frak_displayEmbeddedWallet`,params:[t,e.config.metadata]})}async function l(e,{steps:t,metadata:n}){return await e.request({method:`frak_displayModal`,params:[t,n,e.config.metadata]})}async function u(e){return await e.request({method:`frak_getMerchantInformation`})}async function d(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function f(e,t){try{await e.request({method:`frak_sendInteraction`,params:[t]})}catch{console.warn(`[Frak SDK] Failed to send interaction:`,t.type)}}async function p(t,{walletStatus:r,frakContext:i,modalConfig:o,options:s}){if(!i?.r)return`no-referrer`;n(t,`user_referred_started`,{properties:{referrer:i?.r,walletStatus:r?.key}}),f(t,{type:`arrival`,referrerWallet:i.r,landingUrl:typeof window<`u`?window.location.href:void 0});let c=!1;async function l(){if(!c)return c=!0,h(t,{modalConfig:{...o,loggedIn:{action:{key:`referred`}}},walletStatus:r})}try{let{status:a,currentWallet:o}=await m({initialWalletStatus:r,getFreshWalletStatus:l,frakContext:i});return e.replaceUrl({url:window.location?.href,context:s?.alwaysAppendUrl?{r:o}:null}),n(t,`user_referred_completed`,{properties:{status:a,referrer:i?.r,wallet:o}}),a}catch(o){return console.log(`Error processing referral`,{error:o}),n(t,`user_referred_error`,{properties:{referrer:i?.r,error:o instanceof a?`[${o.code}] ${o.name} - ${o.message}`:o instanceof Error?o.message:`undefined`}}),e.replaceUrl({url:window.location?.href,context:s?.alwaysAppendUrl?{r:r?.wallet}:null}),g(o)}}async function m({initialWalletStatus:e,getFreshWalletStatus:t,frakContext:n}){let i=e?.wallet;return i||=await t(),i&&r(n.r,i)?{status:`self-referral`,currentWallet:i}:{status:`success`,currentWallet:i}}async function h(e,{modalConfig:t,walletStatus:n}){return n?.key===`connected`?n.wallet??void 0:(await c(e,t??{}))?.wallet??void 0}function g(e){if(e instanceof a)switch(e.code){case o.walletNotConnected:return`no-wallet`;default:return`error`}return`error`}async function _(t,{modalConfig:n,options:r}={}){let i=e.parse({url:window.location.href}),a=await y(t);try{return await p(t,{walletStatus:a,frakContext:i,modalConfig:n,options:r})}catch(e){console.warn(`Error processing referral`,{error:e})}}async function v(e){if(typeof window>`u`){console.warn(`[Frak] No window found, can't track purchase`);return}let n=window.sessionStorage.getItem(`frak-wallet-interaction-token`);if(!n){console.warn(`[Frak] No frak session found, skipping purchase check`);return}let r=t();await fetch(`${r}/interactions/listenForPurchase`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`,"x-wallet-sdk-auth":n},body:JSON.stringify(e)})}function y(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(b(e,t),t));let n=new i,r=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},i=>{b(e,i),t(i),r||=(n.resolve(i),!0)}),n.promise}function b(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function x(e,{metadata:t,login:n}){return S(e,{steps:{login:n??{}},metadata:t})}function S(e,t){function n(n){return S(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return S(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return S(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function a(n){return n&&(t.metadata=n(t.metadata??{})),await l(e,t)}return{params:t,sendTx:n,reward:r,sharing:i,display:a}}async function C(e,{tx:t,metadata:n}){return(await l(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}async function w(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 l(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:i,nonce:t?.nonce??s(),uri:t?.uri??`https://${r}`,version:t?.version??`1`,domain:r}}}})).siweAuthenticate}export{v as a,f as c,l as d,c as f,y as i,d as l,C as n,_ as o,x as r,p as s,w as t,u};
|
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import { A as SiweAuthenticateReturnType, D as SendTransactionReturnType, E as SendTransactionModalStepType, F as PrepareSsoParamsType, I as PrepareSsoReturnType, M as LoginModalStepType, R as FinalActionType, S as ModalRpcMetadata, T as ModalStepTypes, a as FrakClient, d as GetMerchantInformationReturnType, g as DisplayEmbeddedWalletResultType, h as DisplayEmbeddedWalletParamsType, i as FrakContext, j as SiweAuthenticationParams, l as WalletStatusReturnType, m as SendInteractionParamsType, w as ModalRpcStepsResultType, x as DisplayModalParamsType, z as FinalModalStepType } from "./openSso-CC1-loUk.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/actions/displayEmbeddedWallet.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Function used to display the Frak embedded wallet popup
|
|
6
|
+
* @param client - The current Frak Client
|
|
7
|
+
* @param params - The parameter used to customise the embedded wallet
|
|
8
|
+
*/
|
|
9
|
+
declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbeddedWalletParamsType): Promise<DisplayEmbeddedWalletResultType>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/actions/displayModal.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Function used to display a modal
|
|
14
|
+
* @param client - The current Frak Client
|
|
15
|
+
* @param args
|
|
16
|
+
* @param args.steps - The different steps of the modal
|
|
17
|
+
* @param args.metadata - The metadata for the modal (customization, etc)
|
|
18
|
+
* @returns The result of each modal steps
|
|
19
|
+
*
|
|
20
|
+
* @description This function will display a modal to the user with the provided steps and metadata.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* - The UI of the displayed modal can be configured with the `customCss` property in the `customizations.css` field of the top-level config.
|
|
24
|
+
* - The `login` step will be automatically skipped if the user is already logged in. It's safe to include this step in all cases to ensure proper user state.
|
|
25
|
+
* - Steps are automatically reordered in the following sequence:
|
|
26
|
+
* 1. `login` (if needed)
|
|
27
|
+
* 2. All other steps in the order specified
|
|
28
|
+
* 3. `success` (if included, always last)
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* Simple sharing modal with steps:
|
|
32
|
+
* 1. Login (Skipped if already logged in)
|
|
33
|
+
* 2. Display a success message with sharing link option
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* const results = await displayModal(frakConfig, {
|
|
37
|
+
* steps: {
|
|
38
|
+
* // Simple login with no SSO, nor customization
|
|
39
|
+
* login: { allowSso: false },
|
|
40
|
+
* // Success message
|
|
41
|
+
* final: {
|
|
42
|
+
* action: { key: "reward" },
|
|
43
|
+
* // Skip this step, it will be only displayed in the stepper within the modal
|
|
44
|
+
* autoSkip: true,
|
|
45
|
+
* },
|
|
46
|
+
* },
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* console.log("Login step - wallet", results.login.wallet);
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* A full modal example, with a few customization options, with the steps:
|
|
54
|
+
* 1. Login (Skipped if already logged in)
|
|
55
|
+
* 2. Authenticate via SIWE
|
|
56
|
+
* 3. Send a transaction
|
|
57
|
+
* 4. Display a success message with sharing link options
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* const results = await displayModal(frakConfig, {
|
|
61
|
+
* steps: {
|
|
62
|
+
* // Login step
|
|
63
|
+
* login: {
|
|
64
|
+
* allowSso: true,
|
|
65
|
+
* ssoMetadata: {
|
|
66
|
+
* logoUrl: "https://my-app.com/logo.png",
|
|
67
|
+
* homepageLink: "https://my-app.com",
|
|
68
|
+
* },
|
|
69
|
+
* },
|
|
70
|
+
* // Siwe authentication
|
|
71
|
+
* siweAuthenticate: {
|
|
72
|
+
* siwe: {
|
|
73
|
+
* domain: "my-app.com",
|
|
74
|
+
* uri: "https://my-app.com/",
|
|
75
|
+
* nonce: generateSiweNonce(),
|
|
76
|
+
* version: "1",
|
|
77
|
+
* },
|
|
78
|
+
* },
|
|
79
|
+
* // Send batched transaction
|
|
80
|
+
* sendTransaction: {
|
|
81
|
+
* tx: [
|
|
82
|
+
* { to: "0xdeadbeef", data: "0xdeadbeef" },
|
|
83
|
+
* { to: "0xdeadbeef", data: "0xdeadbeef" },
|
|
84
|
+
* ],
|
|
85
|
+
* },
|
|
86
|
+
* // Success message with sharing options
|
|
87
|
+
* final: {
|
|
88
|
+
* action: {
|
|
89
|
+
* key: "sharing",
|
|
90
|
+
* options: {
|
|
91
|
+
* popupTitle: "Share the app",
|
|
92
|
+
* text: "Discover my super app website",
|
|
93
|
+
* link: "https://my-app.com",
|
|
94
|
+
* },
|
|
95
|
+
* },
|
|
96
|
+
* dismissedMetadata: {
|
|
97
|
+
* title: "Dismiss",
|
|
98
|
+
* description: "You won't be rewarded for this sharing action",
|
|
99
|
+
* },
|
|
100
|
+
* },
|
|
101
|
+
* },
|
|
102
|
+
* metadata: {
|
|
103
|
+
* // Header of desktop modals
|
|
104
|
+
* header: {
|
|
105
|
+
* title: "My-App",
|
|
106
|
+
* icon: "https://my-app.com/logo.png",
|
|
107
|
+
* },
|
|
108
|
+
* // Context that will be present in every modal steps
|
|
109
|
+
* context: "My-app overkill flow",
|
|
110
|
+
* },
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
declare function displayModal<T extends ModalStepTypes[] = ModalStepTypes[]>(client: FrakClient, {
|
|
115
|
+
steps,
|
|
116
|
+
metadata
|
|
117
|
+
}: DisplayModalParamsType<T>): Promise<ModalRpcStepsResultType<T>>;
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/actions/getMerchantInformation.d.ts
|
|
120
|
+
declare function getMerchantInformation(client: FrakClient): Promise<GetMerchantInformationReturnType>;
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/actions/prepareSso.d.ts
|
|
123
|
+
/**
|
|
124
|
+
* Generate SSO URL without opening popup
|
|
125
|
+
*
|
|
126
|
+
* This is a **synchronous**, client-side function that generates the SSO URL
|
|
127
|
+
* without any RPC calls to the wallet iframe. Use this when you need:
|
|
128
|
+
* - Custom URL modifications before opening popup
|
|
129
|
+
* - Pre-generation for advanced popup strategies
|
|
130
|
+
* - URL inspection/logging before SSO flow
|
|
131
|
+
*
|
|
132
|
+
* @param client - The current Frak Client
|
|
133
|
+
* @param args - The SSO parameters
|
|
134
|
+
* @returns Object containing the generated ssoUrl
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* // Generate URL for inspection
|
|
139
|
+
* const { ssoUrl } = prepareSso(client, {
|
|
140
|
+
* metadata: { logoUrl: "..." },
|
|
141
|
+
* directExit: true
|
|
142
|
+
* });
|
|
143
|
+
* console.log("Opening SSO:", ssoUrl);
|
|
144
|
+
*
|
|
145
|
+
* // Add custom params
|
|
146
|
+
* const customUrl = `${ssoUrl}&tracking=abc123`;
|
|
147
|
+
* await openSso(client, { metadata, ssoPopupUrl: customUrl });
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @remarks
|
|
151
|
+
* For most use cases, just use `openSso()` which handles URL generation automatically.
|
|
152
|
+
* Only use `prepareSso()` when you need explicit control over the URL.
|
|
153
|
+
*/
|
|
154
|
+
declare function prepareSso(client: FrakClient, args: PrepareSsoParamsType): Promise<PrepareSsoReturnType>;
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/actions/referral/processReferral.d.ts
|
|
157
|
+
/**
|
|
158
|
+
* The different states of the referral process
|
|
159
|
+
* @inline
|
|
160
|
+
*/
|
|
161
|
+
type ReferralState = "idle" | "processing" | "success" | "no-wallet" | "error" | "no-referrer" | "self-referral";
|
|
162
|
+
/**
|
|
163
|
+
* Options for the referral auto-interaction process
|
|
164
|
+
*/
|
|
165
|
+
type ProcessReferralOptions = {
|
|
166
|
+
/**
|
|
167
|
+
* If we want to always append the url with the frak context or not
|
|
168
|
+
* @defaultValue false
|
|
169
|
+
*/
|
|
170
|
+
alwaysAppendUrl?: boolean;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* This function handle all the heavy lifting of the referral interaction process
|
|
174
|
+
* 1. Check if the user has been referred or not (if not, early exit)
|
|
175
|
+
* 2. Then check if the user is logged in or not
|
|
176
|
+
* 2.1 If not logged in, try a soft login, if it fail, display a modal for the user to login
|
|
177
|
+
* 3. Check if that's not a self-referral (if yes, early exit)
|
|
178
|
+
* 4. Track the referral event
|
|
179
|
+
* 5. Update the current url with the right data
|
|
180
|
+
* 6. Return the resulting referral state
|
|
181
|
+
*
|
|
182
|
+
* If any error occurs during the process, the function will catch it and return an error state
|
|
183
|
+
*
|
|
184
|
+
* @param client - The current Frak Client
|
|
185
|
+
* @param args
|
|
186
|
+
* @param args.walletStatus - The current user wallet status
|
|
187
|
+
* @param args.frakContext - The current frak context
|
|
188
|
+
* @param args.modalConfig - The modal configuration to display if the user is not logged in
|
|
189
|
+
* @param args.options - Some options for the referral interaction
|
|
190
|
+
* @returns A promise with the resulting referral state
|
|
191
|
+
*
|
|
192
|
+
* @see {@link displayModal} for more details about the displayed modal
|
|
193
|
+
* @see {@link @frak-labs/core-sdk!ModalStepTypes} for more details on each modal steps types
|
|
194
|
+
*/
|
|
195
|
+
declare function processReferral(client: FrakClient, {
|
|
196
|
+
walletStatus,
|
|
197
|
+
frakContext,
|
|
198
|
+
modalConfig,
|
|
199
|
+
options
|
|
200
|
+
}: {
|
|
201
|
+
walletStatus?: WalletStatusReturnType;
|
|
202
|
+
frakContext?: Partial<FrakContext> | null;
|
|
203
|
+
modalConfig?: DisplayEmbeddedWalletParamsType;
|
|
204
|
+
options?: ProcessReferralOptions;
|
|
205
|
+
}): Promise<ReferralState>;
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/actions/referral/referralInteraction.d.ts
|
|
208
|
+
/**
|
|
209
|
+
* Function used to handle referral interactions
|
|
210
|
+
* @param client - The current Frak Client
|
|
211
|
+
* @param args
|
|
212
|
+
* @param args.modalConfig - The modal configuration to display if the user is not logged in
|
|
213
|
+
* @param args.options - Some options for the referral interaction
|
|
214
|
+
*
|
|
215
|
+
* @returns A promise with the resulting referral state, or undefined in case of an error
|
|
216
|
+
*
|
|
217
|
+
* @description This function will automatically handle the referral interaction process
|
|
218
|
+
*
|
|
219
|
+
* @see {@link processReferral} for more details on the automatic referral handling process
|
|
220
|
+
* @see {@link @frak-labs/core-sdk!ModalStepTypes} for more details on each modal steps types
|
|
221
|
+
*/
|
|
222
|
+
declare function referralInteraction(client: FrakClient, {
|
|
223
|
+
modalConfig,
|
|
224
|
+
options
|
|
225
|
+
}?: {
|
|
226
|
+
modalConfig?: DisplayEmbeddedWalletParamsType;
|
|
227
|
+
options?: ProcessReferralOptions;
|
|
228
|
+
}): Promise<("no-referrer" | "self-referral" | "success" | "idle" | "processing" | "no-wallet" | "error") | undefined>;
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/actions/sendInteraction.d.ts
|
|
231
|
+
/**
|
|
232
|
+
* Send an interaction to the backend via the listener RPC.
|
|
233
|
+
* Fire-and-forget: errors are caught and logged, not thrown.
|
|
234
|
+
*
|
|
235
|
+
* @param client - The Frak client instance
|
|
236
|
+
* @param params - The interaction parameters
|
|
237
|
+
*/
|
|
238
|
+
declare function sendInteraction(client: FrakClient, params: SendInteractionParamsType): Promise<void>;
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/actions/trackPurchaseStatus.d.ts
|
|
241
|
+
/**
|
|
242
|
+
* Function used to track the status of a purchase
|
|
243
|
+
* when a purchase is tracked, the `purchaseCompleted` interactions will be automatically send for the user when we receive the purchase confirmation via webhook.
|
|
244
|
+
*
|
|
245
|
+
* @param args.customerId - The customer id that made the purchase (on your side)
|
|
246
|
+
* @param args.orderId - The order id of the purchase (on your side)
|
|
247
|
+
* @param args.token - The token of the purchase
|
|
248
|
+
*
|
|
249
|
+
* @description This function will send a request to the backend to listen for the purchase status.
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* async function trackPurchase(checkout) {
|
|
253
|
+
* const payload = {
|
|
254
|
+
* customerId: checkout.order.customer.id,
|
|
255
|
+
* orderId: checkout.order.id,
|
|
256
|
+
* token: checkout.token,
|
|
257
|
+
* };
|
|
258
|
+
*
|
|
259
|
+
* await trackPurchaseStatus(payload);
|
|
260
|
+
* }
|
|
261
|
+
*
|
|
262
|
+
* @remarks
|
|
263
|
+
* - The `trackPurchaseStatus` function requires the `frak-wallet-interaction-token` stored in the session storage to authenticate the request.
|
|
264
|
+
* - This function will print a warning if used in a non-browser environment or if the wallet interaction token is not available.
|
|
265
|
+
*/
|
|
266
|
+
declare function trackPurchaseStatus(args: {
|
|
267
|
+
customerId: string | number;
|
|
268
|
+
orderId: string | number;
|
|
269
|
+
token: string;
|
|
270
|
+
}): Promise<void>;
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region src/actions/watchWalletStatus.d.ts
|
|
273
|
+
/**
|
|
274
|
+
* Function used to watch the current frak wallet status
|
|
275
|
+
* @param client - The current Frak Client
|
|
276
|
+
* @param callback - The callback that will receive any wallet status change
|
|
277
|
+
* @returns A promise resolving with the initial wallet status
|
|
278
|
+
*
|
|
279
|
+
* @description This function will return the current wallet status, and will listen to any change in the wallet status.
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* await watchWalletStatus(frakConfig, (status: WalletStatusReturnType) => {
|
|
283
|
+
* if (status.key === "connected") {
|
|
284
|
+
* console.log("Wallet connected:", status.wallet);
|
|
285
|
+
* } else {
|
|
286
|
+
* console.log("Wallet not connected");
|
|
287
|
+
* }
|
|
288
|
+
* });
|
|
289
|
+
*/
|
|
290
|
+
declare function watchWalletStatus(client: FrakClient, callback?: (status: WalletStatusReturnType) => void): Promise<WalletStatusReturnType>;
|
|
291
|
+
//#endregion
|
|
292
|
+
//#region src/actions/wrapper/modalBuilder.d.ts
|
|
293
|
+
/**
|
|
294
|
+
* Represent the type of the modal step builder
|
|
295
|
+
*/
|
|
296
|
+
type ModalStepBuilder<Steps extends ModalStepTypes[] = ModalStepTypes[]> = {
|
|
297
|
+
/**
|
|
298
|
+
* The current modal params
|
|
299
|
+
*/
|
|
300
|
+
params: DisplayModalParamsType<Steps>;
|
|
301
|
+
/**
|
|
302
|
+
* Add a send transaction step to the modal
|
|
303
|
+
*/
|
|
304
|
+
sendTx: (options: SendTransactionModalStepType["params"]) => ModalStepBuilder<[...Steps, SendTransactionModalStepType]>;
|
|
305
|
+
/**
|
|
306
|
+
* Add a final step of type reward to the modal
|
|
307
|
+
*/
|
|
308
|
+
reward: (options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
|
|
309
|
+
/**
|
|
310
|
+
* Add a final step of type sharing to the modal
|
|
311
|
+
*/
|
|
312
|
+
sharing: (sharingOptions?: Extract<FinalActionType, {
|
|
313
|
+
key: "sharing";
|
|
314
|
+
}>["options"], options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
|
|
315
|
+
/**
|
|
316
|
+
* Display the modal
|
|
317
|
+
* @param metadataOverride - Function returning optional metadata to override the current modal metadata
|
|
318
|
+
*/
|
|
319
|
+
display: (metadataOverride?: (current?: ModalRpcMetadata) => ModalRpcMetadata | undefined) => Promise<ModalRpcStepsResultType<Steps>>;
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* Represent the output type of the modal builder
|
|
323
|
+
*/
|
|
324
|
+
type ModalBuilder = ModalStepBuilder<[LoginModalStepType]>;
|
|
325
|
+
/**
|
|
326
|
+
* Helper to craft Frak modal, and share a base initial config
|
|
327
|
+
* @param client - The current Frak Client
|
|
328
|
+
* @param args
|
|
329
|
+
* @param args.metadata - Common modal metadata (customisation, language etc)
|
|
330
|
+
* @param args.login - Login step parameters
|
|
331
|
+
*
|
|
332
|
+
* @description This function will create a modal builder with the provided metadata and login parameters.
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* Here is an example of how to use the `modalBuilder` to create and display a sharing modal:
|
|
336
|
+
*
|
|
337
|
+
* ```js
|
|
338
|
+
* // Create the modal builder
|
|
339
|
+
* const modalBuilder = window.FrakSDK.modalBuilder(frakClient, baseModalConfig);
|
|
340
|
+
*
|
|
341
|
+
* // Configure the information to be shared via the sharing link
|
|
342
|
+
* const sharingConfig = {
|
|
343
|
+
* popupTitle: "Share this with your friends",
|
|
344
|
+
* text: "Discover our product!",
|
|
345
|
+
* link: window.location.href,
|
|
346
|
+
* };
|
|
347
|
+
*
|
|
348
|
+
* // Display the sharing modal
|
|
349
|
+
* function modalShare() {
|
|
350
|
+
* modalBuilder.sharing(sharingConfig).display();
|
|
351
|
+
* }
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* @see {@link ModalStepTypes} for more info about each modal step types and their parameters
|
|
355
|
+
* @see {@link ModalRpcMetadata} for more info about the metadata that can be passed to the modal
|
|
356
|
+
* @see {@link ModalRpcStepsResultType} for more info about the result of each modal steps
|
|
357
|
+
* @see {@link displayModal} for more info about how the modal is displayed
|
|
358
|
+
*/
|
|
359
|
+
declare function modalBuilder(client: FrakClient, {
|
|
360
|
+
metadata,
|
|
361
|
+
login
|
|
362
|
+
}: {
|
|
363
|
+
metadata?: ModalRpcMetadata;
|
|
364
|
+
login?: LoginModalStepType["params"];
|
|
365
|
+
}): ModalBuilder;
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/actions/wrapper/sendTransaction.d.ts
|
|
368
|
+
/**
|
|
369
|
+
* Parameters to directly show a modal used to send a transaction
|
|
370
|
+
* @inline
|
|
371
|
+
*/
|
|
372
|
+
type SendTransactionParams = {
|
|
373
|
+
/**
|
|
374
|
+
* The transaction to be sent (either a single tx or multiple ones)
|
|
375
|
+
*/
|
|
376
|
+
tx: SendTransactionModalStepType["params"]["tx"];
|
|
377
|
+
/**
|
|
378
|
+
* Custom metadata to be passed to the modal
|
|
379
|
+
*/
|
|
380
|
+
metadata?: ModalRpcMetadata;
|
|
381
|
+
};
|
|
382
|
+
/**
|
|
383
|
+
* Function used to send a user transaction, simple wrapper around the displayModal function to ease the send transaction process
|
|
384
|
+
* @param client - The current Frak Client
|
|
385
|
+
* @param args - The parameters
|
|
386
|
+
* @returns The hash of the transaction that was sent in a promise
|
|
387
|
+
*
|
|
388
|
+
* @description This function will display a modal to the user with the provided transaction and metadata.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* const { hash } = await sendTransaction(frakConfig, {
|
|
392
|
+
* tx: {
|
|
393
|
+
* to: "0xdeadbeef",
|
|
394
|
+
* value: toHex(100n),
|
|
395
|
+
* },
|
|
396
|
+
* metadata: {
|
|
397
|
+
* header: {
|
|
398
|
+
* title: "Sending eth",
|
|
399
|
+
* },
|
|
400
|
+
* context: "Send 100wei to 0xdeadbeef",
|
|
401
|
+
* },
|
|
402
|
+
* });
|
|
403
|
+
* console.log("Transaction hash:", hash);
|
|
404
|
+
*/
|
|
405
|
+
declare function sendTransaction(client: FrakClient, {
|
|
406
|
+
tx,
|
|
407
|
+
metadata
|
|
408
|
+
}: SendTransactionParams): Promise<SendTransactionReturnType>;
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region src/actions/wrapper/siweAuthenticate.d.ts
|
|
411
|
+
/**
|
|
412
|
+
* Parameter used to directly show a modal used to authenticate with SIWE
|
|
413
|
+
* @inline
|
|
414
|
+
*/
|
|
415
|
+
type SiweAuthenticateModalParams = {
|
|
416
|
+
/**
|
|
417
|
+
* Partial SIWE params, since we can rebuild them from the SDK if they are empty
|
|
418
|
+
*
|
|
419
|
+
* If no parameters provider, some fields will be recomputed from the current configuration and environment.
|
|
420
|
+
* - `statement` will be set to a default value
|
|
421
|
+
* - `nonce` will be generated
|
|
422
|
+
* - `uri` will be set to the current domain
|
|
423
|
+
* - `version` will be set to "1"
|
|
424
|
+
* - `domain` will be set to the current window domain
|
|
425
|
+
*
|
|
426
|
+
* @default {}
|
|
427
|
+
*/
|
|
428
|
+
siwe?: Partial<SiweAuthenticationParams>;
|
|
429
|
+
/**
|
|
430
|
+
* Custom metadata to be passed to the modal
|
|
431
|
+
*/
|
|
432
|
+
metadata?: ModalRpcMetadata;
|
|
433
|
+
};
|
|
434
|
+
/**
|
|
435
|
+
* Function used to launch a siwe authentication
|
|
436
|
+
* @param client - The current Frak Client
|
|
437
|
+
* @param args - The parameters
|
|
438
|
+
* @returns The SIWE authentication result (message + signature) in a promise
|
|
439
|
+
*
|
|
440
|
+
* @description This function will display a modal to the user with the provided SIWE parameters and metadata.
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* import { siweAuthenticate } from "@frak-labs/core-sdk/actions";
|
|
444
|
+
* import { parseSiweMessage } from "viem/siwe";
|
|
445
|
+
*
|
|
446
|
+
* const { signature, message } = await siweAuthenticate(frakConfig, {
|
|
447
|
+
* siwe: {
|
|
448
|
+
* statement: "Sign in to My App",
|
|
449
|
+
* domain: "my-app.com",
|
|
450
|
+
* expirationTimeTimestamp: Date.now() + 1000 * 60 * 5,
|
|
451
|
+
* },
|
|
452
|
+
* metadata: {
|
|
453
|
+
* header: {
|
|
454
|
+
* title: "Sign in",
|
|
455
|
+
* },
|
|
456
|
+
* context: "Sign in to My App",
|
|
457
|
+
* },
|
|
458
|
+
* });
|
|
459
|
+
* console.log("Parsed final message:", parseSiweMessage(message));
|
|
460
|
+
* console.log("Siwe signature:", signature);
|
|
461
|
+
*/
|
|
462
|
+
declare function siweAuthenticate(client: FrakClient, {
|
|
463
|
+
siwe,
|
|
464
|
+
metadata
|
|
465
|
+
}: SiweAuthenticateModalParams): Promise<SiweAuthenticateReturnType>;
|
|
466
|
+
//#endregion
|
|
467
|
+
export { displayEmbeddedWallet as _, ModalBuilder as a, watchWalletStatus as c, referralInteraction as d, ProcessReferralOptions as f, displayModal as g, getMerchantInformation as h, sendTransaction as i, trackPurchaseStatus as l, prepareSso as m, siweAuthenticate as n, ModalStepBuilder as o, processReferral as p, SendTransactionParams as r, modalBuilder as s, SiweAuthenticateModalParams as t, sendInteraction as u };
|