@frak-labs/core-sdk 0.1.0-beta.afa252b0 → 0.1.0-beta.b0bd1f8a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/cdn/bundle.iife.js +14 -0
  2. package/dist/actions-CEEObPYc.js +1 -0
  3. package/dist/actions-DbQhWYx8.cjs +1 -0
  4. package/dist/actions.cjs +1 -1
  5. package/dist/actions.d.cts +3 -1481
  6. package/dist/actions.d.ts +3 -1481
  7. package/dist/actions.js +1 -1
  8. package/dist/bundle.cjs +1 -13
  9. package/dist/bundle.d.cts +6 -2087
  10. package/dist/bundle.d.ts +6 -2087
  11. package/dist/bundle.js +1 -13
  12. package/dist/index-7OZ39x1U.d.ts +195 -0
  13. package/dist/index-C6FxkWPC.d.cts +511 -0
  14. package/dist/index-UFX7xCg3.d.ts +351 -0
  15. package/dist/index-d8xS4ryI.d.ts +511 -0
  16. package/dist/index-p4FqSp8z.d.cts +351 -0
  17. package/dist/index-zDq-VlKx.d.cts +195 -0
  18. package/dist/index.cjs +1 -13
  19. package/dist/index.d.cts +4 -1387
  20. package/dist/index.d.ts +4 -1387
  21. package/dist/index.js +1 -13
  22. package/dist/interaction-DMJ3ZfaF.d.cts +45 -0
  23. package/dist/interaction-KX1h9a7V.d.ts +45 -0
  24. package/dist/interactions-DnfM3oe0.js +1 -0
  25. package/dist/interactions-EIXhNLf6.cjs +1 -0
  26. package/dist/interactions.cjs +1 -1
  27. package/dist/interactions.d.cts +2 -182
  28. package/dist/interactions.d.ts +2 -182
  29. package/dist/interactions.js +1 -1
  30. package/dist/openSso-D--Airj6.d.cts +1018 -0
  31. package/dist/openSso-DsKJ4y0j.d.ts +1018 -0
  32. package/dist/productTypes-BUkXJKZ7.cjs +1 -0
  33. package/dist/productTypes-CGb1MmBF.js +1 -0
  34. package/dist/src-B_xO0AR6.cjs +13 -0
  35. package/dist/src-D2d52OZa.js +13 -0
  36. package/dist/trackEvent-CHnYa85W.js +1 -0
  37. package/dist/trackEvent-GuQm_1Nm.cjs +1 -0
  38. package/package.json +23 -18
  39. package/src/actions/displayEmbeddedWallet.test.ts +194 -0
  40. package/src/actions/displayEmbeddedWallet.ts +20 -0
  41. package/src/actions/displayModal.test.ts +387 -0
  42. package/src/actions/displayModal.ts +131 -0
  43. package/src/actions/getProductInformation.test.ts +133 -0
  44. package/src/actions/getProductInformation.ts +14 -0
  45. package/src/actions/index.ts +29 -0
  46. package/src/actions/openSso.test.ts +407 -0
  47. package/src/actions/openSso.ts +116 -0
  48. package/src/actions/prepareSso.test.ts +223 -0
  49. package/src/actions/prepareSso.ts +48 -0
  50. package/src/actions/referral/processReferral.ts +230 -0
  51. package/src/actions/referral/referralInteraction.ts +57 -0
  52. package/src/actions/sendInteraction.test.ts +219 -0
  53. package/src/actions/sendInteraction.ts +32 -0
  54. package/src/actions/trackPurchaseStatus.test.ts +287 -0
  55. package/src/actions/trackPurchaseStatus.ts +53 -0
  56. package/src/actions/watchWalletStatus.test.ts +372 -0
  57. package/src/actions/watchWalletStatus.ts +94 -0
  58. package/src/actions/wrapper/modalBuilder.ts +212 -0
  59. package/src/actions/wrapper/sendTransaction.ts +62 -0
  60. package/src/actions/wrapper/siweAuthenticate.ts +94 -0
  61. package/src/bundle.ts +3 -0
  62. package/src/clients/DebugInfo.ts +182 -0
  63. package/src/clients/createIFrameFrakClient.ts +287 -0
  64. package/src/clients/index.ts +3 -0
  65. package/src/clients/setupClient.test.ts +343 -0
  66. package/src/clients/setupClient.ts +73 -0
  67. package/src/clients/transports/iframeLifecycleManager.test.ts +399 -0
  68. package/src/clients/transports/iframeLifecycleManager.ts +90 -0
  69. package/src/constants/interactionTypes.ts +44 -0
  70. package/src/constants/locales.ts +14 -0
  71. package/src/constants/productTypes.ts +33 -0
  72. package/src/index.ts +101 -0
  73. package/src/interactions/index.ts +5 -0
  74. package/src/interactions/pressEncoder.test.ts +215 -0
  75. package/src/interactions/pressEncoder.ts +53 -0
  76. package/src/interactions/purchaseEncoder.test.ts +291 -0
  77. package/src/interactions/purchaseEncoder.ts +99 -0
  78. package/src/interactions/referralEncoder.test.ts +170 -0
  79. package/src/interactions/referralEncoder.ts +47 -0
  80. package/src/interactions/retailEncoder.test.ts +107 -0
  81. package/src/interactions/retailEncoder.ts +37 -0
  82. package/src/interactions/webshopEncoder.test.ts +56 -0
  83. package/src/interactions/webshopEncoder.ts +30 -0
  84. package/src/types/client.ts +14 -0
  85. package/src/types/compression.ts +22 -0
  86. package/src/types/config.ts +111 -0
  87. package/src/types/context.ts +13 -0
  88. package/src/types/index.ts +71 -0
  89. package/src/types/lifecycle/client.ts +46 -0
  90. package/src/types/lifecycle/iframe.ts +35 -0
  91. package/src/types/lifecycle/index.ts +2 -0
  92. package/src/types/rpc/displayModal.ts +84 -0
  93. package/src/types/rpc/embedded/index.ts +68 -0
  94. package/src/types/rpc/embedded/loggedIn.ts +55 -0
  95. package/src/types/rpc/embedded/loggedOut.ts +28 -0
  96. package/src/types/rpc/interaction.ts +43 -0
  97. package/src/types/rpc/modal/final.ts +46 -0
  98. package/src/types/rpc/modal/generic.ts +46 -0
  99. package/src/types/rpc/modal/index.ts +20 -0
  100. package/src/types/rpc/modal/login.ts +32 -0
  101. package/src/types/rpc/modal/openSession.ts +25 -0
  102. package/src/types/rpc/modal/siweAuthenticate.ts +37 -0
  103. package/src/types/rpc/modal/transaction.ts +33 -0
  104. package/src/types/rpc/productInformation.ts +59 -0
  105. package/src/types/rpc/sso.ts +80 -0
  106. package/src/types/rpc/walletStatus.ts +35 -0
  107. package/src/types/rpc.ts +158 -0
  108. package/src/types/transport.ts +34 -0
  109. package/src/utils/FrakContext.test.ts +407 -0
  110. package/src/utils/FrakContext.ts +158 -0
  111. package/src/utils/compression/b64.test.ts +181 -0
  112. package/src/utils/compression/b64.ts +29 -0
  113. package/src/utils/compression/compress.test.ts +123 -0
  114. package/src/utils/compression/compress.ts +11 -0
  115. package/src/utils/compression/decompress.test.ts +145 -0
  116. package/src/utils/compression/decompress.ts +11 -0
  117. package/src/utils/compression/index.ts +3 -0
  118. package/src/utils/computeProductId.test.ts +80 -0
  119. package/src/utils/computeProductId.ts +11 -0
  120. package/src/utils/constants.test.ts +23 -0
  121. package/src/utils/constants.ts +4 -0
  122. package/src/utils/formatAmount.test.ts +113 -0
  123. package/src/utils/formatAmount.ts +18 -0
  124. package/src/utils/getCurrencyAmountKey.test.ts +44 -0
  125. package/src/utils/getCurrencyAmountKey.ts +15 -0
  126. package/src/utils/getSupportedCurrency.test.ts +51 -0
  127. package/src/utils/getSupportedCurrency.ts +14 -0
  128. package/src/utils/getSupportedLocale.test.ts +64 -0
  129. package/src/utils/getSupportedLocale.ts +16 -0
  130. package/src/utils/iframeHelper.test.ts +450 -0
  131. package/src/utils/iframeHelper.ts +143 -0
  132. package/src/utils/index.ts +21 -0
  133. package/src/utils/sso.test.ts +361 -0
  134. package/src/utils/sso.ts +119 -0
  135. package/src/utils/ssoUrlListener.ts +60 -0
  136. package/src/utils/trackEvent.test.ts +162 -0
  137. package/src/utils/trackEvent.ts +26 -0
  138. package/cdn/bundle.js +0 -19
  139. package/cdn/bundle.js.LICENSE.txt +0 -10
