@frak-labs/core-sdk 0.1.1-beta.d96bc28d → 0.1.1-beta.df5fa6b3
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 -3
- package/dist/actions.cjs +1 -1
- package/dist/actions.d.cts +1 -1
- package/dist/actions.d.ts +1 -1
- package/dist/actions.js +1 -1
- package/dist/bundle.cjs +1 -1
- package/dist/bundle.d.cts +3 -3
- package/dist/bundle.d.ts +3 -3
- package/dist/bundle.js +1 -1
- package/dist/{computeLegacyProductId-WbD1gXV9.d.ts → computeLegacyProductId-CSSiQO4V.d.ts} +28 -15
- package/dist/{computeLegacyProductId-CscYhyUi.d.cts → computeLegacyProductId-fl_Sx8v5.d.cts} +28 -15
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/setupClient--zfx2pFM.cjs +13 -0
- package/dist/setupClient-CFQDaGKh.js +13 -0
- package/dist/siweAuthenticate-BKSiU7Ej.js +1 -0
- package/dist/{siweAuthenticate-udoruuy9.d.ts → siweAuthenticate-BOqz9Uww.d.ts} +46 -2
- package/dist/siweAuthenticate-CVMVEe3M.cjs +1 -0
- package/dist/{siweAuthenticate-CR4Dpji6.d.cts → siweAuthenticate-DfiQdngJ.d.cts} +46 -2
- package/dist/{trackEvent-YfUh4jrx.js → trackEvent-B0S5E6_h.js} +1 -1
- package/dist/{trackEvent-CGIryq5h.cjs → trackEvent-BbX2d3g_.cjs} +1 -1
- package/package.json +2 -2
- package/src/actions/displayEmbeddedWallet.ts +1 -0
- package/src/actions/getMerchantInformation.ts +7 -0
- package/src/actions/sendInteraction.ts +31 -0
- package/src/actions/trackPurchaseStatus.test.ts +354 -141
- package/src/actions/trackPurchaseStatus.ts +45 -11
- package/src/clients/createIFrameFrakClient.ts +2 -1
- package/src/clients/transports/iframeLifecycleManager.ts +58 -3
- package/src/index.ts +0 -1
- package/src/types/index.ts +0 -1
- package/src/utils/constants.ts +0 -5
- package/src/utils/deepLinkWithFallback.test.ts +2 -2
- package/src/utils/deepLinkWithFallback.ts +9 -3
- package/src/utils/formatAmount.ts +6 -0
- package/src/utils/merchantId.test.ts +90 -1
- package/src/utils/merchantId.ts +22 -1
- package/src/utils/sso.ts +2 -1
- package/src/utils/trackEvent.ts +10 -0
- package/dist/setupClient-BjIbK6XJ.cjs +0 -13
- package/dist/setupClient-D_HId3e2.js +0 -13
- package/dist/siweAuthenticate-B_Z2OZmj.cjs +0 -1
- package/dist/siweAuthenticate-CQ4OfPuA.js +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const e=require(`./trackEvent-BbX2d3g_.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;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}}const h=(()=>{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 g(e){e?localStorage.setItem(r,e):localStorage.removeItem(r)}function _(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.m(),pendingMergeToken:o,configDomain:i}},r),o&&(a.searchParams.delete(`fmt`),window.history.replaceState({},``,a.toString()))}function v(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 y(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 b(e){return e.includes(`/common/social`)}function x(e,t,n,r){if(u(t)){let i=v(t,r);l(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(h&&b(t))y(r);else{let e=v(t,r);window.location.href=e}}function S({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`:g(s.backup);break;case`remove-backup`:localStorage.removeItem(r);break;case`show`:case`hide`:p({iframe:e,isVisible:o===`show`});break;case`handshake`:_(e,s.token,n,i);break;case`redirect`:x(e,s.baseRedirectUrl,n,s.mergeToken);break}},isConnected:a.promise}}function C({config:e,iframe:r}){let i=e?.walletUrl??`https://wallet.frak.id`,a=S({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=w(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=T({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 w(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 T({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 E(n){return(0,t.jsonDecode)(e.f(n))}const D={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function O(e){return e&&e in D?e:`eur`}function k(e){return e?D[e]??D.eur:D.eur}function A(e,t){let n=k(t),r=O(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function j(e){return e?`${e}Amount`:`eurAmount`}async function M({config:e}){let t=N(e),n=await f({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=C({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function N(e){let t=O(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return f}});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import{f as e,m as t}from"./trackEvent-B0S5E6_h.js";import{Deferred as n,FrakRpcError as r,RpcErrorCodes as i,createRpcClient as a,jsonDecode as o}from"@frak-labs/frame-connector";import{OpenPanel as s}from"@openpanel/web";const c=`nexus-wallet-backup`,l=`frakwallet://`;function u(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 d=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(),i=`Unknown`;return e instanceof r?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: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: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 f(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}function p(e){return`intent://${e.slice(13)}#Intent;scheme=frakwallet;end`}function m(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=f()&&h(e)?p(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function h(e){return e.startsWith(l)}const g={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 _({walletBaseUrl:e,config:t}){let n=document.querySelector(`#frak-wallet`);n&&n.remove();let r=document.createElement(`iframe`);return r.id=g.id,r.name=g.name,r.allow=g.allow,r.style.zIndex=g.style.zIndex.toString(),v({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 v({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 y(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}}const b=(()=>{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 x(e){e?localStorage.setItem(c,e):localStorage.removeItem(c)}function S(e,n,r,i){let a=new URL(window.location.href),o=a.searchParams.get(`fmt`)??void 0;e.contentWindow?.postMessage({clientLifecycle:`handshake-response`,data:{token:n,currentUrl:window.location.href,clientId:t(),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){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 T(e){return e.includes(`/common/social`)}function E(e,t,n,r){if(h(t)){let i=C(t,r);m(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(b&&T(t))w(r);else{let e=C(t,r);window.location.href=e}}function D({iframe:e,targetOrigin:t,configDomain:r}){let i=new n;return{handleEvent:async n=>{if(!(`iframeLifecycle`in n))return;let{iframeLifecycle:a,data:o}=n;switch(a){case`connected`:i.resolve(!0);break;case`do-backup`:x(o.backup);break;case`remove-backup`:localStorage.removeItem(c);break;case`show`:case`hide`:v({iframe:e,isVisible:a===`show`});break;case`handshake`:S(e,o.token,t,r);break;case`redirect`:E(e,o.baseRedirectUrl,t,o.mergeToken);break}},isConnected:i.promise}}function O({config:e,iframe:t}){let n=e?.walletUrl??`https://wallet.frak.id`,o=D({iframe:t,targetOrigin:n,configDomain:e.domain}),c=new d(e,t);if(!t.contentWindow)throw new r(i.configError,`The iframe does not have a content window`);let l=a({emittingTransport:t.contentWindow,listeningTransport:window,targetOrigin:n,middleware:[{async onRequest(e,t){if(!await o.isConnected)throw new r(i.clientNotConnected,`The iframe provider isn't connected yet`);return t}},{onRequest(e,t){return c.setLastRequest(e),t},onResponse(e,t){return c.setLastResponse(e,t),t}}],lifecycleHandlers:{iframeLifecycle:async(e,t)=>{await o.handleEvent(e)}}}),u=k(l,o),f=async()=>{u(),l.cleanup(),t.remove()},p;console.log(`[Frak SDK] Initializing OpenPanel`),p=new s({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=A({config:e,rpcClient:l,lifecycleManager:o}).then(()=>c.updateSetupStatus(!0));return{config:e,debugInfo:c,waitForConnection:o.isConnected,waitForSetup:m,request:l.request,listenerRequest:l.listen,destroy:f,openPanel:p}}function k(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 A({config:e,rpcClient:t,lifecycleManager:n}){await n.isConnected,u(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(c);if(!e)return;let n={clientLifecycle:`restore-backup`,data:{backup:e}};t.sendLifecycle(n)}await Promise.allSettled([r(),i(),a()])}function j(t){return o(e(t))}const M={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function N(e){return e&&e in M?e:`eur`}function P(e){return e?M[e]??M.eur:M.eur}function F(e,t){let n=P(t),r=N(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function I(e){return e?`${e}Amount`:`eurAmount`}async function L({config:e}){let t=R(e),n=await _({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=O({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function R(e){let t=N(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}export{l as _,N as a,O as c,y as d,f,d as g,m as h,P as i,g as l,p as m,I as n,M as o,h as p,F as r,j as s,L as t,_ as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,m as t,o as n,r,t as i}from"./trackEvent-B0S5E6_h.js";import{isAddressEqual as a}from"viem";import{Deferred as o,FrakRpcError as s,RpcErrorCodes as c}from"@frak-labs/frame-connector";import{generateSiweNonce as l}from"viem/siwe";async function u(e,t){return await e.request({method:`frak_displayEmbeddedWallet`,params:[t,e.config.metadata]})}async function d(e,{steps:t,metadata:n}){return await e.request({method:`frak_displayModal`,params:[t,n,e.config.metadata]})}async function f(e){return await e.request({method:`frak_getMerchantInformation`})}async function p(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function m(e,t){try{await e.request({method:`frak_sendInteraction`,params:[t]})}catch{console.warn(`[Frak SDK] Failed to send interaction:`,t.type)}}async function h(t,{walletStatus:n,frakContext:r,modalConfig:a,options:o}){if(!r?.r)return`no-referrer`;i(t,`user_referred_started`,{properties:{referrer:r?.r,walletStatus:n?.key}}),m(t,{type:`arrival`,referrerWallet:r.r,landingUrl:typeof window<`u`?window.location.href:void 0});let c=!1;async function l(){if(!c)return c=!0,_(t,{modalConfig:{...a,loggedIn:{action:{key:`referred`}}},walletStatus:n})}try{let{status:a,currentWallet:s}=await g({initialWalletStatus:n,getFreshWalletStatus:l,frakContext:r});return e.replaceUrl({url:window.location?.href,context:o?.alwaysAppendUrl?{r:s}:null}),i(t,`user_referred_completed`,{properties:{status:a,referrer:r?.r,wallet:s}}),a}catch(a){return console.log(`Error processing referral`,{error:a}),i(t,`user_referred_error`,{properties:{referrer:r?.r,error:a instanceof s?`[${a.code}] ${a.name} - ${a.message}`:a instanceof Error?a.message:`undefined`}}),e.replaceUrl({url:window.location?.href,context:o?.alwaysAppendUrl?{r:n?.wallet}:null}),v(a)}}async function g({initialWalletStatus:e,getFreshWalletStatus:t,frakContext:n}){let r=e?.wallet;return r||=await t(),r&&a(n.r,r)?{status:`self-referral`,currentWallet:r}:{status:`success`,currentWallet:r}}async function _(e,{modalConfig:t,walletStatus:n}){return n?.key===`connected`?n.wallet??void 0:(await u(e,t??{}))?.wallet??void 0}function v(e){if(e instanceof s)switch(e.code){case c.walletNotConnected:return`no-wallet`;default:return`error`}return`error`}async function y(t,{modalConfig:n,options:r}={}){let i=e.parse({url:window.location.href}),a=await x(t);try{return await h(t,{walletStatus:a,frakContext:i,modalConfig:n,options:r})}catch(e){console.warn(`Error processing referral`,{error:e})}}async function b(e){if(typeof window>`u`){console.warn(`[Frak] No window found, can't track purchase`);return}let i=window.sessionStorage.getItem(`frak-wallet-interaction-token`),a=t();if(!i&&!a){console.warn(`[Frak] No identity found, skipping purchase check`);return}let o=window.sessionStorage.getItem(`frak-merchant-id`),s=e.merchantId??o??await r();if(!s){console.warn(`[Frak] No merchant id found, skipping purchase check`);return}let c={Accept:`application/json`,"Content-Type":`application/json`};i&&(c[`x-wallet-sdk-auth`]=i),a&&(c[`x-frak-client-id`]=a);let l=n();await fetch(`${l}/user/track/purchase`,{method:`POST`,headers:c,body:JSON.stringify({customerId:e.customerId,orderId:e.orderId,token:e.token,merchantId:s})})}function x(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(S(e,t),t));let n=new o,r=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},i=>{S(e,i),t(i),r||=(n.resolve(i),!0)}),n.promise}function S(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 C(e,{metadata:t,login:n}){return w(e,{steps:{login:n??{}},metadata:t})}function w(e,t){function n(n){return w(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return w(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return w(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function a(n){return n&&(t.metadata=n(t.metadata??{})),await d(e,t)}return{params:t,sendTx:n,reward:r,sharing:i,display:a}}async function T(e,{tx:t,metadata:n}){return(await d(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}async function E(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??l(),uri:t?.uri??`https://${r}`,version:t?.version??`1`,domain:r}}}})).siweAuthenticate}export{b as a,m as c,d,u as f,x as i,p as l,T as n,y as o,C as r,h as s,E as t,f as u};
|
|
@@ -5,6 +5,7 @@ import { A as SiweAuthenticateReturnType, D as SendTransactionReturnType, E as S
|
|
|
5
5
|
* Function used to display the Frak embedded wallet popup
|
|
6
6
|
* @param client - The current Frak Client
|
|
7
7
|
* @param params - The parameter used to customise the embedded wallet
|
|
8
|
+
* @returns The embedded wallet display result
|
|
8
9
|
*/
|
|
9
10
|
declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbeddedWalletParamsType): Promise<DisplayEmbeddedWalletResultType>;
|
|
10
11
|
//#endregion
|
|
@@ -117,6 +118,13 @@ declare function displayModal<T extends ModalStepTypes[] = ModalStepTypes[]>(cli
|
|
|
117
118
|
}: DisplayModalParamsType<T>): Promise<ModalRpcStepsResultType<T>>;
|
|
118
119
|
//#endregion
|
|
119
120
|
//#region src/actions/getMerchantInformation.d.ts
|
|
121
|
+
/**
|
|
122
|
+
* Fetch the current merchant information (name, rewards, tiers) from the wallet iframe
|
|
123
|
+
* @param client - The current Frak Client
|
|
124
|
+
* @returns The merchant information including available reward tiers
|
|
125
|
+
*
|
|
126
|
+
* @see {@link @frak-labs/core-sdk!index.GetMerchantInformationReturnType | `GetMerchantInformationReturnType`} for the return type shape
|
|
127
|
+
*/
|
|
120
128
|
declare function getMerchantInformation(client: FrakClient): Promise<GetMerchantInformationReturnType>;
|
|
121
129
|
//#endregion
|
|
122
130
|
//#region src/actions/prepareSso.d.ts
|
|
@@ -234,6 +242,37 @@ declare function referralInteraction(client: FrakClient, {
|
|
|
234
242
|
*
|
|
235
243
|
* @param client - The Frak client instance
|
|
236
244
|
* @param params - The interaction parameters
|
|
245
|
+
*
|
|
246
|
+
* @description Sends a user interaction event through the wallet iframe RPC. Supports three interaction types: arrival tracking, sharing events, and custom interactions.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* Track a user arrival with referral attribution:
|
|
250
|
+
* ```ts
|
|
251
|
+
* await sendInteraction(client, {
|
|
252
|
+
* type: "arrival",
|
|
253
|
+
* referrerWallet: "0x1234...abcd",
|
|
254
|
+
* landingUrl: window.location.href,
|
|
255
|
+
* utmSource: "twitter",
|
|
256
|
+
* utmMedium: "social",
|
|
257
|
+
* utmCampaign: "launch-2026",
|
|
258
|
+
* });
|
|
259
|
+
* ```
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* Track a sharing event:
|
|
263
|
+
* ```ts
|
|
264
|
+
* await sendInteraction(client, { type: "sharing" });
|
|
265
|
+
* ```
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* Send a custom interaction:
|
|
269
|
+
* ```ts
|
|
270
|
+
* await sendInteraction(client, {
|
|
271
|
+
* type: "custom",
|
|
272
|
+
* customType: "newsletter_signup",
|
|
273
|
+
* data: { email: "user@example.com" },
|
|
274
|
+
* });
|
|
275
|
+
* ```
|
|
237
276
|
*/
|
|
238
277
|
declare function sendInteraction(client: FrakClient, params: SendInteractionParamsType): Promise<void>;
|
|
239
278
|
//#endregion
|
|
@@ -245,6 +284,7 @@ declare function sendInteraction(client: FrakClient, params: SendInteractionPara
|
|
|
245
284
|
* @param args.customerId - The customer id that made the purchase (on your side)
|
|
246
285
|
* @param args.orderId - The order id of the purchase (on your side)
|
|
247
286
|
* @param args.token - The token of the purchase
|
|
287
|
+
* @param args.merchantId - Optional explicit merchant id to use for the tracking request
|
|
248
288
|
*
|
|
249
289
|
* @description This function will send a request to the backend to listen for the purchase status.
|
|
250
290
|
*
|
|
@@ -254,19 +294,23 @@ declare function sendInteraction(client: FrakClient, params: SendInteractionPara
|
|
|
254
294
|
* customerId: checkout.order.customer.id,
|
|
255
295
|
* orderId: checkout.order.id,
|
|
256
296
|
* token: checkout.token,
|
|
297
|
+
* merchantId: "your-merchant-id",
|
|
257
298
|
* };
|
|
258
299
|
*
|
|
259
300
|
* await trackPurchaseStatus(payload);
|
|
260
301
|
* }
|
|
261
302
|
*
|
|
262
303
|
* @remarks
|
|
263
|
-
* -
|
|
264
|
-
* - This function
|
|
304
|
+
* - Merchant id is resolved in this order: explicit `args.merchantId`, `frak-merchant-id` from session storage, then `fetchMerchantId()`.
|
|
305
|
+
* - This function supports anonymous users and will use the `x-frak-client-id` header when available.
|
|
306
|
+
* - At least one identity source must exist (`frak-wallet-interaction-token` or `x-frak-client-id`), otherwise the tracking request is skipped.
|
|
307
|
+
* - This function will print a warning if used in a non-browser environment or if no identity / merchant id can be resolved.
|
|
265
308
|
*/
|
|
266
309
|
declare function trackPurchaseStatus(args: {
|
|
267
310
|
customerId: string | number;
|
|
268
311
|
orderId: string | number;
|
|
269
312
|
token: string;
|
|
313
|
+
merchantId?: string;
|
|
270
314
|
}): Promise<void>;
|
|
271
315
|
//#endregion
|
|
272
316
|
//#region src/actions/watchWalletStatus.d.ts
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./trackEvent-BbX2d3g_.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.a.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.a.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.a.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`),r=e.m();if(!n&&!r){console.warn(`[Frak] No identity found, skipping purchase check`);return}let i=window.sessionStorage.getItem(`frak-merchant-id`),a=t.merchantId??i??await e.r();if(!a){console.warn(`[Frak] No merchant id found, skipping purchase check`);return}let o={Accept:`application/json`,"Content-Type":`application/json`};n&&(o[`x-wallet-sdk-auth`]=n),r&&(o[`x-frak-client-id`]=r);let s=e.o();await fetch(`${s}/user/track/purchase`,{method:`POST`,headers:o,body:JSON.stringify({customerId:t.customerId,orderId:t.orderId,token:t.token,merchantId:a})})}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}});
|
|
@@ -5,6 +5,7 @@ import { A as SiweAuthenticateReturnType, D as SendTransactionReturnType, E as S
|
|
|
5
5
|
* Function used to display the Frak embedded wallet popup
|
|
6
6
|
* @param client - The current Frak Client
|
|
7
7
|
* @param params - The parameter used to customise the embedded wallet
|
|
8
|
+
* @returns The embedded wallet display result
|
|
8
9
|
*/
|
|
9
10
|
declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbeddedWalletParamsType): Promise<DisplayEmbeddedWalletResultType>;
|
|
10
11
|
//#endregion
|
|
@@ -117,6 +118,13 @@ declare function displayModal<T extends ModalStepTypes[] = ModalStepTypes[]>(cli
|
|
|
117
118
|
}: DisplayModalParamsType<T>): Promise<ModalRpcStepsResultType<T>>;
|
|
118
119
|
//#endregion
|
|
119
120
|
//#region src/actions/getMerchantInformation.d.ts
|
|
121
|
+
/**
|
|
122
|
+
* Fetch the current merchant information (name, rewards, tiers) from the wallet iframe
|
|
123
|
+
* @param client - The current Frak Client
|
|
124
|
+
* @returns The merchant information including available reward tiers
|
|
125
|
+
*
|
|
126
|
+
* @see {@link @frak-labs/core-sdk!index.GetMerchantInformationReturnType | `GetMerchantInformationReturnType`} for the return type shape
|
|
127
|
+
*/
|
|
120
128
|
declare function getMerchantInformation(client: FrakClient): Promise<GetMerchantInformationReturnType>;
|
|
121
129
|
//#endregion
|
|
122
130
|
//#region src/actions/prepareSso.d.ts
|
|
@@ -234,6 +242,37 @@ declare function referralInteraction(client: FrakClient, {
|
|
|
234
242
|
*
|
|
235
243
|
* @param client - The Frak client instance
|
|
236
244
|
* @param params - The interaction parameters
|
|
245
|
+
*
|
|
246
|
+
* @description Sends a user interaction event through the wallet iframe RPC. Supports three interaction types: arrival tracking, sharing events, and custom interactions.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* Track a user arrival with referral attribution:
|
|
250
|
+
* ```ts
|
|
251
|
+
* await sendInteraction(client, {
|
|
252
|
+
* type: "arrival",
|
|
253
|
+
* referrerWallet: "0x1234...abcd",
|
|
254
|
+
* landingUrl: window.location.href,
|
|
255
|
+
* utmSource: "twitter",
|
|
256
|
+
* utmMedium: "social",
|
|
257
|
+
* utmCampaign: "launch-2026",
|
|
258
|
+
* });
|
|
259
|
+
* ```
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* Track a sharing event:
|
|
263
|
+
* ```ts
|
|
264
|
+
* await sendInteraction(client, { type: "sharing" });
|
|
265
|
+
* ```
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* Send a custom interaction:
|
|
269
|
+
* ```ts
|
|
270
|
+
* await sendInteraction(client, {
|
|
271
|
+
* type: "custom",
|
|
272
|
+
* customType: "newsletter_signup",
|
|
273
|
+
* data: { email: "user@example.com" },
|
|
274
|
+
* });
|
|
275
|
+
* ```
|
|
237
276
|
*/
|
|
238
277
|
declare function sendInteraction(client: FrakClient, params: SendInteractionParamsType): Promise<void>;
|
|
239
278
|
//#endregion
|
|
@@ -245,6 +284,7 @@ declare function sendInteraction(client: FrakClient, params: SendInteractionPara
|
|
|
245
284
|
* @param args.customerId - The customer id that made the purchase (on your side)
|
|
246
285
|
* @param args.orderId - The order id of the purchase (on your side)
|
|
247
286
|
* @param args.token - The token of the purchase
|
|
287
|
+
* @param args.merchantId - Optional explicit merchant id to use for the tracking request
|
|
248
288
|
*
|
|
249
289
|
* @description This function will send a request to the backend to listen for the purchase status.
|
|
250
290
|
*
|
|
@@ -254,19 +294,23 @@ declare function sendInteraction(client: FrakClient, params: SendInteractionPara
|
|
|
254
294
|
* customerId: checkout.order.customer.id,
|
|
255
295
|
* orderId: checkout.order.id,
|
|
256
296
|
* token: checkout.token,
|
|
297
|
+
* merchantId: "your-merchant-id",
|
|
257
298
|
* };
|
|
258
299
|
*
|
|
259
300
|
* await trackPurchaseStatus(payload);
|
|
260
301
|
* }
|
|
261
302
|
*
|
|
262
303
|
* @remarks
|
|
263
|
-
* -
|
|
264
|
-
* - This function
|
|
304
|
+
* - Merchant id is resolved in this order: explicit `args.merchantId`, `frak-merchant-id` from session storage, then `fetchMerchantId()`.
|
|
305
|
+
* - This function supports anonymous users and will use the `x-frak-client-id` header when available.
|
|
306
|
+
* - At least one identity source must exist (`frak-wallet-interaction-token` or `x-frak-client-id`), otherwise the tracking request is skipped.
|
|
307
|
+
* - This function will print a warning if used in a non-browser environment or if no identity / merchant id can be resolved.
|
|
265
308
|
*/
|
|
266
309
|
declare function trackPurchaseStatus(args: {
|
|
267
310
|
customerId: string | number;
|
|
268
311
|
orderId: string | number;
|
|
269
312
|
token: string;
|
|
313
|
+
merchantId?: string;
|
|
270
314
|
}): Promise<void>;
|
|
271
315
|
//#endregion
|
|
272
316
|
//#region src/actions/watchWalletStatus.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{bytesToHex as e,hexToBytes as t,keccak256 as n,toHex as r}from"viem";import{jsonEncode as i}from"@frak-labs/frame-connector";function a({domain:e}={}){return n(r((e??window.location.host).replace(`www.`,``)))}const o=`frak-client-id`;function s(){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 c(){if(typeof window>`u`||!window.localStorage)return s();let e=localStorage.getItem(o);return e||(e=s(),localStorage.setItem(o,e)),e}function l(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function u(e){let t=e.length%4;return Uint8Array.from(atob(e.replace(/-/g,`+`).replace(/_/g,`/`).padEnd(e.length+(t===0?0:4-t),`=`)),e=>e.charCodeAt(0))}function d(e){return l(i(e))}function f(e,t,n,r,i,a){let o=d(p({redirectUrl:t.redirectUrl,directExit:t.directExit,lang:t.lang,merchantId:n,metadata:{name:r,css:i,logoUrl:t.metadata?.logoUrl,homepageLink:t.metadata?.homepageLink},clientId:a??c()})),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 m=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,h=`frak-sso`;async function g(e,t){let{metadata:n,customizations:r,walletUrl:i}=e.config;if(t.openInSameWindow??!!t.redirectUrl)return await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]});let o=t.ssoPopupUrl??f(i??`https://wallet.frak.id`,t,a(),n.name,r?.css),s=window.open(o,h,m);if(!s)throw Error(`Popup was blocked. Please allow popups for this site.`);return s.focus(),await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]})??{}}const _=`https://backend.frak.id`;function v(e){return e.includes(`localhost:3000`)||e.includes(`localhost:3010`)}function y(e){return v(e)?`http://localhost:3030`:e.includes(`wallet-dev.frak.id`)||e.includes(`wallet.gcp-dev.frak.id`)?`https://backend.gcp-dev.frak.id`:_}function b(e){if(e)return y(e);if(typeof window<`u`){let e=window.FrakSetup?.client?.config?.walletUrl;if(e)return y(e)}return _}const x=`fCtx`;function S(e){if(e?.r)try{return l(t(e.r))}catch(t){console.error(`Error compressing Frak context`,{e:t,context:e})}}function C(t){if(!(!t||t.length===0))try{return{r:e(u(t),{size:20})}}catch(e){console.error(`Error decompressing Frak context`,{e,context:t})}}function w({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(x);return t?C(t):null}function T({url:e,context:t}){if(!e)return null;let n=w({url:e}),r=n?{...n,...t}:t;if(!r.r)return null;let i=S(r);if(!i)return null;let a=new URL(e);return a.searchParams.set(x,i),a.toString()}function E(e){let t=new URL(e);return t.searchParams.delete(x),t.toString()}function D({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?E(n):T({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}const O={compress:S,decompress:C,parse:w,update:T,remove:E,replaceUrl:D};function k(e,t,n={}){if(!e){console.debug(`[Frak] No client provided, skipping event tracking`);return}try{e.openPanel?.track(t,n)}catch(e){console.debug(`[Frak] Failed to track event:`,t,e)}}export{
|
|
1
|
+
import{bytesToHex as e,hexToBytes as t,keccak256 as n,toHex as r}from"viem";import{jsonEncode as i}from"@frak-labs/frame-connector";function a({domain:e}={}){return n(r((e??window.location.host).replace(`www.`,``)))}const o=`frak-client-id`;function s(){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 c(){if(typeof window>`u`||!window.localStorage)return s();let e=localStorage.getItem(o);return e||(e=s(),localStorage.setItem(o,e)),e}function l(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function u(e){let t=e.length%4;return Uint8Array.from(atob(e.replace(/-/g,`+`).replace(/_/g,`/`).padEnd(e.length+(t===0?0:4-t),`=`)),e=>e.charCodeAt(0))}function d(e){return l(i(e))}function f(e,t,n,r,i,a){let o=d(p({redirectUrl:t.redirectUrl,directExit:t.directExit,lang:t.lang,merchantId:n,metadata:{name:r,css:i,logoUrl:t.metadata?.logoUrl,homepageLink:t.metadata?.homepageLink},clientId:a??c()})),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 m=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,h=`frak-sso`;async function g(e,t){let{metadata:n,customizations:r,walletUrl:i}=e.config;if(t.openInSameWindow??!!t.redirectUrl)return await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]});let o=t.ssoPopupUrl??f(i??`https://wallet.frak.id`,t,a(),n.name,r?.css),s=window.open(o,h,m);if(!s)throw Error(`Popup was blocked. Please allow popups for this site.`);return s.focus(),await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]})??{}}const _=`https://backend.frak.id`;function v(e){return e.includes(`localhost:3000`)||e.includes(`localhost:3010`)}function y(e){return v(e)?`http://localhost:3030`:e.includes(`wallet-dev.frak.id`)||e.includes(`wallet.gcp-dev.frak.id`)?`https://backend.gcp-dev.frak.id`:_}function b(e){if(e)return y(e);if(typeof window<`u`){let e=window.FrakSetup?.client?.config?.walletUrl;if(e)return y(e)}return _}const x=`fCtx`;function S(e){if(e?.r)try{return l(t(e.r))}catch(t){console.error(`Error compressing Frak context`,{e:t,context:e})}}function C(t){if(!(!t||t.length===0))try{return{r:e(u(t),{size:20})}}catch(e){console.error(`Error decompressing Frak context`,{e,context:t})}}function w({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(x);return t?C(t):null}function T({url:e,context:t}){if(!e)return null;let n=w({url:e}),r=n?{...n,...t}:t;if(!r.r)return null;let i=S(r);if(!i)return null;let a=new URL(e);return a.searchParams.set(x,i),a.toString()}function E(e){let t=new URL(e);return t.searchParams.delete(x),t.toString()}function D({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?E(n):T({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}const O={compress:S,decompress:C,parse:w,update:T,remove:E,replaceUrl:D},k=`frak-merchant-id`;let A,j;async function M(e,t){if(A)return A;if(typeof window<`u`){let e=window.sessionStorage.getItem(k);if(e)return A=e,e}if(j)return j;j=N(e,t);let n=await j;return j=void 0,n}async function N(e,t){let n=e??(typeof window<`u`?window.location.hostname:``);if(n)try{let e=b(t),r=await fetch(`${e}/user/merchant/resolve?domain=${encodeURIComponent(n)}`);if(!r.ok){console.warn(`[Frak SDK] Merchant lookup failed for domain ${n}: ${r.status}`);return}let i=await r.json();return A=i.merchantId,typeof window<`u`&&window.sessionStorage.setItem(k,i.merchantId),A}catch(e){console.warn(`[Frak SDK] Failed to fetch merchantId:`,e);return}}function P(){A=void 0,j=void 0,typeof window<`u`&&window.sessionStorage.removeItem(k)}async function F(e,t){return e.metadata?.merchantId?e.metadata.merchantId:M(void 0,t)}function I(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)}}export{O as a,m as c,d,u as f,a as h,F as i,h as l,c as m,P as n,b as o,l as p,M as r,g as s,I as t,f as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
let e=require(`viem`),t=require(`@frak-labs/frame-connector`);function n({domain:t}={}){return(0,e.keccak256)((0,e.toHex)((t??window.location.host).replace(`www.`,``)))}const r=`frak-client-id`;function i(){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 a(){if(typeof window>`u`||!window.localStorage)return i();let e=localStorage.getItem(r);return e||(e=i(),localStorage.setItem(r,e)),e}function o(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function s(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 c(e){return o((0,t.jsonEncode)(e))}function l(e,t,n,r,i,o){let s=c(u({redirectUrl:t.redirectUrl,directExit:t.directExit,lang:t.lang,merchantId:n,metadata:{name:r,css:i,logoUrl:t.metadata?.logoUrl,homepageLink:t.metadata?.homepageLink},clientId:o??a()})),l=new URL(e);return l.pathname=`/sso`,l.searchParams.set(`p`,s),l.toString()}function u(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 d=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,f=`frak-sso`;async function p(e,t){let{metadata:r,customizations:i,walletUrl:a}=e.config;if(t.openInSameWindow??!!t.redirectUrl)return await e.request({method:`frak_openSso`,params:[t,r.name,i?.css]});let o=t.ssoPopupUrl??l(a??`https://wallet.frak.id`,t,n(),r.name,i?.css),s=window.open(o,f,d);if(!s)throw Error(`Popup was blocked. Please allow popups for this site.`);return s.focus(),await e.request({method:`frak_openSso`,params:[t,r.name,i?.css]})??{}}const m=`https://backend.frak.id`;function h(e){return e.includes(`localhost:3000`)||e.includes(`localhost:3010`)}function g(e){return h(e)?`http://localhost:3030`:e.includes(`wallet-dev.frak.id`)||e.includes(`wallet.gcp-dev.frak.id`)?`https://backend.gcp-dev.frak.id`:m}function _(e){if(e)return g(e);if(typeof window<`u`){let e=window.FrakSetup?.client?.config?.walletUrl;if(e)return g(e)}return m}const v=`fCtx`;function y(t){if(t?.r)try{return o((0,e.hexToBytes)(t.r))}catch(e){console.error(`Error compressing Frak context`,{e,context:t})}}function b(t){if(!(!t||t.length===0))try{return{r:(0,e.bytesToHex)(s(t),{size:20})}}catch(e){console.error(`Error decompressing Frak context`,{e,context:t})}}function x({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(v);return t?b(t):null}function S({url:e,context:t}){if(!e)return null;let n=x({url:e}),r=n?{...n,...t}:t;if(!r.r)return null;let i=y(r);if(!i)return null;let a=new URL(e);return a.searchParams.set(v,i),a.toString()}function C(e){let t=new URL(e);return t.searchParams.delete(v),t.toString()}function w({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?C(n):S({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}const T={compress:y,decompress:b,parse:x,update:S,remove:C,replaceUrl:w};function E(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)}}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return
|
|
1
|
+
let e=require(`viem`),t=require(`@frak-labs/frame-connector`);function n({domain:t}={}){return(0,e.keccak256)((0,e.toHex)((t??window.location.host).replace(`www.`,``)))}const r=`frak-client-id`;function i(){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 a(){if(typeof window>`u`||!window.localStorage)return i();let e=localStorage.getItem(r);return e||(e=i(),localStorage.setItem(r,e)),e}function o(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function s(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 c(e){return o((0,t.jsonEncode)(e))}function l(e,t,n,r,i,o){let s=c(u({redirectUrl:t.redirectUrl,directExit:t.directExit,lang:t.lang,merchantId:n,metadata:{name:r,css:i,logoUrl:t.metadata?.logoUrl,homepageLink:t.metadata?.homepageLink},clientId:o??a()})),l=new URL(e);return l.pathname=`/sso`,l.searchParams.set(`p`,s),l.toString()}function u(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 d=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,f=`frak-sso`;async function p(e,t){let{metadata:r,customizations:i,walletUrl:a}=e.config;if(t.openInSameWindow??!!t.redirectUrl)return await e.request({method:`frak_openSso`,params:[t,r.name,i?.css]});let o=t.ssoPopupUrl??l(a??`https://wallet.frak.id`,t,n(),r.name,i?.css),s=window.open(o,f,d);if(!s)throw Error(`Popup was blocked. Please allow popups for this site.`);return s.focus(),await e.request({method:`frak_openSso`,params:[t,r.name,i?.css]})??{}}const m=`https://backend.frak.id`;function h(e){return e.includes(`localhost:3000`)||e.includes(`localhost:3010`)}function g(e){return h(e)?`http://localhost:3030`:e.includes(`wallet-dev.frak.id`)||e.includes(`wallet.gcp-dev.frak.id`)?`https://backend.gcp-dev.frak.id`:m}function _(e){if(e)return g(e);if(typeof window<`u`){let e=window.FrakSetup?.client?.config?.walletUrl;if(e)return g(e)}return m}const v=`fCtx`;function y(t){if(t?.r)try{return o((0,e.hexToBytes)(t.r))}catch(e){console.error(`Error compressing Frak context`,{e,context:t})}}function b(t){if(!(!t||t.length===0))try{return{r:(0,e.bytesToHex)(s(t),{size:20})}}catch(e){console.error(`Error decompressing Frak context`,{e,context:t})}}function x({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(v);return t?b(t):null}function S({url:e,context:t}){if(!e)return null;let n=x({url:e}),r=n?{...n,...t}:t;if(!r.r)return null;let i=y(r);if(!i)return null;let a=new URL(e);return a.searchParams.set(v,i),a.toString()}function C(e){let t=new URL(e);return t.searchParams.delete(v),t.toString()}function w({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?C(n):S({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}const T={compress:y,decompress:b,parse:x,update:S,remove:C,replaceUrl:w},E=`frak-merchant-id`;let D,O;async function k(e,t){if(D)return D;if(typeof window<`u`){let e=window.sessionStorage.getItem(E);if(e)return D=e,e}if(O)return O;O=A(e,t);let n=await O;return O=void 0,n}async function A(e,t){let n=e??(typeof window<`u`?window.location.hostname:``);if(n)try{let e=_(t),r=await fetch(`${e}/user/merchant/resolve?domain=${encodeURIComponent(n)}`);if(!r.ok){console.warn(`[Frak SDK] Merchant lookup failed for domain ${n}: ${r.status}`);return}let i=await r.json();return D=i.merchantId,typeof window<`u`&&window.sessionStorage.setItem(E,i.merchantId),D}catch(e){console.warn(`[Frak SDK] Failed to fetch merchantId:`,e);return}}function j(){D=void 0,O=void 0,typeof window<`u`&&window.sessionStorage.removeItem(E)}async function M(e,t){return e.metadata?.merchantId?e.metadata.merchantId:k(void 0,t)}function N(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)}}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return l}});
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "https://twitter.com/QNivelais"
|
|
12
12
|
}
|
|
13
13
|
],
|
|
14
|
-
"version": "0.1.1-beta.
|
|
14
|
+
"version": "0.1.1-beta.df5fa6b3",
|
|
15
15
|
"description": "Core SDK of the Frak wallet, low level library to interact directly with the frak ecosystem.",
|
|
16
16
|
"repository": {
|
|
17
17
|
"url": "https://github.com/frak-id/wallet",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"viem": "^2.x"
|
|
92
92
|
},
|
|
93
93
|
"dependencies": {
|
|
94
|
-
"@frak-labs/frame-connector": "0.1.0-beta.
|
|
94
|
+
"@frak-labs/frame-connector": "0.1.0-beta.df5fa6b3",
|
|
95
95
|
"@openpanel/web": "^1.0.7"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
* Function used to display the Frak embedded wallet popup
|
|
9
9
|
* @param client - The current Frak Client
|
|
10
10
|
* @param params - The parameter used to customise the embedded wallet
|
|
11
|
+
* @returns The embedded wallet display result
|
|
11
12
|
*/
|
|
12
13
|
export async function displayEmbeddedWallet(
|
|
13
14
|
client: FrakClient,
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { FrakClient, GetMerchantInformationReturnType } from "../types";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Fetch the current merchant information (name, rewards, tiers) from the wallet iframe
|
|
5
|
+
* @param client - The current Frak Client
|
|
6
|
+
* @returns The merchant information including available reward tiers
|
|
7
|
+
*
|
|
8
|
+
* @see {@link @frak-labs/core-sdk!index.GetMerchantInformationReturnType | `GetMerchantInformationReturnType`} for the return type shape
|
|
9
|
+
*/
|
|
3
10
|
export async function getMerchantInformation(
|
|
4
11
|
client: FrakClient
|
|
5
12
|
): Promise<GetMerchantInformationReturnType> {
|
|
@@ -7,6 +7,37 @@ import type { SendInteractionParamsType } from "../types/rpc/interaction";
|
|
|
7
7
|
*
|
|
8
8
|
* @param client - The Frak client instance
|
|
9
9
|
* @param params - The interaction parameters
|
|
10
|
+
*
|
|
11
|
+
* @description Sends a user interaction event through the wallet iframe RPC. Supports three interaction types: arrival tracking, sharing events, and custom interactions.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* Track a user arrival with referral attribution:
|
|
15
|
+
* ```ts
|
|
16
|
+
* await sendInteraction(client, {
|
|
17
|
+
* type: "arrival",
|
|
18
|
+
* referrerWallet: "0x1234...abcd",
|
|
19
|
+
* landingUrl: window.location.href,
|
|
20
|
+
* utmSource: "twitter",
|
|
21
|
+
* utmMedium: "social",
|
|
22
|
+
* utmCampaign: "launch-2026",
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* Track a sharing event:
|
|
28
|
+
* ```ts
|
|
29
|
+
* await sendInteraction(client, { type: "sharing" });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* Send a custom interaction:
|
|
34
|
+
* ```ts
|
|
35
|
+
* await sendInteraction(client, {
|
|
36
|
+
* type: "custom",
|
|
37
|
+
* customType: "newsletter_signup",
|
|
38
|
+
* data: { email: "user@example.com" },
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
10
41
|
*/
|
|
11
42
|
export async function sendInteraction(
|
|
12
43
|
client: FrakClient,
|