@frak-labs/core-sdk 0.1.0-beta.8d103039 → 0.1.0-beta.d9302e66
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/package.json +20 -16
- package/src/actions/displayEmbeddedWallet.test.ts +194 -0
- package/src/actions/displayModal.test.ts +387 -0
- package/src/actions/getProductInformation.test.ts +133 -0
- package/src/actions/index.ts +19 -19
- package/src/actions/openSso.test.ts +407 -0
- package/src/actions/prepareSso.test.ts +223 -0
- package/src/actions/referral/processReferral.ts +1 -1
- package/src/actions/referral/referralInteraction.ts +1 -1
- package/src/actions/sendInteraction.test.ts +219 -0
- package/src/actions/trackPurchaseStatus.test.ts +287 -0
- package/src/actions/watchWalletStatus.test.ts +372 -0
- package/src/bundle.ts +1 -1
- package/src/clients/createIFrameFrakClient.ts +2 -2
- package/src/clients/index.ts +1 -1
- package/src/clients/setupClient.ts +3 -1
- package/src/clients/transports/iframeLifecycleManager.ts +3 -1
- package/src/index.ts +72 -74
- package/src/interactions/index.ts +2 -2
- package/src/interactions/pressEncoder.test.ts +215 -0
- package/src/interactions/pressEncoder.ts +1 -1
- package/src/interactions/purchaseEncoder.test.ts +291 -0
- package/src/interactions/purchaseEncoder.ts +8 -3
- package/src/interactions/referralEncoder.test.ts +170 -0
- package/src/interactions/retailEncoder.test.ts +107 -0
- package/src/interactions/retailEncoder.ts +1 -1
- package/src/interactions/webshopEncoder.test.ts +56 -0
- package/src/types/index.ts +51 -50
- package/src/types/lifecycle/index.ts +1 -1
- package/src/types/rpc/embedded/loggedIn.ts +1 -1
- package/src/types/rpc/embedded/loggedOut.ts +1 -1
- package/src/types/rpc/modal/index.ts +11 -11
- package/src/utils/FrakContext.test.ts +338 -0
- package/src/utils/FrakContext.ts +8 -2
- package/src/utils/compression/b64.test.ts +181 -0
- package/src/utils/compression/compress.test.ts +123 -0
- package/src/utils/compression/decompress.test.ts +145 -0
- package/src/utils/compression/index.ts +1 -1
- package/src/utils/computeProductId.test.ts +80 -0
- package/src/utils/constants.test.ts +23 -0
- package/src/utils/formatAmount.test.ts +113 -0
- package/src/utils/getCurrencyAmountKey.test.ts +44 -0
- package/src/utils/getSupportedCurrency.test.ts +51 -0
- package/src/utils/getSupportedLocale.test.ts +64 -0
- package/src/utils/iframeHelper.test.ts +450 -0
- package/src/utils/iframeHelper.ts +4 -3
- package/src/utils/index.ts +12 -12
- package/src/utils/sso.test.ts +361 -0
- package/src/utils/trackEvent.test.ts +162 -0
- package/cdn/bundle.js +0 -19
- package/cdn/bundle.js.LICENSE.txt +0 -10
- package/dist/actions.cjs +0 -1
- package/dist/actions.d.cts +0 -1481
- package/dist/actions.d.ts +0 -1481
- package/dist/actions.js +0 -1
- package/dist/bundle.cjs +0 -13
- package/dist/bundle.d.cts +0 -2087
- package/dist/bundle.d.ts +0 -2087
- package/dist/bundle.js +0 -13
- package/dist/index.cjs +0 -13
- package/dist/index.d.cts +0 -1387
- package/dist/index.d.ts +0 -1387
- package/dist/index.js +0 -13
- package/dist/interactions.cjs +0 -1
- package/dist/interactions.d.cts +0 -182
- package/dist/interactions.d.ts +0 -182
- package/dist/interactions.js +0 -1
package/dist/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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,hexToBytes as l}from"viem";let d="nexus-wallet-backup";class u{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 u}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 f={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 p({walletBaseUrl:e,config:t}){let n=document.querySelector("#frak-wallet");n&&n.remove();let r=document.createElement("iframe");return r.id=f.id,r.name=f.name,r.allow=f.allow,r.style.zIndex=f.style.zIndex.toString(),m({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 m({iframe:e,isVisible:t}){if(!t){e.style.width="0",e.style.height="0",e.style.border="0",e.style.position="fixed",e.style.top="-1000px",e.style.left="-1000px";return}e.style.position="fixed",e.style.top="0",e.style.left="0",e.style.width="100%",e.style.height="100%",e.style.pointerEvents="auto"}function g(e="/listener"){if(!window.opener)return null;let t=t=>{try{return t.location.origin===window.location.origin&&t.location.pathname===e}catch{return!1}};if(t(window.opener))return window.opener;try{let e=window.opener.frames;for(let n=0;n<e.length;n++)if(t(e[n]))return e[n];return null}catch(t){return console.error(`[findIframeInOpener] Error finding iframe with pathname ${e}:`,t),null}}function h({config:r,iframe:o}){let c,l=r?.walletUrl??"https://wallet.frak.id",f=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(d,a.backup):localStorage.removeItem(d);break;case"remove-backup":localStorage.removeItem(d);break;case"show":case"hide":m({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}),p=new u(r,o);if(!o.contentWindow)throw new t(n.configError,"The iframe does not have a content window");let g=a({emittingTransport:o.contentWindow,listeningTransport:window,targetOrigin:l,middleware:[{async onRequest(e,r){if(!await f.isConnected)throw new t(n.clientNotConnected,"The iframe provider isn't connected yet");return r}},i(),{onRequest:(e,t)=>(p.setLastRequest(e),t),onResponse:(e,t)=>(p.setLastResponse(e,t),t)}],lifecycleHandlers:{iframeLifecycle:async(e,t)=>{await f.handleEvent(e)}}}),h=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}(g,f),y=async()=>{h(),g.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 b=w({config:r,rpcClient:g,lifecycleManager:f}).then(()=>p.updateSetupStatus(!0));return{config:r,debugInfo:p,waitForConnection:f.isConnected,waitForSetup:b,request:g.request,listenerRequest:g.listen,destroy:y,openPanel:c}}async function w({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(d);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 y={eur:"fr-FR",usd:"en-US",gbp:"en-GB"};function b(e){return e&&e in y?e:"eur"}async function S({config:e}){let t=function(e){let t=b(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}(e),n=await p({config:t});if(!n)return void console.error("Failed to create iframe");let r=h({config:t,iframe:n});return(await r.waitForSetup,await r.waitForConnection)?r:void console.error("Failed to connect to client")}function k(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join("")).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function L(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 R(e){return k(r(e))}function v(e){return o(L(e))}let I="fCtx";function x(e){if(e?.r)try{let t=l(e.r);return k(t)}catch(t){console.error("Error compressing Frak context",{e:t,context:e})}}function U(e){if(e&&0!==e.length)try{let t=L(e);return{r:c(t,{size:20})}}catch(t){console.error("Error decompressing Frak context",{e:t,context:e})}}function F({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(I);return t?U(t):null}function C({url:e,context:t}){if(!e)return null;let n=F({url:e}),r=n?{...n,...t}:t;if(!r.r)return null;let a=x(r);if(!a)return null;let o=new URL(e);return o.searchParams.set(I,a),o.toString()}function E(e){let t=new URL(e);return t.searchParams.delete(I),t.toString()}let P={compress:x,decompress:U,parse:F,update:C,remove:E,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?C({url:r,context:t}):E(r))&&window.history.replaceState(null,"",n.toString())}};function q(e){return e?y[e]??y.eur:y.eur}function D(e){return e?`${e}Amount`:"eurAmount"}function $(e,t){let n=q(t),r=b(t);return e.toLocaleString(n,{style:"currency",currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function O(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 A(e,t,n,r,a){var o;let i=R({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 T={dapp:1,press:2,webshop:3,retail:4,referral:30,purchase:31},N=Object.entries(T).reduce((e,[t,n])=>(e[t]=BigInt(1)<<BigInt(n),e),{}),V={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"}},z="menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800",W="frak-sso";export{u as DebugInfoGatherer,P as FrakContextManager,L as base64urlDecode,k as base64urlEncode,f as baseIframeProps,R as compressJsonToB64,h as createIFrameFrakClient,p as createIframe,v as decompressJsonFromB64,g as findIframeInOpener,$ as formatAmount,A as generateSsoUrl,D as getCurrencyAmountKey,b as getSupportedCurrency,q as getSupportedLocale,V as interactionTypes,y as locales,T as productTypes,N as productTypesMask,S as setupClient,z as ssoPopupFeatures,W as ssoPopupName,O as trackEvent};
|
package/dist/interactions.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";let __rslib_import_meta_url__="undefined"==typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,r)=>{for(var t in r)__webpack_require__.o(r,t)&&!__webpack_require__.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},__webpack_require__.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{PressInteractionEncoder:()=>PressInteractionEncoder,ReferralInteractionEncoder:()=>ReferralInteractionEncoder,RetailInteractionEncoder:()=>RetailInteractionEncoder,PurchaseInteractionEncoder:()=>PurchaseInteractionEncoder,WebShopInteractionEncoder:()=>WebShopInteractionEncoder});let external_viem_namespaceObject=require("viem"),interactionTypes={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"}},productTypes={dapp:1,press:2,webshop:3,retail:4,referral:30,purchase:31},productTypesMask=Object.entries(productTypes).reduce((e,[r,t])=>(e[r]=BigInt(1)<<BigInt(t),e),{}),PressInteractionEncoder={openArticle({articleId:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.press.openArticle,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.press),interactionData:r}},readArticle({articleId:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.press.readArticle,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.press),interactionData:r}}},ReferralInteractionEncoder={createLink:()=>({handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.referral),interactionData:interactionTypes.referral.createLink}),referred({referrer:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.referral.referred,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.referral),interactionData:r}}},PurchaseInteractionEncoder={startPurchase({purchaseId:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.purchase.started,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.purchase),interactionData:r}},completedPurchase({purchaseId:e,proof:r}){let t=(0,external_viem_namespaceObject.encodeAbiParameters)([{type:"uint256"},{type:"bytes32[]"}],[BigInt(e),r]),a=(0,external_viem_namespaceObject.concatHex)([interactionTypes.purchase.completed,t]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.purchase),interactionData:a}},unsafeCompletedPurchase({purchaseId:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.purchase.unsafeCompleted,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.purchase),interactionData:r}}},WebShopInteractionEncoder={open:()=>({handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.webshop),interactionData:interactionTypes.webshop.open})},RetailInteractionEncoder={customerMeeting({agencyId:e}){let r=(0,external_viem_namespaceObject.concatHex)([interactionTypes.retail.customerMeeting,(0,external_viem_namespaceObject.pad)(e,{size:32})]);return{handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.retail),interactionData:r}}};for(var __webpack_i__ in exports.PressInteractionEncoder=__webpack_exports__.PressInteractionEncoder,exports.PurchaseInteractionEncoder=__webpack_exports__.PurchaseInteractionEncoder,exports.ReferralInteractionEncoder=__webpack_exports__.ReferralInteractionEncoder,exports.RetailInteractionEncoder=__webpack_exports__.RetailInteractionEncoder,exports.WebShopInteractionEncoder=__webpack_exports__.WebShopInteractionEncoder,__webpack_exports__)-1===["PressInteractionEncoder","PurchaseInteractionEncoder","ReferralInteractionEncoder","RetailInteractionEncoder","WebShopInteractionEncoder"].indexOf(__webpack_i__)&&(exports[__webpack_i__]=__webpack_exports__[__webpack_i__]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/interactions.d.cts
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { Address } from 'viem';
|
|
2
|
-
import { Hex } from 'viem';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Represent a prepared user interaction, ready to be sent on-chain via the wallet
|
|
6
|
-
*/
|
|
7
|
-
declare type PreparedInteraction = {
|
|
8
|
-
handlerTypeDenominator: Hex;
|
|
9
|
-
interactionData: Hex;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Press interactions allow you to track user engagement with articles or other press content on your platform.
|
|
14
|
-
* After setting up these interactions, you can create acquisition campaign based on the user engagement with your press content.
|
|
15
|
-
*
|
|
16
|
-
* :::info
|
|
17
|
-
* To properly handle press interactions, ensure that the "Press" product type is enabled in your Business dashboard.
|
|
18
|
-
* :::
|
|
19
|
-
*
|
|
20
|
-
* @description Encode press related user interactions
|
|
21
|
-
*
|
|
22
|
-
* @group Interactions Encoder
|
|
23
|
-
*
|
|
24
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
25
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
26
|
-
*/
|
|
27
|
-
export declare const PressInteractionEncoder: {
|
|
28
|
-
/**
|
|
29
|
-
* Encode an open article interaction
|
|
30
|
-
* @param args
|
|
31
|
-
* @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
|
|
32
|
-
*/
|
|
33
|
-
openArticle({ articleId }: {
|
|
34
|
-
articleId: Hex;
|
|
35
|
-
}): PreparedInteraction;
|
|
36
|
-
/**
|
|
37
|
-
* Encode a read article interaction
|
|
38
|
-
* @param args
|
|
39
|
-
* @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
|
|
40
|
-
*/
|
|
41
|
-
readArticle({ articleId }: {
|
|
42
|
-
articleId: Hex;
|
|
43
|
-
}): PreparedInteraction;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Purchase interactions allow you to track user purchases on your platform.
|
|
48
|
-
* After setting up these interactions, you can create acquisition campaign based on the user purchase (starting a new one, completed, or even purchase dropped).
|
|
49
|
-
*
|
|
50
|
-
* :::info
|
|
51
|
-
* 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.
|
|
52
|
-
* :::
|
|
53
|
-
*
|
|
54
|
-
* :::note
|
|
55
|
-
* The `purchaseId` is used on both interactions. It can be computed like this:
|
|
56
|
-
*
|
|
57
|
-
* ```ts
|
|
58
|
-
* const purchaseId = keccak256(concatHex([productId, toHex(externalPurchaseId)]));
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* With:
|
|
62
|
-
* - `productId`: The id of your product, you can find it in the product dashboard.
|
|
63
|
-
* - `externalPurchaseId`: The id of the purchase in your system (e.g. the shopify `order_id`).
|
|
64
|
-
* :::
|
|
65
|
-
*
|
|
66
|
-
* @description Encode purchase related user interactions
|
|
67
|
-
*
|
|
68
|
-
* @group Interactions Encoder
|
|
69
|
-
*
|
|
70
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
71
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
72
|
-
* @see {@link !actions.trackPurchaseStatus | `trackPurchaseStatus()`} Action that will automatically send the purchase upon completion
|
|
73
|
-
* @see [Purchase Webhooks](/wallet-sdk/references-api/webhook) Webhooks to be implemented on your side to confirm a purchase
|
|
74
|
-
* @see [Purchase Proof](/wallet-sdk/references-api/purchaseProof) Get a merklee proof for the purchase
|
|
75
|
-
*/
|
|
76
|
-
export declare const PurchaseInteractionEncoder: {
|
|
77
|
-
/**
|
|
78
|
-
* Encode a start purchase interaction
|
|
79
|
-
* @param args
|
|
80
|
-
* @param args.purchaseId - The id of the purchase that is being started.
|
|
81
|
-
*/
|
|
82
|
-
startPurchase({ purchaseId }: {
|
|
83
|
-
purchaseId: Hex;
|
|
84
|
-
}): PreparedInteraction;
|
|
85
|
-
/**
|
|
86
|
-
* Encode a complete purchase interaction
|
|
87
|
-
* @param args
|
|
88
|
-
* @param args.purchaseId - The id of the purchase that is being completed.
|
|
89
|
-
* @param args.proof - The merkle proof that the user has completed the purchase (see [Purchase Webhooks](/wallet-sdk/references-api/webhook) for more details).
|
|
90
|
-
*/
|
|
91
|
-
completedPurchase({ purchaseId, proof, }: {
|
|
92
|
-
purchaseId: Hex;
|
|
93
|
-
proof: Hex[];
|
|
94
|
-
}): PreparedInteraction;
|
|
95
|
-
/**
|
|
96
|
-
* Encode an unsafe complete purchase interaction (when we can't provide the proof)
|
|
97
|
-
* @param args
|
|
98
|
-
* @param args.purchaseId - The id of the purchase that is being completed.
|
|
99
|
-
*/
|
|
100
|
-
unsafeCompletedPurchase({ purchaseId, }: {
|
|
101
|
-
purchaseId: Hex;
|
|
102
|
-
}): PreparedInteraction;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Referral interactions allow you to track user sharing activities.
|
|
107
|
-
* These interactions are essential for platforms looking to grow their user base through user-to-user referrals and reward systems.
|
|
108
|
-
*
|
|
109
|
-
* :::info
|
|
110
|
-
* To properly handle referral interactions, ensure that the "Referral" product type is enabled in your Business dashboard.
|
|
111
|
-
* :::
|
|
112
|
-
*
|
|
113
|
-
* @description Encode referral related user interactions
|
|
114
|
-
*
|
|
115
|
-
* @group Interactions Encoder
|
|
116
|
-
*
|
|
117
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
118
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
119
|
-
*/
|
|
120
|
-
export declare const ReferralInteractionEncoder: {
|
|
121
|
-
/**
|
|
122
|
-
* 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.
|
|
123
|
-
*/
|
|
124
|
-
createLink(): PreparedInteraction;
|
|
125
|
-
/**
|
|
126
|
-
* Encode a referred interaction
|
|
127
|
-
* @param args
|
|
128
|
-
* @param args.referrer - The Ethereum address of the user who made the referral
|
|
129
|
-
*/
|
|
130
|
-
referred({ referrer }: {
|
|
131
|
-
referrer: Address;
|
|
132
|
-
}): PreparedInteraction;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Retail interactions allow you to track user activities on your retails products.
|
|
137
|
-
*
|
|
138
|
-
* :::info
|
|
139
|
-
* To properly handle retail interactions, ensure that the "Retail" product type is enabled in your Business dashboard.
|
|
140
|
-
* :::
|
|
141
|
-
*
|
|
142
|
-
* @description Encode retail related user interactions
|
|
143
|
-
*
|
|
144
|
-
* @group Interactions Encoder
|
|
145
|
-
*
|
|
146
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
147
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
148
|
-
*/
|
|
149
|
-
export declare const RetailInteractionEncoder: {
|
|
150
|
-
/**
|
|
151
|
-
* Encode a customer meeting retail interaction
|
|
152
|
-
* @param args
|
|
153
|
-
* @param args.agencyId - The id of the agency that the customer is meeting with
|
|
154
|
-
*
|
|
155
|
-
*/
|
|
156
|
-
customerMeeting({ agencyId }: {
|
|
157
|
-
agencyId: Hex;
|
|
158
|
-
}): PreparedInteraction;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Webshop interactions allow you to track user activities on your webshop.
|
|
163
|
-
*
|
|
164
|
-
* :::info
|
|
165
|
-
* To properly handle webshop interactions, ensure that the "WebShop" product type is enabled in your Business dashboard.
|
|
166
|
-
* :::
|
|
167
|
-
*
|
|
168
|
-
* @description Encode webshop related user interactions
|
|
169
|
-
*
|
|
170
|
-
* @group Interactions Encoder
|
|
171
|
-
*
|
|
172
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
173
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
174
|
-
*/
|
|
175
|
-
export declare const WebShopInteractionEncoder: {
|
|
176
|
-
/**
|
|
177
|
-
* Encode an open webshop interaction
|
|
178
|
-
*/
|
|
179
|
-
open(): PreparedInteraction;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
export { }
|
package/dist/interactions.d.ts
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { Address } from 'viem';
|
|
2
|
-
import { Hex } from 'viem';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Represent a prepared user interaction, ready to be sent on-chain via the wallet
|
|
6
|
-
*/
|
|
7
|
-
declare type PreparedInteraction = {
|
|
8
|
-
handlerTypeDenominator: Hex;
|
|
9
|
-
interactionData: Hex;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Press interactions allow you to track user engagement with articles or other press content on your platform.
|
|
14
|
-
* After setting up these interactions, you can create acquisition campaign based on the user engagement with your press content.
|
|
15
|
-
*
|
|
16
|
-
* :::info
|
|
17
|
-
* To properly handle press interactions, ensure that the "Press" product type is enabled in your Business dashboard.
|
|
18
|
-
* :::
|
|
19
|
-
*
|
|
20
|
-
* @description Encode press related user interactions
|
|
21
|
-
*
|
|
22
|
-
* @group Interactions Encoder
|
|
23
|
-
*
|
|
24
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
25
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
26
|
-
*/
|
|
27
|
-
export declare const PressInteractionEncoder: {
|
|
28
|
-
/**
|
|
29
|
-
* Encode an open article interaction
|
|
30
|
-
* @param args
|
|
31
|
-
* @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
|
|
32
|
-
*/
|
|
33
|
-
openArticle({ articleId }: {
|
|
34
|
-
articleId: Hex;
|
|
35
|
-
}): PreparedInteraction;
|
|
36
|
-
/**
|
|
37
|
-
* Encode a read article interaction
|
|
38
|
-
* @param args
|
|
39
|
-
* @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
|
|
40
|
-
*/
|
|
41
|
-
readArticle({ articleId }: {
|
|
42
|
-
articleId: Hex;
|
|
43
|
-
}): PreparedInteraction;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Purchase interactions allow you to track user purchases on your platform.
|
|
48
|
-
* After setting up these interactions, you can create acquisition campaign based on the user purchase (starting a new one, completed, or even purchase dropped).
|
|
49
|
-
*
|
|
50
|
-
* :::info
|
|
51
|
-
* 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.
|
|
52
|
-
* :::
|
|
53
|
-
*
|
|
54
|
-
* :::note
|
|
55
|
-
* The `purchaseId` is used on both interactions. It can be computed like this:
|
|
56
|
-
*
|
|
57
|
-
* ```ts
|
|
58
|
-
* const purchaseId = keccak256(concatHex([productId, toHex(externalPurchaseId)]));
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* With:
|
|
62
|
-
* - `productId`: The id of your product, you can find it in the product dashboard.
|
|
63
|
-
* - `externalPurchaseId`: The id of the purchase in your system (e.g. the shopify `order_id`).
|
|
64
|
-
* :::
|
|
65
|
-
*
|
|
66
|
-
* @description Encode purchase related user interactions
|
|
67
|
-
*
|
|
68
|
-
* @group Interactions Encoder
|
|
69
|
-
*
|
|
70
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
71
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
72
|
-
* @see {@link !actions.trackPurchaseStatus | `trackPurchaseStatus()`} Action that will automatically send the purchase upon completion
|
|
73
|
-
* @see [Purchase Webhooks](/wallet-sdk/references-api/webhook) Webhooks to be implemented on your side to confirm a purchase
|
|
74
|
-
* @see [Purchase Proof](/wallet-sdk/references-api/purchaseProof) Get a merklee proof for the purchase
|
|
75
|
-
*/
|
|
76
|
-
export declare const PurchaseInteractionEncoder: {
|
|
77
|
-
/**
|
|
78
|
-
* Encode a start purchase interaction
|
|
79
|
-
* @param args
|
|
80
|
-
* @param args.purchaseId - The id of the purchase that is being started.
|
|
81
|
-
*/
|
|
82
|
-
startPurchase({ purchaseId }: {
|
|
83
|
-
purchaseId: Hex;
|
|
84
|
-
}): PreparedInteraction;
|
|
85
|
-
/**
|
|
86
|
-
* Encode a complete purchase interaction
|
|
87
|
-
* @param args
|
|
88
|
-
* @param args.purchaseId - The id of the purchase that is being completed.
|
|
89
|
-
* @param args.proof - The merkle proof that the user has completed the purchase (see [Purchase Webhooks](/wallet-sdk/references-api/webhook) for more details).
|
|
90
|
-
*/
|
|
91
|
-
completedPurchase({ purchaseId, proof, }: {
|
|
92
|
-
purchaseId: Hex;
|
|
93
|
-
proof: Hex[];
|
|
94
|
-
}): PreparedInteraction;
|
|
95
|
-
/**
|
|
96
|
-
* Encode an unsafe complete purchase interaction (when we can't provide the proof)
|
|
97
|
-
* @param args
|
|
98
|
-
* @param args.purchaseId - The id of the purchase that is being completed.
|
|
99
|
-
*/
|
|
100
|
-
unsafeCompletedPurchase({ purchaseId, }: {
|
|
101
|
-
purchaseId: Hex;
|
|
102
|
-
}): PreparedInteraction;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Referral interactions allow you to track user sharing activities.
|
|
107
|
-
* These interactions are essential for platforms looking to grow their user base through user-to-user referrals and reward systems.
|
|
108
|
-
*
|
|
109
|
-
* :::info
|
|
110
|
-
* To properly handle referral interactions, ensure that the "Referral" product type is enabled in your Business dashboard.
|
|
111
|
-
* :::
|
|
112
|
-
*
|
|
113
|
-
* @description Encode referral related user interactions
|
|
114
|
-
*
|
|
115
|
-
* @group Interactions Encoder
|
|
116
|
-
*
|
|
117
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
118
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
119
|
-
*/
|
|
120
|
-
export declare const ReferralInteractionEncoder: {
|
|
121
|
-
/**
|
|
122
|
-
* 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.
|
|
123
|
-
*/
|
|
124
|
-
createLink(): PreparedInteraction;
|
|
125
|
-
/**
|
|
126
|
-
* Encode a referred interaction
|
|
127
|
-
* @param args
|
|
128
|
-
* @param args.referrer - The Ethereum address of the user who made the referral
|
|
129
|
-
*/
|
|
130
|
-
referred({ referrer }: {
|
|
131
|
-
referrer: Address;
|
|
132
|
-
}): PreparedInteraction;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Retail interactions allow you to track user activities on your retails products.
|
|
137
|
-
*
|
|
138
|
-
* :::info
|
|
139
|
-
* To properly handle retail interactions, ensure that the "Retail" product type is enabled in your Business dashboard.
|
|
140
|
-
* :::
|
|
141
|
-
*
|
|
142
|
-
* @description Encode retail related user interactions
|
|
143
|
-
*
|
|
144
|
-
* @group Interactions Encoder
|
|
145
|
-
*
|
|
146
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
147
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
148
|
-
*/
|
|
149
|
-
export declare const RetailInteractionEncoder: {
|
|
150
|
-
/**
|
|
151
|
-
* Encode a customer meeting retail interaction
|
|
152
|
-
* @param args
|
|
153
|
-
* @param args.agencyId - The id of the agency that the customer is meeting with
|
|
154
|
-
*
|
|
155
|
-
*/
|
|
156
|
-
customerMeeting({ agencyId }: {
|
|
157
|
-
agencyId: Hex;
|
|
158
|
-
}): PreparedInteraction;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Webshop interactions allow you to track user activities on your webshop.
|
|
163
|
-
*
|
|
164
|
-
* :::info
|
|
165
|
-
* To properly handle webshop interactions, ensure that the "WebShop" product type is enabled in your Business dashboard.
|
|
166
|
-
* :::
|
|
167
|
-
*
|
|
168
|
-
* @description Encode webshop related user interactions
|
|
169
|
-
*
|
|
170
|
-
* @group Interactions Encoder
|
|
171
|
-
*
|
|
172
|
-
* @see {@link PreparedInteraction} The prepared interaction object that can be sent
|
|
173
|
-
* @see {@link !actions.sendInteraction | `sendInteraction()`} Action used to send the prepared interaction to the Frak Wallet
|
|
174
|
-
*/
|
|
175
|
-
export declare const WebShopInteractionEncoder: {
|
|
176
|
-
/**
|
|
177
|
-
* Encode an open webshop interaction
|
|
178
|
-
*/
|
|
179
|
-
open(): PreparedInteraction;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
export { }
|
package/dist/interactions.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{concatHex as e,encodeAbiParameters as r,pad as t,toHex as n}from"viem";let a="0xc0a24ffb",o="0xd5bd0fbe",i="0xb311798f",c="0x010cc3b9",l="0xb2c0f17c",p="0xd87e90c3",s="0x8403aeb4",d="0x4d5b14e0",h="0x74489004",u={dapp:1,press:2,webshop:3,retail:4,referral:30,purchase:31};Object.entries(u).reduce((e,[r,t])=>(e[r]=BigInt(1)<<BigInt(t),e),{});let m={openArticle({articleId:r}){let o=e([a,t(r,{size:32})]);return{handlerTypeDenominator:n(u.press),interactionData:o}},readArticle({articleId:r}){let a=e([o,t(r,{size:32})]);return{handlerTypeDenominator:n(u.press),interactionData:a}}},b={createLink:()=>({handlerTypeDenominator:n(u.referral),interactionData:l}),referred({referrer:r}){let a=e([c,t(r,{size:32})]);return{handlerTypeDenominator:n(u.referral),interactionData:a}}},f={startPurchase({purchaseId:r}){let a=e([p,t(r,{size:32})]);return{handlerTypeDenominator:n(u.purchase),interactionData:a}},completedPurchase({purchaseId:t,proof:a}){let o=r([{type:"uint256"},{type:"bytes32[]"}],[BigInt(t),a]),i=e([s,o]);return{handlerTypeDenominator:n(u.purchase),interactionData:i}},unsafeCompletedPurchase({purchaseId:r}){let a=e([d,t(r,{size:32})]);return{handlerTypeDenominator:n(u.purchase),interactionData:a}}},y={open:()=>({handlerTypeDenominator:n(u.webshop),interactionData:i})},D={customerMeeting({agencyId:r}){let a=e([h,t(r,{size:32})]);return{handlerTypeDenominator:n(u.retail),interactionData:a}}};export{m as PressInteractionEncoder,f as PurchaseInteractionEncoder,b as ReferralInteractionEncoder,D as RetailInteractionEncoder,y as WebShopInteractionEncoder};
|