package/dist/bundle.js CHANGED
@@ -1,13 +1 @@
1
- import{Deferred as e,FrakRpcError as t,RpcErrorCodes as n,compressJson as r,createRpcClient as a,decompressJson as o}from"@frak-labs/frame-connector";import{createClientCompressionMiddleware as i}from"@frak-labs/frame-connector/middleware";import{OpenPanel as s}from"@openpanel/web";import{bytesToHex as c,concatHex as l,encodeAbiParameters as u,hexToBytes as d,isAddressEqual as f,keccak256 as p,pad as m,toHex as w}from"viem";import{generateSiweNonce as h}from"viem/siwe";let g="nexus-wallet-backup";class y{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?+("complete"===this.iframe.contentDocument.readyState):-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(),a="Unknown";return e instanceof t?a=`FrakRpcError: ${e.code} '${e.message}'`:e instanceof Error?a=e.message:"string"==typeof e&&(a=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:a}}static empty(){return new y}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()}}let k={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 S({walletBaseUrl:e,config:t}){let n=document.querySelector("#frak-wallet");n&&n.remove();let r=document.createElement("iframe");return r.id=k.id,r.name=k.name,r.allow=k.allow,r.style.zIndex=k.style.zIndex.toString(),b({iframe:r,isVisible:!1}),document.body.appendChild(r),new Promise(n=>{r?.addEventListener("load",()=>n(r)),r.src=`${t?.walletUrl??e??"https://wallet.frak.id"}/listener`})}function b({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 I(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}};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 L({config:r,iframe:o}){let c,l=r?.walletUrl??"https://wallet.frak.id",u=function({iframe:t}){let n=new e;return{handleEvent:async e=>{if(!("iframeLifecycle"in e))return;let{iframeLifecycle:r,data:a}=e;switch(r){case"connected":n.resolve(!0);break;case"do-backup":a.backup?localStorage.setItem(g,a.backup):localStorage.removeItem(g);break;case"remove-backup":localStorage.removeItem(g);break;case"show":case"hide":b({iframe:t,isVisible:"show"===r});break;case"handshake":t.contentWindow?.postMessage({clientLifecycle:"handshake-response",data:{token:a.token,currentUrl:window.location.href}},"*");break;case"redirect":{let e=new URL(a.baseRedirectUrl);e.searchParams.has("u")?(e.searchParams.delete("u"),e.searchParams.append("u",window.location.href),window.location.href=e.toString()):window.location.href=a.baseRedirectUrl}}},isConnected:n.promise}}({iframe:o}),d=new y(r,o);if(!o.contentWindow)throw new t(n.configError,"The iframe does not have a content window");let f=a({emittingTransport:o.contentWindow,listeningTransport:window,targetOrigin:l,middleware:[{async onRequest(e,r){if(!await u.isConnected)throw new t(n.clientNotConnected,"The iframe provider isn't connected yet");return r}},i(),{onRequest:(e,t)=>(d.setLastRequest(e),t),onResponse:(e,t)=>(d.setLastResponse(e,t),t)}],lifecycleHandlers:{iframeLifecycle:async(e,t)=>{await u.handleEvent(e)}}}),p=function(e,t){let n,r,a=()=>e.sendLifecycle({clientLifecycle:"heartbeat"});function o(){n&&clearInterval(n),r&&clearTimeout(r)}return async function(){a(),n=setInterval(a,1e3),r=setTimeout(()=>{o(),console.log("Heartbeat timeout: connection failed")},3e4),await t.isConnected,o()}(),o}(f,u),m=async()=>{p(),f.cleanup(),o.remove()};console.log("[Frak SDK] Initializing OpenPanel"),(c=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})=>!("track"===e&&t?.properties)||("sdkVersion"in t.properties||(t.properties={...t.properties,sdkVersion:"0.1.0"}),!0)})).setGlobalProperties({sdkVersion:"0.1.0"}),c.init();let w=v({config:r,rpcClient:f,lifecycleManager:u}).then(()=>d.updateSetupStatus(!0));return{config:r,debugInfo:d,waitForConnection:u.isConnected,waitForSetup:w,request:f.request,listenerRequest:f.listen,destroy:m,openPanel:c}}async function v({config:e,rpcClient:t,lifecycleManager:n}){async function r(){let n=e.customizations?.css;n&&t.sendLifecycle({clientLifecycle:"modal-css",data:{cssLink:n}})}async function a(){let n=e.customizations?.i18n;n&&t.sendLifecycle({clientLifecycle:"modal-i18n",data:{i18n:n}})}async function o(){if("undefined"==typeof window)return;let e=window.localStorage.getItem(g);e&&t.sendLifecycle({clientLifecycle:"restore-backup",data:{backup:e}})}await n.isConnected,function(e,t){if("undefined"==typeof window)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"))}(t,n.isConnected),await Promise.allSettled([r(),a(),o()])}let R={eur:"fr-FR",usd:"en-US",gbp:"en-GB"};function U(e){return e&&e in R?e:"eur"}async function x({config:e}){let t=function(e){let t=U(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}(e),n=await S({config:t});if(!n)return void console.error("Failed to create iframe");let r=L({config:t,iframe:n});return(await r.waitForSetup,await r.waitForConnection)?r:void console.error("Failed to connect to client")}function E(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join("")).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function P(e){let t=e.length%4;return Uint8Array.from(atob(e.replace(/-/g,"+").replace(/_/g,"/").padEnd(e.length+(0===t?0:4-t),"=")),e=>e.charCodeAt(0))}function F(e){return E(r(e))}function C(e){return o(P(e))}let T="fCtx";function D(e){if(e?.r)try{let t=d(e.r);return E(t)}catch(t){console.error("Error compressing Frak context",{e:t,context:e})}}function q(e){if(e&&0!==e.length)try{let t=P(e);return{r:c(t,{size:20})}}catch(t){console.error("Error decompressing Frak context",{e:t,context:e})}}function A({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(T);return t?q(t):null}function $({url:e,context:t}){if(!e)return null;let n=A({url:e}),r=n?{...n,...t}:t;if(!r.r)return null;let a=D(r);if(!a)return null;let o=new URL(e);return o.searchParams.set(T,a),o.toString()}function O(e){let t=new URL(e);return t.searchParams.delete(T),t.toString()}let W={compress:D,decompress:q,parse:A,update:$,remove:O,replaceUrl:function({url:e,context:t}){let n;if(!window.location?.href||"undefined"==typeof window)return void console.error("No window found, can't update context");let r=e??window.location.href;(n=null!==t?$({url:r,context:t}):O(r))&&window.history.replaceState(null,"",n.toString())}};function N(e){return e?R[e]??R.eur:R.eur}function z(e){return e?`${e}Amount`:"eurAmount"}function _(e,t){let n=N(t),r=U(t);return e.toLocaleString(n,{style:"currency",currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function M(e,t,n={}){if(!e)return void console.debug("[Frak] No client provided, skipping event tracking");try{e.openPanel?.track(t,n)}catch(e){console.debug("[Frak] Failed to track event:",t,e)}}function V(e,t,n,r,a){var o;let i=F({r:(o={redirectUrl:t.redirectUrl,directExit:t.directExit,lang:t.lang,productId:n,metadata:{name:r,css:a,logoUrl:t.metadata?.logoUrl,homepageLink:t.metadata?.homepageLink}}).redirectUrl,d:o.directExit,l:o.lang,p:o.productId,m:{n:o.metadata?.name,css:o.metadata?.css,l:o.metadata?.logoUrl,h:o.metadata?.homepageLink}}),s=new URL(e);return s.pathname="/sso",s.searchParams.set("p",i),s.toString()}let B={dapp:1,press:2,webshop:3,retail:4,referral:30,purchase:31},j=Object.entries(B).reduce((e,[t,n])=>(e[t]=BigInt(1)<<BigInt(n),e),{}),G={press:{openArticle:"0xc0a24ffb",readArticle:"0xd5bd0fbe"},dapp:{proofVerifiableStorageUpdate:"0x2ab2aeef",callableVerifiableStorageUpdate:"0xa07da986"},webshop:{open:"0xb311798f"},referral:{referred:"0x010cc3b9",createLink:"0xb2c0f17c"},purchase:{started:"0xd87e90c3",completed:"0x8403aeb4",unsafeCompleted:"0x4d5b14e0"},retail:{customerMeeting:"0x74489004"}};function J({domain:e}={}){return p(w((e??window.location.host).replace("www.","")))}let H="menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800",K="frak-sso";async function Q(e,t){let{metadata:n,customizations:r,walletUrl:a}=e.config;if(t.openInSameWindow??!!t.redirectUrl)return await e.request({method:"frak_openSso",params:[t,n.name,r?.css]});let o=t.ssoPopupUrl??V(a??"https://wallet.frak.id",t,J(),n.name,r?.css),i=window.open(o,K,H);if(!i)throw Error("Popup was blocked. Please allow popups for this site.");return i.focus(),await e.request({method:"frak_openSso",params:[t,n.name,r?.css]})??{}}function X(t,n){if(!n)return t.request({method:"frak_listenToWalletStatus"}).then(e=>(Y(t,e),e));let r=new e,a=!1;return t.listenerRequest({method:"frak_listenToWalletStatus"},e=>{Y(t,e),n(e),a||(r.resolve(e),a=!0)}),r.promise}function Y(e,t){"undefined"!=typeof window&&(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"))}async function Z(e,{productId:t,interaction:n,validation:r}){let a=t??J(e.config);return await e.request({method:"frak_sendInteraction",params:[a,n,r]})}async function ee(e,{steps:t,metadata:n}){return await e.request({method:"frak_displayModal",params:[t,n,e.config.metadata]})}async function et(e,t){return await e.request({method:"frak_displayEmbeddedWallet",params:[t,e.config.metadata]})}async function en(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:"frak_prepareSso",params:[t,n.name,r?.css]})}async function er(e){return await e.request({method:"frak_getProductInformation"})}async function ea(e){if("undefined"==typeof window)return void console.warn("[Frak] No window found, can't track purchase");let t=window.sessionStorage.getItem("frak-wallet-interaction-token");if(!t)return void console.warn("[Frak] No frak session found, skipping purchase check");await fetch("https://backend.frak.id/interactions/listenForPurchase",{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","x-wallet-sdk-auth":t},body:JSON.stringify(e)})}async function eo(e,{siwe:t,metadata:n}){let r=e.config?.domain??window.location.host,a=t?.statement??`I confirm that I want to use my Frak wallet on: ${e.config.metadata.name}`,o={...t,statement:a,nonce:t?.nonce??h(),uri:t?.uri??`https://${r}`,version:t?.version??"1",domain:r};return(await ee(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:o}}})).siweAuthenticate}async function ei(e,{tx:t,metadata:n}){return(await ee(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}function es(e,{metadata:t,login:n,openSession:r}){return function e(t,n){async function r(e){return e&&(n.metadata=e(n.metadata??{})),await ee(t,n)}return{params:n,sendTx:function(r){return e(t,{...n,steps:{...n.steps,sendTransaction:r}})},reward:function(r){return e(t,{...n,steps:{...n.steps,final:{...r,action:{key:"reward"}}}})},sharing:function(r,a){return e(t,{...n,steps:{...n.steps,final:{...a,action:{key:"sharing",options:r}}}})},display:r}}(e,{steps:{login:n??{},openSession:r??{}},metadata:t})}let ec={createLink:()=>({handlerTypeDenominator:w(B.referral),interactionData:G.referral.createLink}),referred({referrer:e}){let t=l([G.referral.referred,m(e,{size:32})]);return{handlerTypeDenominator:w(B.referral),interactionData:t}}};async function el(e,{walletStatus:r,frakContext:a,modalConfig:o,productId:i,options:s}){let c=!1;async function l(){if(!c)return c=!0,ed(e,{modalConfig:{...o,loggedIn:{action:{key:"referred"}}},walletStatus:r})}async function u(t){let n=ec.referred({referrer:t});await Promise.allSettled([Z(e,{productId:i,interaction:n}),M(e,"user_referred",{properties:{referrer:t}})])}try{let{status:e,currentWallet:t}=await eu({initialWalletStatus:r,getFreshWalletStatus:l,pushReferralInteraction:u,frakContext:a});return W.replaceUrl({url:window.location?.href,context:s?.alwaysAppendUrl?{r:t}:null}),e}catch(e){return console.log("Error processing referral",{error:e}),W.replaceUrl({url:window.location?.href,context:s?.alwaysAppendUrl?{r:r?.wallet}:null}),function(e){if(e instanceof t)switch(e.code){case n.walletNotConnected:return"no-wallet";case n.serverErrorForInteractionDelegation:return"no-session"}return"error"}(e)}}async function eu({initialWalletStatus:e,getFreshWalletStatus:t,pushReferralInteraction:n,frakContext:r}){let a=e?.wallet;return r?.r?(a||(a=await t()),a&&f(r.r,a))?{status:"self-referral",currentWallet:a}:(e?.interactionSession||(a=await t()),await n(r.r),{status:"success",currentWallet:a}):{status:"no-referrer",currentWallet:a}}async function ed(e,{modalConfig:t,walletStatus:n}){if(!n?.interactionSession){let n=await et(e,t??{});return n?.wallet??void 0}return n.wallet??void 0}async function ef(e,{productId:t,modalConfig:n,options:r}={}){let a=W.parse({url:window.location.href}),o=await X(e);try{return await el(e,{walletStatus:o,frakContext:a,modalConfig:n,productId:t,options:r})}catch(e){console.warn("Error processing referral",{error:e})}}let ep={openArticle({articleId:e}){let t=l([G.press.openArticle,m(e,{size:32})]);return{handlerTypeDenominator:w(B.press),interactionData:t}},readArticle({articleId:e}){let t=l([G.press.readArticle,m(e,{size:32})]);return{handlerTypeDenominator:w(B.press),interactionData:t}}},em={startPurchase({purchaseId:e}){let t=l([G.purchase.started,m(e,{size:32})]);return{handlerTypeDenominator:w(B.purchase),interactionData:t}},completedPurchase({purchaseId:e,proof:t}){let n=u([{type:"uint256"},{type:"bytes32[]"}],[BigInt(e),t]),r=l([G.purchase.completed,n]);return{handlerTypeDenominator:w(B.purchase),interactionData:r}},unsafeCompletedPurchase({purchaseId:e}){let t=l([G.purchase.unsafeCompleted,m(e,{size:32})]);return{handlerTypeDenominator:w(B.purchase),interactionData:t}}},ew={open:()=>({handlerTypeDenominator:w(B.webshop),interactionData:G.webshop.open})},eh={customerMeeting({agencyId:e}){let t=l([G.retail.customerMeeting,m(e,{size:32})]);return{handlerTypeDenominator:w(B.retail),interactionData:t}}};export{y as DebugInfoGatherer,W as FrakContextManager,ep as PressInteractionEncoder,em as PurchaseInteractionEncoder,ec as ReferralInteractionEncoder,eh as RetailInteractionEncoder,ew as WebShopInteractionEncoder,P as base64urlDecode,E as base64urlEncode,k as baseIframeProps,F as compressJsonToB64,L as createIFrameFrakClient,S as createIframe,C as decompressJsonFromB64,et as displayEmbeddedWallet,ee as displayModal,I as findIframeInOpener,_ as formatAmount,V as generateSsoUrl,z as getCurrencyAmountKey,er as getProductInformation,U as getSupportedCurrency,N as getSupportedLocale,G as interactionTypes,R as locales,es as modalBuilder,Q as openSso,en as prepareSso,el as processReferral,B as productTypes,j as productTypesMask,ef as referralInteraction,Z as sendInteraction,ei as sendTransaction,x as setupClient,eo as siweAuthenticate,H as ssoPopupFeatures,K as ssoPopupName,M as trackEvent,ea as trackPurchaseStatus,X as watchWalletStatus};
1
+ import{a as e,c as t,i as n,l as r,n as i,o as a,r as o,s,t as c}from"./trackEvent-CHnYa85W.js";import{a as l,c as u,d,f,i as p,l as m,n as h,o as g,r as _,s as v,t as y,u as b}from"./src-D2d52OZa.js";import{n as x,r as S,t as C}from"./productTypes-CGb1MmBF.js";import{a as w,c as T,d as E,f as D,i as O,l as k,n as A,o as j,r as M,s as N,t as P,u as F}from"./actions-CEEObPYc.js";import{a as I,i as L,n as R,r as z,t as B}from"./interactions-DnfM3oe0.js";export{f as DebugInfoGatherer,i as FrakContextManager,I as PressInteractionEncoder,L as PurchaseInteractionEncoder,z as ReferralInteractionEncoder,R as RetailInteractionEncoder,B as WebShopInteractionEncoder,t as base64urlDecode,r as base64urlEncode,m as baseIframeProps,s as compressJsonToB64,u as createIFrameFrakClient,b as createIframe,v as decompressJsonFromB64,D as displayEmbeddedWallet,E as displayModal,d as findIframeInOpener,_ as formatAmount,a as generateSsoUrl,h as getCurrencyAmountKey,F as getProductInformation,l as getSupportedCurrency,p as getSupportedLocale,S as interactionTypes,g as locales,M as modalBuilder,o as openSso,k as prepareSso,T as processReferral,C as productTypes,x as productTypesMask,N as referralInteraction,j as sendInteraction,A as sendTransaction,y as setupClient,P as siweAuthenticate,n as ssoPopupFeatures,e as ssoPopupName,c as trackEvent,w as trackPurchaseStatus,O as watchWalletStatus};
@@ -0,0 +1,195 @@
1
+ import { t as PreparedInteraction } from "./interaction-KX1h9a7V.js";
2
+ import { Address, Hex } from "viem";
3
+
4
+ //#region src/interactions/pressEncoder.d.ts
5
+
6
+ /**
7
+ * Press interactions allow you to track user engagement with articles or other press content on your platform.
8
+ * After setting up these interactions, you can create acquisition campaign based on the user engagement with your press content.
9
+ *
10
+ * :::info
11
+ * To properly handle press interactions, ensure that the "Press" product type is enabled in your Business dashboard.
12
+ * :::
13
+ *
14
+ * @description Encode press related user interactions
15
+ *
16
+ * @group Interactions Encoder
17
+ *
18
+ * @see {@link PreparedInteraction} The prepared interaction object that can be sent
19
+ * @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
20
+ */
21
+ declare const PressInteractionEncoder: {
22
+ /**
23
+ * Encode an open article interaction
24
+ * @param args
25
+ * @param args.articleId - The id of the article the user opened (32 bytes), could be a `keccak256` hash of the article slug, or your internal id
26
+ */
27
+ openArticle({
28
+ articleId
29
+ }: {
30
+ articleId: Hex;
31
+ }): PreparedInteraction;
32
+ /**
33
+ * Encode a read article interaction
34
+ * @param args
35
+ * @param args.articleId - The id of the article the user opened (32 bytes), could be a `keccak256` hash of the article slug, or your internal id
36
+ */
37
+ readArticle({
38
+ articleId
39
+ }: {
40
+ articleId: Hex;
41
+ }): PreparedInteraction;
42
+ };
43
+ //#endregion
44
+ //#region src/interactions/purchaseEncoder.d.ts
45
+ /**
46
+ * Purchase interactions allow you to track user purchases on your platform.
47
+ * After setting up these interactions, you can create acquisition campaign based on the user purchase (starting a new one, completed, or even purchase dropped).
48
+ *
49
+ * :::info
50
+ * To properly handle purchase interactions, ensure that the "Purchase" product type is enabled in your Business dashboard, and that you have set up everything correctly in the `Purchasetracker` section.
51
+ * :::
52
+ *
53
+ * :::note
54
+ * The `purchaseId` is used on both interactions. It can be computed like this:
55
+ *
56
+ * ```ts
57
+ * const purchaseId = keccak256(concatHex([productId, toHex(externalPurchaseId)]));
58
+ * ```
59
+ *
60
+ * With:
61
+ * - `productId`: The id of your product, you can find it in the product dashboard.
62
+ * - `externalPurchaseId`: The id of the purchase in your system (e.g. the shopify `order_id`).
63
+ * :::
64
+ *
65
+ * @description Encode purchase related user interactions
66
+ *
67
+ * @group Interactions Encoder
68
+ *
69
+ * @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
70
+ * @see {@link PreparedInteraction} The prepared interaction object that can be sent
71
+ * @see {@link !actions.trackPurchaseStatus | `trackPurchaseStatus()`} Action that will automatically send the purchase upon completion
72
+ * @see [Purchase Webhooks](/wallet-sdk/references-api/webhook) Webhooks to be implemented on your side to confirm a purchase
73
+ * @see [Purchase Proof](/wallet-sdk/references-api/purchaseProof) Get a merklee proof for the purchase
74
+ */
75
+ declare const PurchaseInteractionEncoder: {
76
+ /**
77
+ * Encode a start purchase interaction
78
+ * @param args
79
+ * @param args.purchaseId - The id of the purchase that is being started.
80
+ */
81
+ startPurchase({
82
+ purchaseId
83
+ }: {
84
+ purchaseId: Hex;
85
+ }): PreparedInteraction;
86
+ /**
87
+ * Encode a complete purchase interaction
88
+ * @param args
89
+ * @param args.purchaseId - The id of the purchase that is being completed.
90
+ * @param args.proof - The merkle proof that the user has completed the purchase (see [Purchase Webhooks](/wallet-sdk/references-api/webhook) for more details).
91
+ */
92
+ completedPurchase({
93
+ purchaseId,
94
+ proof
95
+ }: {
96
+ purchaseId: Hex;
97
+ proof: Hex[];
98
+ }): PreparedInteraction;
99
+ /**
100
+ * Encode an unsafe complete purchase interaction (when we can't provide the proof)
101
+ * @param args
102
+ * @param args.purchaseId - The id of the purchase that is being completed.
103
+ */
104
+ unsafeCompletedPurchase({
105
+ purchaseId
106
+ }: {
107
+ purchaseId: Hex;
108
+ }): PreparedInteraction;
109
+ };
110
+ //#endregion
111
+ //#region src/interactions/referralEncoder.d.ts
112
+ /**
113
+ * Referral interactions allow you to track user sharing activities.
114
+ * These interactions are essential for platforms looking to grow their user base through user-to-user referrals and reward systems.
115
+ *
116
+ * :::info
117
+ * To properly handle referral interactions, ensure that the "Referral" product type is enabled in your Business dashboard.
118
+ * :::
119
+ *
120
+ * @description Encode referral related user interactions
121
+ *
122
+ * @group Interactions Encoder
123
+ *
124
+ * @see {@link PreparedInteraction} The prepared interaction object that can be sent
125
+ * @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
126
+ */
127
+ declare const ReferralInteractionEncoder: {
128
+ /**
129
+ * Records the event of a user creating a referral link. Note that this interaction doesn't actually create the link itself; it only sends an event to track that a link was created.
130
+ */
131
+ createLink(): PreparedInteraction;
132
+ /**
133
+ * Encode a referred interaction
134
+ * @param args
135
+ * @param args.referrer - The Ethereum address of the user who made the referral
136
+ */
137
+ referred({
138
+ referrer
139
+ }: {
140
+ referrer: Address;
141
+ }): PreparedInteraction;
142
+ };
143
+ //#endregion
144
+ //#region src/interactions/retailEncoder.d.ts
145
+ /**
146
+ * Retail interactions allow you to track user activities on your retails products.
147
+ *
148
+ * :::info
149
+ * To properly handle retail interactions, ensure that the "Retail" product type is enabled in your Business dashboard.
150
+ * :::
151
+ *
152
+ * @description Encode retail related user interactions
153
+ *
154
+ * @group Interactions Encoder
155
+ *
156
+ * @see {@link PreparedInteraction} The prepared interaction object that can be sent
157
+ * @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
158
+ */
159
+ declare const RetailInteractionEncoder: {
160
+ /**
161
+ * Encode a customer meeting retail interaction
162
+ * @param args
163
+ * @param args.agencyId - The id of the agency that the customer is meeting with
164
+ *
165
+ */
166
+ customerMeeting({
167
+ agencyId
168
+ }: {
169
+ agencyId: Hex;
170
+ }): PreparedInteraction;
171
+ };
172
+ //#endregion
173
+ //#region src/interactions/webshopEncoder.d.ts
174
+ /**
175
+ * Webshop interactions allow you to track user activities on your webshop.
176
+ *
177
+ * :::info
178
+ * To properly handle webshop interactions, ensure that the "WebShop" product type is enabled in your Business dashboard.
179
+ * :::
180
+ *
181
+ * @description Encode webshop related user interactions
182
+ *
183
+ * @group Interactions Encoder
184
+ *
185
+ * @see {@link PreparedInteraction} The prepared interaction object that can be sent
186
+ * @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
187
+ */
188
+ declare const WebShopInteractionEncoder: {
189
+ /**
190
+ * Encode an open webshop interaction
191
+ */
192
+ open(): PreparedInteraction;
193
+ };
194
+ //#endregion
195
+ export { PressInteractionEncoder as a, PurchaseInteractionEncoder as i, RetailInteractionEncoder as n, ReferralInteractionEncoder as r, WebShopInteractionEncoder as t };