@frak-labs/core-sdk 0.0.16 → 0.0.18-beta.27947565
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 +62 -60
- package/dist/actions.d.ts +62 -60
- package/dist/actions.js +1 -1
- package/dist/bundle.cjs +13 -0
- package/dist/bundle.d.cts +1927 -0
- package/dist/bundle.d.ts +1927 -0
- package/dist/bundle.js +13 -0
- package/dist/index.cjs +11 -11
- package/dist/index.d.cts +76 -172
- package/dist/index.d.ts +76 -172
- package/dist/index.js +2 -2
- package/dist/interactions.cjs +1 -1
- package/dist/interactions.js +1 -1
- package/package.json +23 -6
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__,{openSso:()=>openSso,referralInteraction:()=>referralInteraction,trackPurchaseStatus:()=>trackPurchaseStatus,modalBuilder:()=>modalBuilder,processReferral:()=>processReferral,sendTransaction:()=>sendTransaction,displayModal:()=>displayModal,getProductInformation:()=>getProductInformation,displayEmbeddedWallet:()=>displayEmbeddedWallet,sendInteraction:()=>sendInteraction,siweAuthenticate:()=>siweAuthenticate,watchWalletStatus:()=>watchWalletStatus});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(e=>(savePotentialToken(e.interactionToken),e));let t=new Deferred,a=!1;return e.listenerRequest({method:"frak_listenToWalletStatus"},e=>{r(e),savePotentialToken(e.interactionToken),a||(t.resolve(e),a=!0)}).then(()=>t.promise)}function savePotentialToken(e){"undefined"!=typeof window&&(e?window.sessionStorage.setItem("frak-wallet-interaction-token",e):window.sessionStorage.removeItem("frak.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};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 sendInteraction(e,{productId:n,interaction:t})}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 rpc_namespaceObject=require("@frak-labs/rpc");function watchWalletStatus(e,t){if(!t)return e.request({method:"frak_listenToWalletStatus"}).then(t=>(walletStatusSideEffect(e,t),t));let r=new rpc_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 s=!1;async function c(){if(!s)return s=!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:c,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 rpc_namespaceObject.FrakRpcError)switch(e.code){case rpc_namespaceObject.RpcErrorCodes.walletNotConnected:return"no-wallet";case rpc_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,7 +1,8 @@
|
|
|
1
1
|
import type { Address } from 'viem';
|
|
2
2
|
import { Hex } from 'viem';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
3
|
+
import type { LifecycleMessage } from '@frak-labs/rpc';
|
|
4
|
+
import type { OpenPanel } from '@openpanel/web';
|
|
5
|
+
import type { RpcClient } from '@frak-labs/rpc';
|
|
5
6
|
import type { SiweMessage } from 'viem/siwe';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -236,34 +237,6 @@ declare type EmbeddedViewActionSharing = {
|
|
|
236
237
|
};
|
|
237
238
|
};
|
|
238
239
|
|
|
239
|
-
/**
|
|
240
|
-
* Type that extract the possible return type from a RPC Schema
|
|
241
|
-
* @ignore
|
|
242
|
-
*/
|
|
243
|
-
declare type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = Extract<TRpcSchema[number], {
|
|
244
|
-
Method: TMethod;
|
|
245
|
-
}>;
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Type that extract the possible parameters from a RPC Schema
|
|
249
|
-
* @ignore
|
|
250
|
-
*/
|
|
251
|
-
declare type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema> = {
|
|
252
|
-
[K in keyof TRpcSchema]: Prettify<{
|
|
253
|
-
method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
|
|
254
|
-
} & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
|
|
255
|
-
params?: never;
|
|
256
|
-
} : {
|
|
257
|
-
params: TRpcSchema[K]["Parameters"];
|
|
258
|
-
} : never)>;
|
|
259
|
-
}[number];
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Type that extract the possible return type from a RPC Schema
|
|
263
|
-
* @ignore
|
|
264
|
-
*/
|
|
265
|
-
declare type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"];
|
|
266
|
-
|
|
267
240
|
/**
|
|
268
241
|
* The different types of final actions we can display in the final step
|
|
269
242
|
* @group Modal Display
|
|
@@ -308,6 +281,7 @@ declare type FrakClient = {
|
|
|
308
281
|
debugInfo: {
|
|
309
282
|
formatDebugInfo: (error: Error | unknown | string) => string;
|
|
310
283
|
};
|
|
284
|
+
openPanel?: OpenPanel;
|
|
311
285
|
} & IFrameTransport;
|
|
312
286
|
|
|
313
287
|
/**
|
|
@@ -488,40 +462,51 @@ declare type I18nConfig = Record<Language, LocalizedI18nConfig> | LocalizedI18nC
|
|
|
488
462
|
/**
|
|
489
463
|
* RPC interface that's used for the iframe communication
|
|
490
464
|
*
|
|
491
|
-
* 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
|
|
492
466
|
*
|
|
493
467
|
* @group RPC Schema
|
|
494
468
|
*
|
|
495
469
|
* @remarks
|
|
496
|
-
*
|
|
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
|
|
497
473
|
*
|
|
498
|
-
* ###
|
|
474
|
+
* ### Methods:
|
|
475
|
+
*
|
|
476
|
+
* #### frak_listenToWalletStatus
|
|
499
477
|
* - Params: None
|
|
500
478
|
* - Returns: {@link WalletStatusReturnType}
|
|
479
|
+
* - Response Type: stream (emits updates when wallet status changes)
|
|
501
480
|
*
|
|
502
|
-
*
|
|
503
|
-
* - Params: [{@link ModalRpcStepsInput},
|
|
481
|
+
* #### frak_displayModal
|
|
482
|
+
* - Params: [requests: {@link ModalRpcStepsInput}, metadata?: {@link ModalRpcMetadata}, configMetadata: {@link FrakWalletSdkConfig}["metadata"]]
|
|
504
483
|
* - Returns: {@link ModalRpcStepsResultType}
|
|
484
|
+
* - Response Type: promise (one-shot)
|
|
505
485
|
*
|
|
506
|
-
*
|
|
486
|
+
* #### frak_sendInteraction
|
|
507
487
|
* - Params: [productId: Hex, interaction: {@link PreparedInteraction}, signature?: Hex]
|
|
508
488
|
* - Returns: {@link SendInteractionReturnType}
|
|
489
|
+
* - Response Type: promise (one-shot)
|
|
509
490
|
*
|
|
510
|
-
*
|
|
511
|
-
* - Params [params: {@link OpenSsoParamsType}, name: string, customCss?: string]
|
|
512
|
-
* - Returns:
|
|
491
|
+
* #### frak_sso
|
|
492
|
+
* - Params: [params: {@link OpenSsoParamsType}, name: string, customCss?: string]
|
|
493
|
+
* - Returns: {@link OpenSsoReturnType}
|
|
494
|
+
* - Response Type: promise (one-shot)
|
|
513
495
|
*
|
|
514
|
-
*
|
|
496
|
+
* #### frak_getProductInformation
|
|
515
497
|
* - Params: None
|
|
516
498
|
* - Returns: {@link GetProductInformationReturnType}
|
|
499
|
+
* - Response Type: promise (one-shot)
|
|
517
500
|
*
|
|
518
|
-
*
|
|
519
|
-
* - Params: [{@link DisplayEmbeddedWalletParamsType}]
|
|
501
|
+
* #### frak_displayEmbeddedWallet
|
|
502
|
+
* - Params: [request: {@link DisplayEmbeddedWalletParamsType}, metadata: {@link FrakWalletSdkConfig}["metadata"]]
|
|
520
503
|
* - Returns: {@link DisplayEmbeddedWalletResultType}
|
|
504
|
+
* - Response Type: promise (one-shot)
|
|
521
505
|
*/
|
|
522
506
|
declare type IFrameRpcSchema = [
|
|
523
507
|
/**
|
|
524
508
|
* Method used to listen to the wallet status
|
|
509
|
+
* This is a streaming method that emits updates when wallet status changes
|
|
525
510
|
*/
|
|
526
511
|
{
|
|
527
512
|
Method: "frak_listenToWalletStatus";
|
|
@@ -530,6 +515,7 @@ declare type IFrameRpcSchema = [
|
|
|
530
515
|
},
|
|
531
516
|
/**
|
|
532
517
|
* Method to display a modal with the provided steps
|
|
518
|
+
* This is a one-shot request
|
|
533
519
|
*/
|
|
534
520
|
{
|
|
535
521
|
Method: "frak_displayModal";
|
|
@@ -542,6 +528,7 @@ declare type IFrameRpcSchema = [
|
|
|
542
528
|
},
|
|
543
529
|
/**
|
|
544
530
|
* Method to transmit a user interaction
|
|
531
|
+
* This is a one-shot request
|
|
545
532
|
*/
|
|
546
533
|
{
|
|
547
534
|
Method: "frak_sendInteraction";
|
|
@@ -554,7 +541,7 @@ declare type IFrameRpcSchema = [
|
|
|
554
541
|
},
|
|
555
542
|
/**
|
|
556
543
|
* Method to start a SSO
|
|
557
|
-
*
|
|
544
|
+
* This is a one-shot request
|
|
558
545
|
*/
|
|
559
546
|
{
|
|
560
547
|
Method: "frak_sso";
|
|
@@ -563,13 +550,14 @@ declare type IFrameRpcSchema = [
|
|
|
563
550
|
name: string,
|
|
564
551
|
customCss?: string
|
|
565
552
|
];
|
|
566
|
-
ReturnType:
|
|
553
|
+
ReturnType: OpenSsoReturnType;
|
|
567
554
|
},
|
|
568
555
|
/**
|
|
569
556
|
* Method to get current product information's
|
|
570
557
|
* - Is product minted?
|
|
571
558
|
* - Does it have running campaign?
|
|
572
559
|
* - Estimated reward on actions
|
|
560
|
+
* This is a one-shot request
|
|
573
561
|
*/
|
|
574
562
|
{
|
|
575
563
|
Method: "frak_getProductInformation";
|
|
@@ -578,6 +566,7 @@ declare type IFrameRpcSchema = [
|
|
|
578
566
|
},
|
|
579
567
|
/**
|
|
580
568
|
* Method to show the embedded wallet, with potential customization
|
|
569
|
+
* This is a one-shot request
|
|
581
570
|
*/
|
|
582
571
|
{
|
|
583
572
|
Method: "frak_displayEmbeddedWallet";
|
|
@@ -604,11 +593,11 @@ declare type IFrameTransport = {
|
|
|
604
593
|
/**
|
|
605
594
|
* Function used to perform a single request via the iframe transport
|
|
606
595
|
*/
|
|
607
|
-
request:
|
|
596
|
+
request: RpcClient<IFrameRpcSchema, LifecycleMessage>["request"];
|
|
608
597
|
/**
|
|
609
598
|
* Function used to listen to a request response via the iframe transport
|
|
610
599
|
*/
|
|
611
|
-
listenerRequest:
|
|
600
|
+
listenerRequest: RpcClient<IFrameRpcSchema, LifecycleMessage>["listen"];
|
|
612
601
|
/**
|
|
613
602
|
* Function used to destroy the iframe transport
|
|
614
603
|
*/
|
|
@@ -650,12 +639,6 @@ declare const interactionTypes: {
|
|
|
650
639
|
*/
|
|
651
640
|
declare type Language = "fr" | "en";
|
|
652
641
|
|
|
653
|
-
/**
|
|
654
|
-
* Type used for a listening request
|
|
655
|
-
* @inline
|
|
656
|
-
*/
|
|
657
|
-
declare type ListenerRequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters, callback: (result: _ReturnType) => void) => Promise<void>;
|
|
658
|
-
|
|
659
642
|
/**
|
|
660
643
|
* A localized i18n config
|
|
661
644
|
* @category Config
|
|
@@ -952,9 +935,18 @@ declare type OpenInteractionSessionReturnType = {
|
|
|
952
935
|
* metadata,
|
|
953
936
|
* });
|
|
954
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
|
+
* ```
|
|
955
947
|
* :::
|
|
956
948
|
*/
|
|
957
|
-
export declare function openSso(client: FrakClient, args: OpenSsoParamsType): Promise<
|
|
949
|
+
export declare function openSso(client: FrakClient, args: OpenSsoParamsType): Promise<OpenSsoReturnType>;
|
|
958
950
|
|
|
959
951
|
/**
|
|
960
952
|
* Params to start a SSO
|
|
@@ -970,6 +962,11 @@ declare type OpenSsoParamsType = {
|
|
|
970
962
|
* @defaultValue true
|
|
971
963
|
*/
|
|
972
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;
|
|
973
970
|
/**
|
|
974
971
|
* Language of the SSO page (optional)
|
|
975
972
|
* It will default to the current user language (or "en" if unsupported language)
|
|
@@ -981,6 +978,17 @@ declare type OpenSsoParamsType = {
|
|
|
981
978
|
metadata: SsoMetadata;
|
|
982
979
|
};
|
|
983
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
|
+
|
|
984
992
|
/**
|
|
985
993
|
* Represent a prepared user interaction, ready to be sent on-chain via the wallet
|
|
986
994
|
*/
|
|
@@ -1081,12 +1089,6 @@ export declare function referralInteraction(client: FrakClient, { productId, mod
|
|
|
1081
1089
|
*/
|
|
1082
1090
|
declare type ReferralState = "idle" | "processing" | "success" | "no-wallet" | "no-session" | "error" | "no-referrer" | "self-referral";
|
|
1083
1091
|
|
|
1084
|
-
/**
|
|
1085
|
-
* Type used for a one shot request function
|
|
1086
|
-
* @inline
|
|
1087
|
-
*/
|
|
1088
|
-
declare type RequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters) => Promise<_ReturnType>;
|
|
1089
|
-
|
|
1090
1092
|
/**
|
|
1091
1093
|
* Function used to send an interaction
|
|
1092
1094
|
* @param client - The current Frak Client
|
|
@@ -1379,7 +1381,7 @@ declare type WalletStatusReturnType = WalletConnected | WalletNotConnected;
|
|
|
1379
1381
|
* Function used to watch the current frak wallet status
|
|
1380
1382
|
* @param client - The current Frak Client
|
|
1381
1383
|
* @param callback - The callback that will receive any wallet status change
|
|
1382
|
-
* @returns A
|
|
1384
|
+
* @returns A promise resolving with the initial wallet status
|
|
1383
1385
|
*
|
|
1384
1386
|
* @description This function will return the current wallet status, and will listen to any change in the wallet status.
|
|
1385
1387
|
*
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Address } from 'viem';
|
|
2
2
|
import { Hex } from 'viem';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
3
|
+
import type { LifecycleMessage } from '@frak-labs/rpc';
|
|
4
|
+
import type { OpenPanel } from '@openpanel/web';
|
|
5
|
+
import type { RpcClient } from '@frak-labs/rpc';
|
|
5
6
|
import type { SiweMessage } from 'viem/siwe';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -236,34 +237,6 @@ declare type EmbeddedViewActionSharing = {
|
|
|
236
237
|
};
|
|
237
238
|
};
|
|
238
239
|
|
|
239
|
-
/**
|
|
240
|
-
* Type that extract the possible return type from a RPC Schema
|
|
241
|
-
* @ignore
|
|
242
|
-
*/
|
|
243
|
-
declare type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = Extract<TRpcSchema[number], {
|
|
244
|
-
Method: TMethod;
|
|
245
|
-
}>;
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Type that extract the possible parameters from a RPC Schema
|
|
249
|
-
* @ignore
|
|
250
|
-
*/
|
|
251
|
-
declare type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema> = {
|
|
252
|
-
[K in keyof TRpcSchema]: Prettify<{
|
|
253
|
-
method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
|
|
254
|
-
} & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
|
|
255
|
-
params?: never;
|
|
256
|
-
} : {
|
|
257
|
-
params: TRpcSchema[K]["Parameters"];
|
|
258
|
-
} : never)>;
|
|
259
|
-
}[number];
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Type that extract the possible return type from a RPC Schema
|
|
263
|
-
* @ignore
|
|
264
|
-
*/
|
|
265
|
-
declare type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"];
|
|
266
|
-
|
|
267
240
|
/**
|
|
268
241
|
* The different types of final actions we can display in the final step
|
|
269
242
|
* @group Modal Display
|
|
@@ -308,6 +281,7 @@ declare type FrakClient = {
|
|
|
308
281
|
debugInfo: {
|
|
309
282
|
formatDebugInfo: (error: Error | unknown | string) => string;
|
|
310
283
|
};
|
|
284
|
+
openPanel?: OpenPanel;
|
|
311
285
|
} & IFrameTransport;
|
|
312
286
|
|
|
313
287
|
/**
|
|
@@ -488,40 +462,51 @@ declare type I18nConfig = Record<Language, LocalizedI18nConfig> | LocalizedI18nC
|
|
|
488
462
|
/**
|
|
489
463
|
* RPC interface that's used for the iframe communication
|
|
490
464
|
*
|
|
491
|
-
* 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
|
|
492
466
|
*
|
|
493
467
|
* @group RPC Schema
|
|
494
468
|
*
|
|
495
469
|
* @remarks
|
|
496
|
-
*
|
|
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
|
|
497
473
|
*
|
|
498
|
-
* ###
|
|
474
|
+
* ### Methods:
|
|
475
|
+
*
|
|
476
|
+
* #### frak_listenToWalletStatus
|
|
499
477
|
* - Params: None
|
|
500
478
|
* - Returns: {@link WalletStatusReturnType}
|
|
479
|
+
* - Response Type: stream (emits updates when wallet status changes)
|
|
501
480
|
*
|
|
502
|
-
*
|
|
503
|
-
* - Params: [{@link ModalRpcStepsInput},
|
|
481
|
+
* #### frak_displayModal
|
|
482
|
+
* - Params: [requests: {@link ModalRpcStepsInput}, metadata?: {@link ModalRpcMetadata}, configMetadata: {@link FrakWalletSdkConfig}["metadata"]]
|
|
504
483
|
* - Returns: {@link ModalRpcStepsResultType}
|
|
484
|
+
* - Response Type: promise (one-shot)
|
|
505
485
|
*
|
|
506
|
-
*
|
|
486
|
+
* #### frak_sendInteraction
|
|
507
487
|
* - Params: [productId: Hex, interaction: {@link PreparedInteraction}, signature?: Hex]
|
|
508
488
|
* - Returns: {@link SendInteractionReturnType}
|
|
489
|
+
* - Response Type: promise (one-shot)
|
|
509
490
|
*
|
|
510
|
-
*
|
|
511
|
-
* - Params [params: {@link OpenSsoParamsType}, name: string, customCss?: string]
|
|
512
|
-
* - Returns:
|
|
491
|
+
* #### frak_sso
|
|
492
|
+
* - Params: [params: {@link OpenSsoParamsType}, name: string, customCss?: string]
|
|
493
|
+
* - Returns: {@link OpenSsoReturnType}
|
|
494
|
+
* - Response Type: promise (one-shot)
|
|
513
495
|
*
|
|
514
|
-
*
|
|
496
|
+
* #### frak_getProductInformation
|
|
515
497
|
* - Params: None
|
|
516
498
|
* - Returns: {@link GetProductInformationReturnType}
|
|
499
|
+
* - Response Type: promise (one-shot)
|
|
517
500
|
*
|
|
518
|
-
*
|
|
519
|
-
* - Params: [{@link DisplayEmbeddedWalletParamsType}]
|
|
501
|
+
* #### frak_displayEmbeddedWallet
|
|
502
|
+
* - Params: [request: {@link DisplayEmbeddedWalletParamsType}, metadata: {@link FrakWalletSdkConfig}["metadata"]]
|
|
520
503
|
* - Returns: {@link DisplayEmbeddedWalletResultType}
|
|
504
|
+
* - Response Type: promise (one-shot)
|
|
521
505
|
*/
|
|
522
506
|
declare type IFrameRpcSchema = [
|
|
523
507
|
/**
|
|
524
508
|
* Method used to listen to the wallet status
|
|
509
|
+
* This is a streaming method that emits updates when wallet status changes
|
|
525
510
|
*/
|
|
526
511
|
{
|
|
527
512
|
Method: "frak_listenToWalletStatus";
|
|
@@ -530,6 +515,7 @@ declare type IFrameRpcSchema = [
|
|
|
530
515
|
},
|
|
531
516
|
/**
|
|
532
517
|
* Method to display a modal with the provided steps
|
|
518
|
+
* This is a one-shot request
|
|
533
519
|
*/
|
|
534
520
|
{
|
|
535
521
|
Method: "frak_displayModal";
|
|
@@ -542,6 +528,7 @@ declare type IFrameRpcSchema = [
|
|
|
542
528
|
},
|
|
543
529
|
/**
|
|
544
530
|
* Method to transmit a user interaction
|
|
531
|
+
* This is a one-shot request
|
|
545
532
|
*/
|
|
546
533
|
{
|
|
547
534
|
Method: "frak_sendInteraction";
|
|
@@ -554,7 +541,7 @@ declare type IFrameRpcSchema = [
|
|
|
554
541
|
},
|
|
555
542
|
/**
|
|
556
543
|
* Method to start a SSO
|
|
557
|
-
*
|
|
544
|
+
* This is a one-shot request
|
|
558
545
|
*/
|
|
559
546
|
{
|
|
560
547
|
Method: "frak_sso";
|
|
@@ -563,13 +550,14 @@ declare type IFrameRpcSchema = [
|
|
|
563
550
|
name: string,
|
|
564
551
|
customCss?: string
|
|
565
552
|
];
|
|
566
|
-
ReturnType:
|
|
553
|
+
ReturnType: OpenSsoReturnType;
|
|
567
554
|
},
|
|
568
555
|
/**
|
|
569
556
|
* Method to get current product information's
|
|
570
557
|
* - Is product minted?
|
|
571
558
|
* - Does it have running campaign?
|
|
572
559
|
* - Estimated reward on actions
|
|
560
|
+
* This is a one-shot request
|
|
573
561
|
*/
|
|
574
562
|
{
|
|
575
563
|
Method: "frak_getProductInformation";
|
|
@@ -578,6 +566,7 @@ declare type IFrameRpcSchema = [
|
|
|
578
566
|
},
|
|
579
567
|
/**
|
|
580
568
|
* Method to show the embedded wallet, with potential customization
|
|
569
|
+
* This is a one-shot request
|
|
581
570
|
*/
|
|
582
571
|
{
|
|
583
572
|
Method: "frak_displayEmbeddedWallet";
|
|
@@ -604,11 +593,11 @@ declare type IFrameTransport = {
|
|
|
604
593
|
/**
|
|
605
594
|
* Function used to perform a single request via the iframe transport
|
|
606
595
|
*/
|
|
607
|
-
request:
|
|
596
|
+
request: RpcClient<IFrameRpcSchema, LifecycleMessage>["request"];
|
|
608
597
|
/**
|
|
609
598
|
* Function used to listen to a request response via the iframe transport
|
|
610
599
|
*/
|
|
611
|
-
listenerRequest:
|
|
600
|
+
listenerRequest: RpcClient<IFrameRpcSchema, LifecycleMessage>["listen"];
|
|
612
601
|
/**
|
|
613
602
|
* Function used to destroy the iframe transport
|
|
614
603
|
*/
|
|
@@ -650,12 +639,6 @@ declare const interactionTypes: {
|
|
|
650
639
|
*/
|
|
651
640
|
declare type Language = "fr" | "en";
|
|
652
641
|
|
|
653
|
-
/**
|
|
654
|
-
* Type used for a listening request
|
|
655
|
-
* @inline
|
|
656
|
-
*/
|
|
657
|
-
declare type ListenerRequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters, callback: (result: _ReturnType) => void) => Promise<void>;
|
|
658
|
-
|
|
659
642
|
/**
|
|
660
643
|
* A localized i18n config
|
|
661
644
|
* @category Config
|
|
@@ -952,9 +935,18 @@ declare type OpenInteractionSessionReturnType = {
|
|
|
952
935
|
* metadata,
|
|
953
936
|
* });
|
|
954
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
|
+
* ```
|
|
955
947
|
* :::
|
|
956
948
|
*/
|
|
957
|
-
export declare function openSso(client: FrakClient, args: OpenSsoParamsType): Promise<
|
|
949
|
+
export declare function openSso(client: FrakClient, args: OpenSsoParamsType): Promise<OpenSsoReturnType>;
|
|
958
950
|
|
|
959
951
|
/**
|
|
960
952
|
* Params to start a SSO
|
|
@@ -970,6 +962,11 @@ declare type OpenSsoParamsType = {
|
|
|
970
962
|
* @defaultValue true
|
|
971
963
|
*/
|
|
972
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;
|
|
973
970
|
/**
|
|
974
971
|
* Language of the SSO page (optional)
|
|
975
972
|
* It will default to the current user language (or "en" if unsupported language)
|
|
@@ -981,6 +978,17 @@ declare type OpenSsoParamsType = {
|
|
|
981
978
|
metadata: SsoMetadata;
|
|
982
979
|
};
|
|
983
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
|
+
|
|
984
992
|
/**
|
|
985
993
|
* Represent a prepared user interaction, ready to be sent on-chain via the wallet
|
|
986
994
|
*/
|
|
@@ -1081,12 +1089,6 @@ export declare function referralInteraction(client: FrakClient, { productId, mod
|
|
|
1081
1089
|
*/
|
|
1082
1090
|
declare type ReferralState = "idle" | "processing" | "success" | "no-wallet" | "no-session" | "error" | "no-referrer" | "self-referral";
|
|
1083
1091
|
|
|
1084
|
-
/**
|
|
1085
|
-
* Type used for a one shot request function
|
|
1086
|
-
* @inline
|
|
1087
|
-
*/
|
|
1088
|
-
declare type RequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters) => Promise<_ReturnType>;
|
|
1089
|
-
|
|
1090
1092
|
/**
|
|
1091
1093
|
* Function used to send an interaction
|
|
1092
1094
|
* @param client - The current Frak Client
|
|
@@ -1379,7 +1381,7 @@ declare type WalletStatusReturnType = WalletConnected | WalletNotConnected;
|
|
|
1379
1381
|
* Function used to watch the current frak wallet status
|
|
1380
1382
|
* @param client - The current Frak Client
|
|
1381
1383
|
* @param callback - The callback that will receive any wallet status change
|
|
1382
|
-
* @returns A
|
|
1384
|
+
* @returns A promise resolving with the initial wallet status
|
|
1383
1385
|
*
|
|
1384
1386
|
* @description This function will return the current wallet status, and will listen to any change in the wallet status.
|
|
1385
1387
|
*
|
package/dist/actions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{Deferred as e,FrakRpcError as t,RpcErrorCodes as n}from"@frak-labs/rpc";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};
|