@frak-labs/core-sdk 0.0.18 → 0.0.19-beta.f259d7fc
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/cdn/bundle.js +5 -5
- package/dist/actions.cjs +1 -1
- package/dist/actions.d.cts +60 -60
- package/dist/actions.d.ts +60 -60
- package/dist/actions.js +1 -1
- package/dist/bundle.cjs +2 -2
- package/dist/bundle.d.cts +80 -175
- package/dist/bundle.d.ts +80 -175
- package/dist/bundle.js +2 -2
- package/dist/index.cjs +11 -11
- package/dist/index.d.cts +69 -173
- package/dist/index.d.ts +69 -173
- package/dist/index.js +2 -2
- package/package.json +5 -1
package/dist/actions.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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__,{getProductInformation:()=>getProductInformation,displayModal:()=>displayModal,displayEmbeddedWallet:()=>displayEmbeddedWallet,processReferral:()=>processReferral,sendInteraction:()=>sendInteraction,watchWalletStatus:()=>watchWalletStatus,sendTransaction:()=>sendTransaction,modalBuilder:()=>modalBuilder,trackPurchaseStatus:()=>trackPurchaseStatus,siweAuthenticate:()=>siweAuthenticate,referralInteraction:()=>referralInteraction,openSso:()=>openSso});class Deferred{_promise;_resolve;_reject;constructor(){this._promise=new Promise((e,r)=>{this._resolve=e,this._reject=r})}get promise(){return this._promise}resolve=e=>{this._resolve?.(e)};reject=e=>{this._reject?.(e)}}function watchWalletStatus(e,r){if(!r)return e.request({method:"frak_listenToWalletStatus"}).then(r=>(walletStatusSideEffect(e,r),r));let t=new Deferred,a=!1;return e.listenerRequest({method:"frak_listenToWalletStatus"},n=>{walletStatusSideEffect(e,n),r(n),a||(t.resolve(n),a=!0)}).then(()=>t.promise)}function walletStatusSideEffect(e,r){"undefined"!=typeof window&&(e.openPanel?.setGlobalProperties({wallet:r.wallet??null}),r.interactionToken?window.sessionStorage.setItem("frak-wallet-interaction-token",r.interactionToken):window.sessionStorage.removeItem("frak-wallet-interaction-token"))}let external_viem_namespaceObject=require("viem");function computeProductId({domain:e}){let r=(e??window.location.host).replace("www.","");return(0,external_viem_namespaceObject.keccak256)((0,external_viem_namespaceObject.toHex)(r))}async function sendInteraction(e,{productId:r,interaction:t,validation:a}){let n=r??computeProductId(e.config);return await e.request({method:"frak_sendInteraction",params:[n,t,a]})}async function displayModal(e,{steps:r,metadata:t}){return await e.request({method:"frak_displayModal",params:[r,t,e.config.metadata]})}async function displayEmbeddedWallet(e,r){return await e.request({method:"frak_displayEmbeddedWallet",params:[r,e.config.metadata]})}async function openSso(e,r){let{metadata:t,customizations:a}=e.config;await e.request({method:"frak_sso",params:[r,t.name,a?.css]})}async function getProductInformation(e){return await e.request({method:"frak_getProductInformation"})}async function trackPurchaseStatus(e){if("undefined"==typeof window)return void console.warn("[Frak] No window found, can't track purchase");let r=window.sessionStorage.getItem("frak-wallet-interaction-token");if(!r)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":r},body:JSON.stringify(e)})}let siwe_namespaceObject=require("viem/siwe");async function siweAuthenticate(e,{siwe:r,metadata:t}){let a=e.config?.domain??window.location.host,n=r?.statement??`I confirm that I want to use my Frak wallet on: ${e.config.metadata.name}`,o={...r,statement:n,nonce:r?.nonce??(0,siwe_namespaceObject.generateSiweNonce)(),uri:r?.uri??`https://${a}`,version:r?.version??"1",domain:a};return(await displayModal(e,{metadata:t,steps:{login:{},siweAuthenticate:{siwe:o}}})).siweAuthenticate}async function sendTransaction(e,{tx:r,metadata:t}){return(await displayModal(e,{metadata:t,steps:{login:{},sendTransaction:{tx:r}}})).sendTransaction}function modalBuilder(e,{metadata:r,login:t,openSession:a}){return modalStepsBuilder(e,{steps:{login:t??{},openSession:a??{}},metadata:r})}function modalStepsBuilder(e,r){async function t(t){return t&&(r.metadata=t(r.metadata??{})),await displayModal(e,r)}return{params:r,sendTx:function(t){return modalStepsBuilder(e,{...r,steps:{...r.steps,sendTransaction:t}})},reward:function(t){return modalStepsBuilder(e,{...r,steps:{...r.steps,final:{...t,action:{key:"reward"}}}})},sharing:function(t,a){return modalStepsBuilder(e,{...r,steps:{...r.steps,final:{...a,action:{key:"sharing",options:t}}}})},display:t}}function base64urlEncode(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join("")).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function base64urlDecode(e){let r=e.length%4;return Uint8Array.from(atob(e.replace(/-/g,"+").replace(/_/g,"/").padEnd(e.length+(0===r?0:4-r),"=")),e=>e.charCodeAt(0))}let contextKey="fCtx";function compress(e){if(e?.r)try{let r=(0,external_viem_namespaceObject.hexToBytes)(e.r);return base64urlEncode(r)}catch(r){console.error("Error compressing Frak context",{e:r,context:e})}}function decompress(e){if(e&&0!==e.length)try{let r=base64urlDecode(e);return{r:(0,external_viem_namespaceObject.bytesToHex)(r,{size:20})}}catch(r){console.error("Error decompressing Frak context",{e:r,context:e})}}function parse({url:e}){if(!e)return null;let r=new URL(e).searchParams.get(contextKey);return r?decompress(r):null}function update({url:e,context:r}){if(!e)return null;let t=parse({url:e}),a=t?{...t,...r}:r;if(!a.r)return null;let n=compress(a);if(!n)return null;let o=new URL(e);return o.searchParams.set(contextKey,n),o.toString()}function remove(e){let r=new URL(e);return r.searchParams.delete(contextKey),r.toString()}function replaceUrl({url:e,context:r}){let t;if(!window.location?.href||"undefined"==typeof window)return void console.error("No window found, can't update context");let a=e??window.location.href;(t=null!==r?update({url:a,context:r}):remove(a))&&window.history.replaceState(null,"",t.toString())}let FrakContextManager={compress,decompress,parse,update,remove,replaceUrl},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),{}),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}}};class FrakRpcError extends Error{code;data;constructor(e,r,t){super(r),this.code=e,this.data=t}}class MethodNotFoundError extends FrakRpcError{constructor(e,r){super(RpcErrorCodes.methodNotFound,e,{method:r})}}class InternalError extends FrakRpcError{constructor(e){super(RpcErrorCodes.internalError,e)}}class ClientNotFound extends FrakRpcError{constructor(){super(RpcErrorCodes.clientNotConnected,"Client not found")}}let RpcErrorCodes={parseError:-32700,invalidRequest:-32600,methodNotFound:-32601,invalidParams:-32602,internalError:-32603,serverError:-32e3,clientNotConnected:-32001,configError:-32002,corruptedResponse:-32003,clientAborted:-32004,walletNotConnected:-32005,serverErrorForInteractionDelegation:-32006};function trackEvent(e,r,t={}){if(!e)return void console.debug("[Frak] No client provided, skipping event tracking");try{e.openPanel?.track(r,t)}catch(e){console.debug("[Frak] Failed to track event:",r,e)}}async function processReferral(e,{walletStatus:r,frakContext:t,modalConfig:a,productId:n,options:o}){let s=!1;async function c(){if(!s)return s=!0,ensureWalletConnected(e,{modalConfig:{...a,loggedIn:{action:{key:"referred"}}},walletStatus:r})}async function i(r){let t=ReferralInteractionEncoder.referred({referrer:r});await Promise.allSettled([sendInteraction(e,{productId:n,interaction:t}),trackEvent(e,"user_referred",{properties:{referrer:r}})])}try{let{status:e,currentWallet:a}=await processReferralLogic({initialWalletStatus:r,getFreshWalletStatus:c,pushReferralInteraction:i,frakContext:t});return FrakContextManager.replaceUrl({url:window.location?.href,context:o?.alwaysAppendUrl?{r:a}:null}),e}catch(e){return console.log("Error processing referral",{error:e}),FrakContextManager.replaceUrl({url:window.location?.href,context:o?.alwaysAppendUrl?{r:r?.wallet}:null}),mapErrorToState(e)}}async function processReferralLogic({initialWalletStatus:e,getFreshWalletStatus:r,pushReferralInteraction:t,frakContext:a}){let n=e?.wallet;return a?.r?(n||(n=await r()),n&&(0,external_viem_namespaceObject.isAddressEqual)(a.r,n))?{status:"self-referral",currentWallet:n}:(e?.interactionSession||(n=await r()),await t(a.r),{status:"success",currentWallet:n}):{status:"no-referrer",currentWallet:n}}async function ensureWalletConnected(e,{modalConfig:r,walletStatus:t}){if(!t?.interactionSession){let t=await displayEmbeddedWallet(e,r??{});return t?.wallet??void 0}return t.wallet??void 0}function mapErrorToState(e){if(e instanceof FrakRpcError)switch(e.code){case RpcErrorCodes.walletNotConnected:return"no-wallet";case RpcErrorCodes.serverErrorForInteractionDelegation:return"no-session"}return"error"}async function referralInteraction(e,{productId:r,modalConfig:t,options:a}={}){let n=FrakContextManager.parse({url:window.location.href}),o=await watchWalletStatus(e);try{return await processReferral(e,{walletStatus:o,frakContext:n,modalConfig:t,productId:r,options:a})}catch(e){console.warn("Error processing referral",{error:e})}}for(var __webpack_i__ in exports.displayEmbeddedWallet=__webpack_exports__.displayEmbeddedWallet,exports.displayModal=__webpack_exports__.displayModal,exports.getProductInformation=__webpack_exports__.getProductInformation,exports.modalBuilder=__webpack_exports__.modalBuilder,exports.openSso=__webpack_exports__.openSso,exports.processReferral=__webpack_exports__.processReferral,exports.referralInteraction=__webpack_exports__.referralInteraction,exports.sendInteraction=__webpack_exports__.sendInteraction,exports.sendTransaction=__webpack_exports__.sendTransaction,exports.siweAuthenticate=__webpack_exports__.siweAuthenticate,exports.trackPurchaseStatus=__webpack_exports__.trackPurchaseStatus,exports.watchWalletStatus=__webpack_exports__.watchWalletStatus,__webpack_exports__)-1===["displayEmbeddedWallet","displayModal","getProductInformation","modalBuilder","openSso","processReferral","referralInteraction","sendInteraction","sendTransaction","siweAuthenticate","trackPurchaseStatus","watchWalletStatus"].indexOf(__webpack_i__)&&(exports[__webpack_i__]=__webpack_exports__[__webpack_i__]);Object.defineProperty(exports,"__esModule",{value:!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,t)=>{for(var r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__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__,{getProductInformation:()=>getProductInformation,displayModal:()=>displayModal,displayEmbeddedWallet:()=>displayEmbeddedWallet,processReferral:()=>processReferral,sendInteraction:()=>sendInteraction,watchWalletStatus:()=>watchWalletStatus,sendTransaction:()=>sendTransaction,modalBuilder:()=>modalBuilder,trackPurchaseStatus:()=>trackPurchaseStatus,siweAuthenticate:()=>siweAuthenticate,referralInteraction:()=>referralInteraction,openSso:()=>openSso});let frame_connector_namespaceObject=require("@frak-labs/frame-connector");function watchWalletStatus(e,t){if(!t)return e.request({method:"frak_listenToWalletStatus"}).then(t=>(walletStatusSideEffect(e,t),t));let r=new frame_connector_namespaceObject.Deferred,a=!1;return e.listenerRequest({method:"frak_listenToWalletStatus"},n=>{walletStatusSideEffect(e,n),t(n),a||(r.resolve(n),a=!0)}),r.promise}function walletStatusSideEffect(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"))}let external_viem_namespaceObject=require("viem");function computeProductId({domain:e}){let t=(e??window.location.host).replace("www.","");return(0,external_viem_namespaceObject.keccak256)((0,external_viem_namespaceObject.toHex)(t))}async function sendInteraction(e,{productId:t,interaction:r,validation:a}){let n=t??computeProductId(e.config);return await e.request({method:"frak_sendInteraction",params:[n,r,a]})}async function displayModal(e,{steps:t,metadata:r}){return await e.request({method:"frak_displayModal",params:[t,r,e.config.metadata]})}async function displayEmbeddedWallet(e,t){return await e.request({method:"frak_displayEmbeddedWallet",params:[t,e.config.metadata]})}async function openSso(e,t){let{metadata:r,customizations:a}=e.config;return await e.request({method:"frak_sso",params:[t,r.name,a?.css]})??{}}async function getProductInformation(e){return await e.request({method:"frak_getProductInformation"})}async function trackPurchaseStatus(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)})}let siwe_namespaceObject=require("viem/siwe");async function siweAuthenticate(e,{siwe:t,metadata:r}){let a=e.config?.domain??window.location.host,n=t?.statement??`I confirm that I want to use my Frak wallet on: ${e.config.metadata.name}`,o={...t,statement:n,nonce:t?.nonce??(0,siwe_namespaceObject.generateSiweNonce)(),uri:t?.uri??`https://${a}`,version:t?.version??"1",domain:a};return(await displayModal(e,{metadata:r,steps:{login:{},siweAuthenticate:{siwe:o}}})).siweAuthenticate}async function sendTransaction(e,{tx:t,metadata:r}){return(await displayModal(e,{metadata:r,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}function modalBuilder(e,{metadata:t,login:r,openSession:a}){return modalStepsBuilder(e,{steps:{login:r??{},openSession:a??{}},metadata:t})}function modalStepsBuilder(e,t){async function r(r){return r&&(t.metadata=r(t.metadata??{})),await displayModal(e,t)}return{params:t,sendTx:function(r){return modalStepsBuilder(e,{...t,steps:{...t.steps,sendTransaction:r}})},reward:function(r){return modalStepsBuilder(e,{...t,steps:{...t.steps,final:{...r,action:{key:"reward"}}}})},sharing:function(r,a){return modalStepsBuilder(e,{...t,steps:{...t.steps,final:{...a,action:{key:"sharing",options:r}}}})},display:r}}function base64urlEncode(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join("")).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function base64urlDecode(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))}let contextKey="fCtx";function compress(e){if(e?.r)try{let t=(0,external_viem_namespaceObject.hexToBytes)(e.r);return base64urlEncode(t)}catch(t){console.error("Error compressing Frak context",{e:t,context:e})}}function decompress(e){if(e&&0!==e.length)try{let t=base64urlDecode(e);return{r:(0,external_viem_namespaceObject.bytesToHex)(t,{size:20})}}catch(t){console.error("Error decompressing Frak context",{e:t,context:e})}}function parse({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(contextKey);return t?decompress(t):null}function update({url:e,context:t}){if(!e)return null;let r=parse({url:e}),a=r?{...r,...t}:t;if(!a.r)return null;let n=compress(a);if(!n)return null;let o=new URL(e);return o.searchParams.set(contextKey,n),o.toString()}function remove(e){let t=new URL(e);return t.searchParams.delete(contextKey),t.toString()}function replaceUrl({url:e,context:t}){let r;if(!window.location?.href||"undefined"==typeof window)return void console.error("No window found, can't update context");let a=e??window.location.href;(r=null!==t?update({url:a,context:t}):remove(a))&&window.history.replaceState(null,"",r.toString())}let FrakContextManager={compress,decompress,parse,update,remove,replaceUrl},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,[t,r])=>(e[t]=BigInt(1)<<BigInt(r),e),{}),ReferralInteractionEncoder={createLink:()=>({handlerTypeDenominator:(0,external_viem_namespaceObject.toHex)(productTypes.referral),interactionData:interactionTypes.referral.createLink}),referred({referrer:e}){let t=(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:t}}};function trackEvent(e,t,r={}){if(!e)return void console.debug("[Frak] No client provided, skipping event tracking");try{e.openPanel?.track(t,r)}catch(e){console.debug("[Frak] Failed to track event:",t,e)}}async function processReferral(e,{walletStatus:t,frakContext:r,modalConfig:a,productId:n,options:o}){let c=!1;async function s(){if(!c)return c=!0,ensureWalletConnected(e,{modalConfig:{...a,loggedIn:{action:{key:"referred"}}},walletStatus:t})}async function i(t){let r=ReferralInteractionEncoder.referred({referrer:t});await Promise.allSettled([sendInteraction(e,{productId:n,interaction:r}),trackEvent(e,"user_referred",{properties:{referrer:t}})])}try{let{status:e,currentWallet:a}=await processReferralLogic({initialWalletStatus:t,getFreshWalletStatus:s,pushReferralInteraction:i,frakContext:r});return FrakContextManager.replaceUrl({url:window.location?.href,context:o?.alwaysAppendUrl?{r:a}:null}),e}catch(e){return console.log("Error processing referral",{error:e}),FrakContextManager.replaceUrl({url:window.location?.href,context:o?.alwaysAppendUrl?{r:t?.wallet}:null}),mapErrorToState(e)}}async function processReferralLogic({initialWalletStatus:e,getFreshWalletStatus:t,pushReferralInteraction:r,frakContext:a}){let n=e?.wallet;return a?.r?(n||(n=await t()),n&&(0,external_viem_namespaceObject.isAddressEqual)(a.r,n))?{status:"self-referral",currentWallet:n}:(e?.interactionSession||(n=await t()),await r(a.r),{status:"success",currentWallet:n}):{status:"no-referrer",currentWallet:n}}async function ensureWalletConnected(e,{modalConfig:t,walletStatus:r}){if(!r?.interactionSession){let r=await displayEmbeddedWallet(e,t??{});return r?.wallet??void 0}return r.wallet??void 0}function mapErrorToState(e){if(e instanceof frame_connector_namespaceObject.FrakRpcError)switch(e.code){case frame_connector_namespaceObject.RpcErrorCodes.walletNotConnected:return"no-wallet";case frame_connector_namespaceObject.RpcErrorCodes.serverErrorForInteractionDelegation:return"no-session"}return"error"}async function referralInteraction(e,{productId:t,modalConfig:r,options:a}={}){let n=FrakContextManager.parse({url:window.location.href}),o=await watchWalletStatus(e);try{return await processReferral(e,{walletStatus:o,frakContext:n,modalConfig:r,productId:t,options:a})}catch(e){console.warn("Error processing referral",{error:e})}}for(var __webpack_i__ in exports.displayEmbeddedWallet=__webpack_exports__.displayEmbeddedWallet,exports.displayModal=__webpack_exports__.displayModal,exports.getProductInformation=__webpack_exports__.getProductInformation,exports.modalBuilder=__webpack_exports__.modalBuilder,exports.openSso=__webpack_exports__.openSso,exports.processReferral=__webpack_exports__.processReferral,exports.referralInteraction=__webpack_exports__.referralInteraction,exports.sendInteraction=__webpack_exports__.sendInteraction,exports.sendTransaction=__webpack_exports__.sendTransaction,exports.siweAuthenticate=__webpack_exports__.siweAuthenticate,exports.trackPurchaseStatus=__webpack_exports__.trackPurchaseStatus,exports.watchWalletStatus=__webpack_exports__.watchWalletStatus,__webpack_exports__)-1===["displayEmbeddedWallet","displayModal","getProductInformation","modalBuilder","openSso","processReferral","referralInteraction","sendInteraction","sendTransaction","siweAuthenticate","trackPurchaseStatus","watchWalletStatus"].indexOf(__webpack_i__)&&(exports[__webpack_i__]=__webpack_exports__[__webpack_i__]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/actions.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Address } from 'viem';
|
|
2
2
|
import { Hex } from 'viem';
|
|
3
|
+
import type { LifecycleMessage } from '@frak-labs/frame-connector';
|
|
3
4
|
import type { OpenPanel } from '@openpanel/web';
|
|
4
|
-
import type {
|
|
5
|
-
import type { RpcSchema } from 'viem';
|
|
5
|
+
import type { RpcClient } from '@frak-labs/frame-connector';
|
|
6
6
|
import type { SiweMessage } from 'viem/siwe';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -237,34 +237,6 @@ declare type EmbeddedViewActionSharing = {
|
|
|
237
237
|
};
|
|
238
238
|
};
|
|
239
239
|
|
|
240
|
-
/**
|
|
241
|
-
* Type that extract the possible return type from a RPC Schema
|
|
242
|
-
* @ignore
|
|
243
|
-
*/
|
|
244
|
-
declare type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = Extract<TRpcSchema[number], {
|
|
245
|
-
Method: TMethod;
|
|
246
|
-
}>;
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Type that extract the possible parameters from a RPC Schema
|
|
250
|
-
* @ignore
|
|
251
|
-
*/
|
|
252
|
-
declare type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema> = {
|
|
253
|
-
[K in keyof TRpcSchema]: Prettify<{
|
|
254
|
-
method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
|
|
255
|
-
} & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
|
|
256
|
-
params?: never;
|
|
257
|
-
} : {
|
|
258
|
-
params: TRpcSchema[K]["Parameters"];
|
|
259
|
-
} : never)>;
|
|
260
|
-
}[number];
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Type that extract the possible return type from a RPC Schema
|
|
264
|
-
* @ignore
|
|
265
|
-
*/
|
|
266
|
-
declare type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"];
|
|
267
|
-
|
|
268
240
|
/**
|
|
269
241
|
* The different types of final actions we can display in the final step
|
|
270
242
|
* @group Modal Display
|
|
@@ -490,40 +462,51 @@ declare type I18nConfig = Record<Language, LocalizedI18nConfig> | LocalizedI18nC
|
|
|
490
462
|
/**
|
|
491
463
|
* RPC interface that's used for the iframe communication
|
|
492
464
|
*
|
|
493
|
-
* Define all the methods available within the iFrame RPC client
|
|
465
|
+
* Define all the methods available within the iFrame RPC client with response type annotations
|
|
494
466
|
*
|
|
495
467
|
* @group RPC Schema
|
|
496
468
|
*
|
|
497
469
|
* @remarks
|
|
498
|
-
*
|
|
470
|
+
* Each method in the schema now includes a ResponseType field that indicates:
|
|
471
|
+
* - "promise": One-shot request that resolves once
|
|
472
|
+
* - "stream": Streaming request that can emit multiple values
|
|
499
473
|
*
|
|
500
|
-
* ###
|
|
474
|
+
* ### Methods:
|
|
475
|
+
*
|
|
476
|
+
* #### frak_listenToWalletStatus
|
|
501
477
|
* - Params: None
|
|
502
478
|
* - Returns: {@link WalletStatusReturnType}
|
|
479
|
+
* - Response Type: stream (emits updates when wallet status changes)
|
|
503
480
|
*
|
|
504
|
-
*
|
|
505
|
-
* - Params: [{@link ModalRpcStepsInput},
|
|
481
|
+
* #### frak_displayModal
|
|
482
|
+
* - Params: [requests: {@link ModalRpcStepsInput}, metadata?: {@link ModalRpcMetadata}, configMetadata: {@link FrakWalletSdkConfig}["metadata"]]
|
|
506
483
|
* - Returns: {@link ModalRpcStepsResultType}
|
|
484
|
+
* - Response Type: promise (one-shot)
|
|
507
485
|
*
|
|
508
|
-
*
|
|
486
|
+
* #### frak_sendInteraction
|
|
509
487
|
* - Params: [productId: Hex, interaction: {@link PreparedInteraction}, signature?: Hex]
|
|
510
488
|
* - Returns: {@link SendInteractionReturnType}
|
|
489
|
+
* - Response Type: promise (one-shot)
|
|
511
490
|
*
|
|
512
|
-
*
|
|
513
|
-
* - Params [params: {@link OpenSsoParamsType}, name: string, customCss?: string]
|
|
514
|
-
* - Returns:
|
|
491
|
+
* #### frak_sso
|
|
492
|
+
* - Params: [params: {@link OpenSsoParamsType}, name: string, customCss?: string]
|
|
493
|
+
* - Returns: {@link OpenSsoReturnType}
|
|
494
|
+
* - Response Type: promise (one-shot)
|
|
515
495
|
*
|
|
516
|
-
*
|
|
496
|
+
* #### frak_getProductInformation
|
|
517
497
|
* - Params: None
|
|
518
498
|
* - Returns: {@link GetProductInformationReturnType}
|
|
499
|
+
* - Response Type: promise (one-shot)
|
|
519
500
|
*
|
|
520
|
-
*
|
|
521
|
-
* - Params: [{@link DisplayEmbeddedWalletParamsType}]
|
|
501
|
+
* #### frak_displayEmbeddedWallet
|
|
502
|
+
* - Params: [request: {@link DisplayEmbeddedWalletParamsType}, metadata: {@link FrakWalletSdkConfig}["metadata"]]
|
|
522
503
|
* - Returns: {@link DisplayEmbeddedWalletResultType}
|
|
504
|
+
* - Response Type: promise (one-shot)
|
|
523
505
|
*/
|
|
524
506
|
declare type IFrameRpcSchema = [
|
|
525
507
|
/**
|
|
526
508
|
* Method used to listen to the wallet status
|
|
509
|
+
* This is a streaming method that emits updates when wallet status changes
|
|
527
510
|
*/
|
|
528
511
|
{
|
|
529
512
|
Method: "frak_listenToWalletStatus";
|
|
@@ -532,6 +515,7 @@ declare type IFrameRpcSchema = [
|
|
|
532
515
|
},
|
|
533
516
|
/**
|
|
534
517
|
* Method to display a modal with the provided steps
|
|
518
|
+
* This is a one-shot request
|
|
535
519
|
*/
|
|
536
520
|
{
|
|
537
521
|
Method: "frak_displayModal";
|
|
@@ -544,6 +528,7 @@ declare type IFrameRpcSchema = [
|
|
|
544
528
|
},
|
|
545
529
|
/**
|
|
546
530
|
* Method to transmit a user interaction
|
|
531
|
+
* This is a one-shot request
|
|
547
532
|
*/
|
|
548
533
|
{
|
|
549
534
|
Method: "frak_sendInteraction";
|
|
@@ -556,7 +541,7 @@ declare type IFrameRpcSchema = [
|
|
|
556
541
|
},
|
|
557
542
|
/**
|
|
558
543
|
* Method to start a SSO
|
|
559
|
-
*
|
|
544
|
+
* This is a one-shot request
|
|
560
545
|
*/
|
|
561
546
|
{
|
|
562
547
|
Method: "frak_sso";
|
|
@@ -565,13 +550,14 @@ declare type IFrameRpcSchema = [
|
|
|
565
550
|
name: string,
|
|
566
551
|
customCss?: string
|
|
567
552
|
];
|
|
568
|
-
ReturnType:
|
|
553
|
+
ReturnType: OpenSsoReturnType;
|
|
569
554
|
},
|
|
570
555
|
/**
|
|
571
556
|
* Method to get current product information's
|
|
572
557
|
* - Is product minted?
|
|
573
558
|
* - Does it have running campaign?
|
|
574
559
|
* - Estimated reward on actions
|
|
560
|
+
* This is a one-shot request
|
|
575
561
|
*/
|
|
576
562
|
{
|
|
577
563
|
Method: "frak_getProductInformation";
|
|
@@ -580,6 +566,7 @@ declare type IFrameRpcSchema = [
|
|
|
580
566
|
},
|
|
581
567
|
/**
|
|
582
568
|
* Method to show the embedded wallet, with potential customization
|
|
569
|
+
* This is a one-shot request
|
|
583
570
|
*/
|
|
584
571
|
{
|
|
585
572
|
Method: "frak_displayEmbeddedWallet";
|
|
@@ -606,11 +593,11 @@ declare type IFrameTransport = {
|
|
|
606
593
|
/**
|
|
607
594
|
* Function used to perform a single request via the iframe transport
|
|
608
595
|
*/
|
|
609
|
-
request:
|
|
596
|
+
request: RpcClient<IFrameRpcSchema, LifecycleMessage>["request"];
|
|
610
597
|
/**
|
|
611
598
|
* Function used to listen to a request response via the iframe transport
|
|
612
599
|
*/
|
|
613
|
-
listenerRequest:
|
|
600
|
+
listenerRequest: RpcClient<IFrameRpcSchema, LifecycleMessage>["listen"];
|
|
614
601
|
/**
|
|
615
602
|
* Function used to destroy the iframe transport
|
|
616
603
|
*/
|
|
@@ -652,12 +639,6 @@ declare const interactionTypes: {
|
|
|
652
639
|
*/
|
|
653
640
|
declare type Language = "fr" | "en";
|
|
654
641
|
|
|
655
|
-
/**
|
|
656
|
-
* Type used for a listening request
|
|
657
|
-
* @inline
|
|
658
|
-
*/
|
|
659
|
-
declare type ListenerRequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters, callback: (result: _ReturnType) => void) => Promise<void>;
|
|
660
|
-
|
|
661
642
|
/**
|
|
662
643
|
* A localized i18n config
|
|
663
644
|
* @category Config
|
|
@@ -954,9 +935,18 @@ declare type OpenInteractionSessionReturnType = {
|
|
|
954
935
|
* metadata,
|
|
955
936
|
* });
|
|
956
937
|
* ```
|
|
938
|
+
* ```ts [With tracking]
|
|
939
|
+
* // Trigger an sso with consumeKey for tracking
|
|
940
|
+
* const result = await openSso(frakConfig, {
|
|
941
|
+
* directExit: true,
|
|
942
|
+
* generateConsumeKey: true,
|
|
943
|
+
* metadata,
|
|
944
|
+
* });
|
|
945
|
+
* console.log(result.consumeKey); // Use this to track SSO status
|
|
946
|
+
* ```
|
|
957
947
|
* :::
|
|
958
948
|
*/
|
|
959
|
-
export declare function openSso(client: FrakClient, args: OpenSsoParamsType): Promise<
|
|
949
|
+
export declare function openSso(client: FrakClient, args: OpenSsoParamsType): Promise<OpenSsoReturnType>;
|
|
960
950
|
|
|
961
951
|
/**
|
|
962
952
|
* Params to start a SSO
|
|
@@ -972,6 +962,11 @@ declare type OpenSsoParamsType = {
|
|
|
972
962
|
* @defaultValue true
|
|
973
963
|
*/
|
|
974
964
|
directExit?: boolean;
|
|
965
|
+
/**
|
|
966
|
+
* If true, opens SSO in same window instead of popup
|
|
967
|
+
* Defaults to true when redirectUrl is provided, false otherwise
|
|
968
|
+
*/
|
|
969
|
+
openInSameWindow?: boolean;
|
|
975
970
|
/**
|
|
976
971
|
* Language of the SSO page (optional)
|
|
977
972
|
* It will default to the current user language (or "en" if unsupported language)
|
|
@@ -983,6 +978,17 @@ declare type OpenSsoParamsType = {
|
|
|
983
978
|
metadata: SsoMetadata;
|
|
984
979
|
};
|
|
985
980
|
|
|
981
|
+
/**
|
|
982
|
+
* Response after an SSO has been openned
|
|
983
|
+
*/
|
|
984
|
+
declare type OpenSsoReturnType = {
|
|
985
|
+
/**
|
|
986
|
+
* Optional wallet address, returned when SSO completes via postMessage
|
|
987
|
+
* Note: Only present when SSO flow completes (not immediately on open)
|
|
988
|
+
*/
|
|
989
|
+
wallet?: Hex;
|
|
990
|
+
};
|
|
991
|
+
|
|
986
992
|
/**
|
|
987
993
|
* Represent a prepared user interaction, ready to be sent on-chain via the wallet
|
|
988
994
|
*/
|
|
@@ -1083,12 +1089,6 @@ export declare function referralInteraction(client: FrakClient, { productId, mod
|
|
|
1083
1089
|
*/
|
|
1084
1090
|
declare type ReferralState = "idle" | "processing" | "success" | "no-wallet" | "no-session" | "error" | "no-referrer" | "self-referral";
|
|
1085
1091
|
|
|
1086
|
-
/**
|
|
1087
|
-
* Type used for a one shot request function
|
|
1088
|
-
* @inline
|
|
1089
|
-
*/
|
|
1090
|
-
declare type RequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters) => Promise<_ReturnType>;
|
|
1091
|
-
|
|
1092
1092
|
/**
|
|
1093
1093
|
* Function used to send an interaction
|
|
1094
1094
|
* @param client - The current Frak Client
|
|
@@ -1381,7 +1381,7 @@ declare type WalletStatusReturnType = WalletConnected | WalletNotConnected;
|
|
|
1381
1381
|
* Function used to watch the current frak wallet status
|
|
1382
1382
|
* @param client - The current Frak Client
|
|
1383
1383
|
* @param callback - The callback that will receive any wallet status change
|
|
1384
|
-
* @returns A
|
|
1384
|
+
* @returns A promise resolving with the initial wallet status
|
|
1385
1385
|
*
|
|
1386
1386
|
* @description This function will return the current wallet status, and will listen to any change in the wallet status.
|
|
1387
1387
|
*
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Address } from 'viem';
|
|
2
2
|
import { Hex } from 'viem';
|
|
3
|
+
import type { LifecycleMessage } from '@frak-labs/frame-connector';
|
|
3
4
|
import type { OpenPanel } from '@openpanel/web';
|
|
4
|
-
import type {
|
|
5
|
-
import type { RpcSchema } from 'viem';
|
|
5
|
+
import type { RpcClient } from '@frak-labs/frame-connector';
|
|
6
6
|
import type { SiweMessage } from 'viem/siwe';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -237,34 +237,6 @@ declare type EmbeddedViewActionSharing = {
|
|
|
237
237
|
};
|
|
238
238
|
};
|
|
239
239
|
|
|
240
|
-
/**
|
|
241
|
-
* Type that extract the possible return type from a RPC Schema
|
|
242
|
-
* @ignore
|
|
243
|
-
*/
|
|
244
|
-
declare type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = Extract<TRpcSchema[number], {
|
|
245
|
-
Method: TMethod;
|
|
246
|
-
}>;
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Type that extract the possible parameters from a RPC Schema
|
|
250
|
-
* @ignore
|
|
251
|
-
*/
|
|
252
|
-
declare type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema> = {
|
|
253
|
-
[K in keyof TRpcSchema]: Prettify<{
|
|
254
|
-
method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
|
|
255
|
-
} & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
|
|
256
|
-
params?: never;
|
|
257
|
-
} : {
|
|
258
|
-
params: TRpcSchema[K]["Parameters"];
|
|
259
|
-
} : never)>;
|
|
260
|
-
}[number];
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Type that extract the possible return type from a RPC Schema
|
|
264
|
-
* @ignore
|
|
265
|
-
*/
|
|
266
|
-
declare type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"];
|
|
267
|
-
|
|
268
240
|
/**
|
|
269
241
|
* The different types of final actions we can display in the final step
|
|
270
242
|
* @group Modal Display
|
|
@@ -490,40 +462,51 @@ declare type I18nConfig = Record<Language, LocalizedI18nConfig> | LocalizedI18nC
|
|
|
490
462
|
/**
|
|
491
463
|
* RPC interface that's used for the iframe communication
|
|
492
464
|
*
|
|
493
|
-
* Define all the methods available within the iFrame RPC client
|
|
465
|
+
* Define all the methods available within the iFrame RPC client with response type annotations
|
|
494
466
|
*
|
|
495
467
|
* @group RPC Schema
|
|
496
468
|
*
|
|
497
469
|
* @remarks
|
|
498
|
-
*
|
|
470
|
+
* Each method in the schema now includes a ResponseType field that indicates:
|
|
471
|
+
* - "promise": One-shot request that resolves once
|
|
472
|
+
* - "stream": Streaming request that can emit multiple values
|
|
499
473
|
*
|
|
500
|
-
* ###
|
|
474
|
+
* ### Methods:
|
|
475
|
+
*
|
|
476
|
+
* #### frak_listenToWalletStatus
|
|
501
477
|
* - Params: None
|
|
502
478
|
* - Returns: {@link WalletStatusReturnType}
|
|
479
|
+
* - Response Type: stream (emits updates when wallet status changes)
|
|
503
480
|
*
|
|
504
|
-
*
|
|
505
|
-
* - Params: [{@link ModalRpcStepsInput},
|
|
481
|
+
* #### frak_displayModal
|
|
482
|
+
* - Params: [requests: {@link ModalRpcStepsInput}, metadata?: {@link ModalRpcMetadata}, configMetadata: {@link FrakWalletSdkConfig}["metadata"]]
|
|
506
483
|
* - Returns: {@link ModalRpcStepsResultType}
|
|
484
|
+
* - Response Type: promise (one-shot)
|
|
507
485
|
*
|
|
508
|
-
*
|
|
486
|
+
* #### frak_sendInteraction
|
|
509
487
|
* - Params: [productId: Hex, interaction: {@link PreparedInteraction}, signature?: Hex]
|
|
510
488
|
* - Returns: {@link SendInteractionReturnType}
|
|
489
|
+
* - Response Type: promise (one-shot)
|
|
511
490
|
*
|
|
512
|
-
*
|
|
513
|
-
* - Params [params: {@link OpenSsoParamsType}, name: string, customCss?: string]
|
|
514
|
-
* - Returns:
|
|
491
|
+
* #### frak_sso
|
|
492
|
+
* - Params: [params: {@link OpenSsoParamsType}, name: string, customCss?: string]
|
|
493
|
+
* - Returns: {@link OpenSsoReturnType}
|
|
494
|
+
* - Response Type: promise (one-shot)
|
|
515
495
|
*
|
|
516
|
-
*
|
|
496
|
+
* #### frak_getProductInformation
|
|
517
497
|
* - Params: None
|
|
518
498
|
* - Returns: {@link GetProductInformationReturnType}
|
|
499
|
+
* - Response Type: promise (one-shot)
|
|
519
500
|
*
|
|
520
|
-
*
|
|
521
|
-
* - Params: [{@link DisplayEmbeddedWalletParamsType}]
|
|
501
|
+
* #### frak_displayEmbeddedWallet
|
|
502
|
+
* - Params: [request: {@link DisplayEmbeddedWalletParamsType}, metadata: {@link FrakWalletSdkConfig}["metadata"]]
|
|
522
503
|
* - Returns: {@link DisplayEmbeddedWalletResultType}
|
|
504
|
+
* - Response Type: promise (one-shot)
|
|
523
505
|
*/
|
|
524
506
|
declare type IFrameRpcSchema = [
|
|
525
507
|
/**
|
|
526
508
|
* Method used to listen to the wallet status
|
|
509
|
+
* This is a streaming method that emits updates when wallet status changes
|
|
527
510
|
*/
|
|
528
511
|
{
|
|
529
512
|
Method: "frak_listenToWalletStatus";
|
|
@@ -532,6 +515,7 @@ declare type IFrameRpcSchema = [
|
|
|
532
515
|
},
|
|
533
516
|
/**
|
|
534
517
|
* Method to display a modal with the provided steps
|
|
518
|
+
* This is a one-shot request
|
|
535
519
|
*/
|
|
536
520
|
{
|
|
537
521
|
Method: "frak_displayModal";
|
|
@@ -544,6 +528,7 @@ declare type IFrameRpcSchema = [
|
|
|
544
528
|
},
|
|
545
529
|
/**
|
|
546
530
|
* Method to transmit a user interaction
|
|
531
|
+
* This is a one-shot request
|
|
547
532
|
*/
|
|
548
533
|
{
|
|
549
534
|
Method: "frak_sendInteraction";
|
|
@@ -556,7 +541,7 @@ declare type IFrameRpcSchema = [
|
|
|
556
541
|
},
|
|
557
542
|
/**
|
|
558
543
|
* Method to start a SSO
|
|
559
|
-
*
|
|
544
|
+
* This is a one-shot request
|
|
560
545
|
*/
|
|
561
546
|
{
|
|
562
547
|
Method: "frak_sso";
|
|
@@ -565,13 +550,14 @@ declare type IFrameRpcSchema = [
|
|
|
565
550
|
name: string,
|
|
566
551
|
customCss?: string
|
|
567
552
|
];
|
|
568
|
-
ReturnType:
|
|
553
|
+
ReturnType: OpenSsoReturnType;
|
|
569
554
|
},
|
|
570
555
|
/**
|
|
571
556
|
* Method to get current product information's
|
|
572
557
|
* - Is product minted?
|
|
573
558
|
* - Does it have running campaign?
|
|
574
559
|
* - Estimated reward on actions
|
|
560
|
+
* This is a one-shot request
|
|
575
561
|
*/
|
|
576
562
|
{
|
|
577
563
|
Method: "frak_getProductInformation";
|
|
@@ -580,6 +566,7 @@ declare type IFrameRpcSchema = [
|
|
|
580
566
|
},
|
|
581
567
|
/**
|
|
582
568
|
* Method to show the embedded wallet, with potential customization
|
|
569
|
+
* This is a one-shot request
|
|
583
570
|
*/
|
|
584
571
|
{
|
|
585
572
|
Method: "frak_displayEmbeddedWallet";
|
|
@@ -606,11 +593,11 @@ declare type IFrameTransport = {
|
|
|
606
593
|
/**
|
|
607
594
|
* Function used to perform a single request via the iframe transport
|
|
608
595
|
*/
|
|
609
|
-
request:
|
|
596
|
+
request: RpcClient<IFrameRpcSchema, LifecycleMessage>["request"];
|
|
610
597
|
/**
|
|
611
598
|
* Function used to listen to a request response via the iframe transport
|
|
612
599
|
*/
|
|
613
|
-
listenerRequest:
|
|
600
|
+
listenerRequest: RpcClient<IFrameRpcSchema, LifecycleMessage>["listen"];
|
|
614
601
|
/**
|
|
615
602
|
* Function used to destroy the iframe transport
|
|
616
603
|
*/
|
|
@@ -652,12 +639,6 @@ declare const interactionTypes: {
|
|
|
652
639
|
*/
|
|
653
640
|
declare type Language = "fr" | "en";
|
|
654
641
|
|
|
655
|
-
/**
|
|
656
|
-
* Type used for a listening request
|
|
657
|
-
* @inline
|
|
658
|
-
*/
|
|
659
|
-
declare type ListenerRequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters, callback: (result: _ReturnType) => void) => Promise<void>;
|
|
660
|
-
|
|
661
642
|
/**
|
|
662
643
|
* A localized i18n config
|
|
663
644
|
* @category Config
|
|
@@ -954,9 +935,18 @@ declare type OpenInteractionSessionReturnType = {
|
|
|
954
935
|
* metadata,
|
|
955
936
|
* });
|
|
956
937
|
* ```
|
|
938
|
+
* ```ts [With tracking]
|
|
939
|
+
* // Trigger an sso with consumeKey for tracking
|
|
940
|
+
* const result = await openSso(frakConfig, {
|
|
941
|
+
* directExit: true,
|
|
942
|
+
* generateConsumeKey: true,
|
|
943
|
+
* metadata,
|
|
944
|
+
* });
|
|
945
|
+
* console.log(result.consumeKey); // Use this to track SSO status
|
|
946
|
+
* ```
|
|
957
947
|
* :::
|
|
958
948
|
*/
|
|
959
|
-
export declare function openSso(client: FrakClient, args: OpenSsoParamsType): Promise<
|
|
949
|
+
export declare function openSso(client: FrakClient, args: OpenSsoParamsType): Promise<OpenSsoReturnType>;
|
|
960
950
|
|
|
961
951
|
/**
|
|
962
952
|
* Params to start a SSO
|
|
@@ -972,6 +962,11 @@ declare type OpenSsoParamsType = {
|
|
|
972
962
|
* @defaultValue true
|
|
973
963
|
*/
|
|
974
964
|
directExit?: boolean;
|
|
965
|
+
/**
|
|
966
|
+
* If true, opens SSO in same window instead of popup
|
|
967
|
+
* Defaults to true when redirectUrl is provided, false otherwise
|
|
968
|
+
*/
|
|
969
|
+
openInSameWindow?: boolean;
|
|
975
970
|
/**
|
|
976
971
|
* Language of the SSO page (optional)
|
|
977
972
|
* It will default to the current user language (or "en" if unsupported language)
|
|
@@ -983,6 +978,17 @@ declare type OpenSsoParamsType = {
|
|
|
983
978
|
metadata: SsoMetadata;
|
|
984
979
|
};
|
|
985
980
|
|
|
981
|
+
/**
|
|
982
|
+
* Response after an SSO has been openned
|
|
983
|
+
*/
|
|
984
|
+
declare type OpenSsoReturnType = {
|
|
985
|
+
/**
|
|
986
|
+
* Optional wallet address, returned when SSO completes via postMessage
|
|
987
|
+
* Note: Only present when SSO flow completes (not immediately on open)
|
|
988
|
+
*/
|
|
989
|
+
wallet?: Hex;
|
|
990
|
+
};
|
|
991
|
+
|
|
986
992
|
/**
|
|
987
993
|
* Represent a prepared user interaction, ready to be sent on-chain via the wallet
|
|
988
994
|
*/
|
|
@@ -1083,12 +1089,6 @@ export declare function referralInteraction(client: FrakClient, { productId, mod
|
|
|
1083
1089
|
*/
|
|
1084
1090
|
declare type ReferralState = "idle" | "processing" | "success" | "no-wallet" | "no-session" | "error" | "no-referrer" | "self-referral";
|
|
1085
1091
|
|
|
1086
|
-
/**
|
|
1087
|
-
* Type used for a one shot request function
|
|
1088
|
-
* @inline
|
|
1089
|
-
*/
|
|
1090
|
-
declare type RequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters) => Promise<_ReturnType>;
|
|
1091
|
-
|
|
1092
1092
|
/**
|
|
1093
1093
|
* Function used to send an interaction
|
|
1094
1094
|
* @param client - The current Frak Client
|
|
@@ -1381,7 +1381,7 @@ declare type WalletStatusReturnType = WalletConnected | WalletNotConnected;
|
|
|
1381
1381
|
* Function used to watch the current frak wallet status
|
|
1382
1382
|
* @param client - The current Frak Client
|
|
1383
1383
|
* @param callback - The callback that will receive any wallet status change
|
|
1384
|
-
* @returns A
|
|
1384
|
+
* @returns A promise resolving with the initial wallet status
|
|
1385
1385
|
*
|
|
1386
1386
|
* @description This function will return the current wallet status, and will listen to any change in the wallet status.
|
|
1387
1387
|
*
|
package/dist/actions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Deferred as e,FrakRpcError as t,RpcErrorCodes as n}from"@frak-labs/frame-connector";import{bytesToHex as r,concatHex as a,hexToBytes as o,isAddressEqual as i,keccak256 as s,pad as l,toHex as c}from"viem";import{generateSiweNonce as u}from"viem/siwe";function f(t,n){if(!n)return t.request({method:"frak_listenToWalletStatus"}).then(e=>(d(t,e),e));let r=new e,a=!1;return t.listenerRequest({method:"frak_listenToWalletStatus"},e=>{d(t,e),n(e),a||(r.resolve(e),a=!0)}),r.promise}function d(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 w(e,{productId:t,interaction:n,validation:r}){let a=t??function({domain:e}){return s(c((e??window.location.host).replace("www.","")))}(e.config);return await e.request({method:"frak_sendInteraction",params:[a,n,r]})}async function p(e,{steps:t,metadata:n}){return await e.request({method:"frak_displayModal",params:[t,n,e.config.metadata]})}async function m(e,t){return await e.request({method:"frak_displayEmbeddedWallet",params:[t,e.config.metadata]})}async function h(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:"frak_sso",params:[t,n.name,r?.css]})??{}}async function g(e){return await e.request({method:"frak_getProductInformation"})}async function y(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 k(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??u(),uri:t?.uri??`https://${r}`,version:t?.version??"1",domain:r};return(await p(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:o}}})).siweAuthenticate}async function S(e,{tx:t,metadata:n}){return(await p(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}function v(e,{metadata:t,login:n,openSession:r}){return function e(t,n){async function r(e){return e&&(n.metadata=e(n.metadata??{})),await p(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 b="fCtx";function I({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(b);return t?function(e){if(e&&0!==e.length)try{let t=function(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))}(e);return{r:r(t,{size:20})}}catch(t){console.error("Error decompressing Frak context",{e:t,context:e})}}(t):null}let T={parse:I,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?function({url:e,context:t}){if(!e)return null;let n=I({url:e}),r=n?{...n,...t}:t;if(!r.r)return null;let a=function(e){if(e?.r)try{var t;return t=o(e.r),btoa(Array.from(t,e=>String.fromCharCode(e)).join("")).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}catch(t){console.error("Error compressing Frak context",{e:t,context:e})}}(r);if(!a)return null;let i=new URL(e);return i.searchParams.set(b,a),i.toString()}({url:r,context:t}):function(e){let t=new URL(e);return t.searchParams.delete(b),t.toString()}(r))&&window.history.replaceState(null,"",n.toString())}},P="0x010cc3b9",x="0xb2c0f17c",F={dapp:1,press:2,webshop:3,retail:4,referral:30,purchase:31};Object.entries(F).reduce((e,[t,n])=>(e[t]=BigInt(1)<<BigInt(n),e),{});let _={createLink:()=>({handlerTypeDenominator:c(F.referral),interactionData:x}),referred({referrer:e}){let t=a([P,l(e,{size:32})]);return{handlerTypeDenominator:c(F.referral),interactionData:t}}};async function A(e,{walletStatus:r,frakContext:a,modalConfig:o,productId:i,options:s}){let l=!1;async function c(){if(!l)return l=!0,E(e,{modalConfig:{...o,loggedIn:{action:{key:"referred"}}},walletStatus:r})}async function u(t){let n=_.referred({referrer:t});await Promise.allSettled([w(e,{productId:i,interaction:n}),function(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)}}(e,"user_referred",{properties:{referrer:t}})])}try{let{status:e,currentWallet:t}=await U({initialWalletStatus:r,getFreshWalletStatus:c,pushReferralInteraction:u,frakContext:a});return T.replaceUrl({url:window.location?.href,context:s?.alwaysAppendUrl?{r:t}:null}),e}catch(e){return console.log("Error processing referral",{error:e}),T.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 U({initialWalletStatus:e,getFreshWalletStatus:t,pushReferralInteraction:n,frakContext:r}){let a=e?.wallet;return r?.r?(a||(a=await t()),a&&i(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 E(e,{modalConfig:t,walletStatus:n}){if(!n?.interactionSession){let n=await m(e,t??{});return n?.wallet??void 0}return n.wallet??void 0}async function q(e,{productId:t,modalConfig:n,options:r}={}){let a=T.parse({url:window.location.href}),o=await f(e);try{return await A(e,{walletStatus:o,frakContext:a,modalConfig:n,productId:t,options:r})}catch(e){console.warn("Error processing referral",{error:e})}}export{m as displayEmbeddedWallet,p as displayModal,g as getProductInformation,v as modalBuilder,h as openSso,A as processReferral,q as referralInteraction,w as sendInteraction,S as sendTransaction,k as siweAuthenticate,y as trackPurchaseStatus,f as watchWalletStatus};
|