@frak-labs/core-sdk 0.0.19 → 0.1.0-beta.6e0d8026
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 +154 -73
- package/dist/actions.d.ts +154 -73
- package/dist/actions.js +1 -1
- package/dist/bundle.cjs +2 -2
- package/dist/bundle.d.cts +257 -192
- package/dist/bundle.d.ts +257 -192
- package/dist/bundle.js +2 -2
- package/dist/index.cjs +11 -11
- package/dist/index.d.cts +199 -185
- package/dist/index.d.ts +199 -185
- package/dist/index.js +2 -2
- package/package.json +5 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Deferred as e,FrakRpcError as t,RpcErrorCodes as n,compressJson as r,createRpcClient as a,decompressJson as o}from"@frak-labs/frame-connector";import{createClientCompressionMiddleware as i}from"@frak-labs/frame-connector/middleware";import{OpenPanel as s}from"@openpanel/web";import{bytesToHex as c,hexToBytes as l}from"viem";let d="nexus-wallet-backup";class u{config;iframe;isSetupDone=!1;lastResponse=null;lastRequest=null;constructor(e,t){this.config=e,this.iframe=t,this.lastRequest=null,this.lastResponse=null}setLastResponse(e,t){this.lastResponse={message:e,response:t,timestamp:Date.now()}}setLastRequest(e){this.lastRequest={event:e,timestamp:Date.now()}}updateSetupStatus(e){this.isSetupDone=e}base64Encode(e){try{return btoa(JSON.stringify(e))}catch(e){return console.warn("Failed to encode debug data",e),btoa("Failed to encode data")}}getIframeStatus(){return this.iframe?{loading:this.iframe.hasAttribute("loading"),url:this.iframe.src,readyState:this.iframe.contentDocument?.readyState?+("complete"===this.iframe.contentDocument.readyState):-1,contentWindow:!!this.iframe.contentWindow,isConnected:this.iframe.isConnected}:null}getNavigatorInfo(){return navigator?{userAgent:navigator.userAgent,language:navigator.language,onLine:navigator.onLine,screenWidth:window.screen.width,screenHeight:window.screen.height,pixelRatio:window.devicePixelRatio}:null}gatherDebugInfo(e){let n=this.getIframeStatus(),r=this.getNavigatorInfo(),a="Unknown";return e instanceof t?a=`FrakRpcError: ${e.code} '${e.message}'`:e instanceof Error?a=e.message:"string"==typeof e&&(a=e),{timestamp:new Date().toISOString(),encodedUrl:btoa(window.location.href),encodedConfig:this.config?this.base64Encode(this.config):"no-config",navigatorInfo:r?this.base64Encode(r):"no-navigator",iframeStatus:n?this.base64Encode(n):"not-iframe",lastRequest:this.lastRequest?this.base64Encode(this.lastRequest):"No Frak request logged",lastResponse:this.lastResponse?this.base64Encode(this.lastResponse):"No Frak response logged",clientStatus:this.isSetupDone?"setup":"not-setup",error:a}}static empty(){return new u}formatDebugInfo(e){let t=this.gatherDebugInfo(e);return`
|
|
2
2
|
Debug Information:
|
|
3
3
|
-----------------
|
|
4
4
|
Timestamp: ${t.timestamp}
|
|
@@ -10,4 +10,4 @@ import{OpenPanel as e}from"@openpanel/web";import{CborDecoder as t,CborEncoder a
|
|
|
10
10
|
Last Response: ${t.lastResponse}
|
|
11
11
|
Client Status: ${t.clientStatus}
|
|
12
12
|
Error: ${t.error}
|
|
13
|
-
`.trim()}}let
|
|
13
|
+
`.trim()}}let f={id:"frak-wallet",name:"frak-wallet",title:"Frak Wallet",allow:"publickey-credentials-get *; clipboard-write; web-share *",style:{width:"0",height:"0",border:"0",position:"absolute",zIndex:2000001,top:"-1000px",left:"-1000px",colorScheme:"auto"}};function p({walletBaseUrl:e,config:t}){let n=document.querySelector("#frak-wallet");n&&n.remove();let r=document.createElement("iframe");return r.id=f.id,r.name=f.name,r.allow=f.allow,r.style.zIndex=f.style.zIndex.toString(),m({iframe:r,isVisible:!1}),document.body.appendChild(r),new Promise(n=>{r?.addEventListener("load",()=>n(r)),r.src=`${t?.walletUrl??e??"https://wallet.frak.id"}/listener`})}function m({iframe:e,isVisible:t}){if(!t){e.style.width="0",e.style.height="0",e.style.border="0",e.style.position="fixed",e.style.top="-1000px",e.style.left="-1000px";return}e.style.position="fixed",e.style.top="0",e.style.left="0",e.style.width="100%",e.style.height="100%",e.style.pointerEvents="auto"}function g(e="/listener"){if(!window.opener)return null;let t=t=>{try{return t.location.origin===window.location.origin&&t.location.pathname===e}catch{return!1}};if(t(window.opener))return window.opener;try{let e=window.opener.frames;for(let n=0;n<e.length;n++)if(t(e[n]))return e[n];return null}catch(t){return console.error(`[findIframeInOpener] Error finding iframe with pathname ${e}:`,t),null}}function h({config:r,iframe:o}){let c,l=r?.walletUrl??"https://wallet.frak.id",f=function({iframe:t}){let n=new e;return{handleEvent:async e=>{if(!("iframeLifecycle"in e))return;let{iframeLifecycle:r,data:a}=e;switch(r){case"connected":n.resolve(!0);break;case"do-backup":a.backup?localStorage.setItem(d,a.backup):localStorage.removeItem(d);break;case"remove-backup":localStorage.removeItem(d);break;case"show":case"hide":m({iframe:t,isVisible:"show"===r});break;case"handshake":t.contentWindow?.postMessage({clientLifecycle:"handshake-response",data:{token:a.token,currentUrl:window.location.href}},"*");break;case"redirect":{let e=new URL(a.baseRedirectUrl);e.searchParams.has("u")?(e.searchParams.delete("u"),e.searchParams.append("u",window.location.href),window.location.href=e.toString()):window.location.href=a.baseRedirectUrl}}},isConnected:n.promise}}({iframe:o}),p=new u(r,o);if(!o.contentWindow)throw new t(n.configError,"The iframe does not have a content window");let g=a({emittingTransport:o.contentWindow,listeningTransport:window,targetOrigin:l,middleware:[{async onRequest(e,r){if(!await f.isConnected)throw new t(n.clientNotConnected,"The iframe provider isn't connected yet");return r}},i(),{onRequest:(e,t)=>(p.setLastRequest(e),t),onResponse:(e,t)=>(p.setLastResponse(e,t),t)}],lifecycleHandlers:{iframeLifecycle:async(e,t)=>{await f.handleEvent(e)}}}),h=function(e,t){let n,r,a=()=>e.sendLifecycle({clientLifecycle:"heartbeat"});function o(){n&&clearInterval(n),r&&clearTimeout(r)}return async function(){a(),n=setInterval(a,1e3),r=setTimeout(()=>{o(),console.log("Heartbeat timeout: connection failed")},3e4),await t.isConnected,o()}(),o}(g,f),y=async()=>{h(),g.cleanup(),o.remove()};console.log("[Frak SDK] Initializing OpenPanel"),(c=new s({apiUrl:"https://op-api.gcp.frak.id",clientId:"6eacc8d7-49ac-4936-95e9-81ef29449570",trackScreenViews:!0,trackOutgoingLinks:!0,trackAttributes:!1,filter:({type:e,payload:t})=>!("track"===e&&t?.properties)||("sdkVersion"in t.properties||(t.properties={...t.properties,sdkVersion:"0.1.0"}),!0)})).setGlobalProperties({sdkVersion:"0.1.0"}),c.init();let b=w({config:r,rpcClient:g,lifecycleManager:f}).then(()=>p.updateSetupStatus(!0));return{config:r,debugInfo:p,waitForConnection:f.isConnected,waitForSetup:b,request:g.request,listenerRequest:g.listen,destroy:y,openPanel:c}}async function w({config:e,rpcClient:t,lifecycleManager:n}){async function r(){let n=e.customizations?.css;n&&t.sendLifecycle({clientLifecycle:"modal-css",data:{cssLink:n}})}async function a(){let n=e.customizations?.i18n;n&&t.sendLifecycle({clientLifecycle:"modal-i18n",data:{i18n:n}})}async function o(){if("undefined"==typeof window)return;let e=window.localStorage.getItem(d);e&&t.sendLifecycle({clientLifecycle:"restore-backup",data:{backup:e}})}await n.isConnected,function(e,t){if("undefined"==typeof window)return;let n=new URL(window.location.href),r=n.searchParams.get("sso");r&&(t.then(()=>{e.sendLifecycle({clientLifecycle:"sso-redirect-complete",data:{compressed:r}}),console.log("[SSO URL Listener] Forwarded compressed SSO data to iframe")}).catch(e=>{console.error("[SSO URL Listener] Failed to forward SSO data:",e)}),n.searchParams.delete("sso"),window.history.replaceState({},"",n.toString()),console.log("[SSO URL Listener] SSO parameter detected and URL cleaned"))}(t,n.isConnected),await Promise.allSettled([r(),a(),o()])}let y={eur:"fr-FR",usd:"en-US",gbp:"en-GB"};function b(e){return e&&e in y?e:"eur"}async function S({config:e}){let t=function(e){let t=b(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}(e),n=await p({config:t});if(!n)return void console.error("Failed to create iframe");let r=h({config:t,iframe:n});return(await r.waitForSetup,await r.waitForConnection)?r:void console.error("Failed to connect to client")}function k(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join("")).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function L(e){let t=e.length%4;return Uint8Array.from(atob(e.replace(/-/g,"+").replace(/_/g,"/").padEnd(e.length+(0===t?0:4-t),"=")),e=>e.charCodeAt(0))}function R(e){return k(r(e))}function v(e){return o(L(e))}let I="fCtx";function x(e){if(e?.r)try{let t=l(e.r);return k(t)}catch(t){console.error("Error compressing Frak context",{e:t,context:e})}}function U(e){if(e&&0!==e.length)try{let t=L(e);return{r:c(t,{size:20})}}catch(t){console.error("Error decompressing Frak context",{e:t,context:e})}}function F({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(I);return t?U(t):null}function C({url:e,context:t}){if(!e)return null;let n=F({url:e}),r=n?{...n,...t}:t;if(!r.r)return null;let a=x(r);if(!a)return null;let o=new URL(e);return o.searchParams.set(I,a),o.toString()}function E(e){let t=new URL(e);return t.searchParams.delete(I),t.toString()}let P={compress:x,decompress:U,parse:F,update:C,remove:E,replaceUrl:function({url:e,context:t}){let n;if(!window.location?.href||"undefined"==typeof window)return void console.error("No window found, can't update context");let r=e??window.location.href;(n=null!==t?C({url:r,context:t}):E(r))&&window.history.replaceState(null,"",n.toString())}};function q(e){return e?y[e]??y.eur:y.eur}function D(e){return e?`${e}Amount`:"eurAmount"}function $(e,t){let n=q(t),r=b(t);return e.toLocaleString(n,{style:"currency",currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function O(e,t,n={}){if(!e)return void console.debug("[Frak] No client provided, skipping event tracking");try{e.openPanel?.track(t,n)}catch(e){console.debug("[Frak] Failed to track event:",t,e)}}function A(e,t,n,r,a){var o;let i=R({r:(o={redirectUrl:t.redirectUrl,directExit:t.directExit,lang:t.lang,productId:n,metadata:{name:r,css:a,logoUrl:t.metadata?.logoUrl,homepageLink:t.metadata?.homepageLink}}).redirectUrl,d:o.directExit,l:o.lang,p:o.productId,m:{n:o.metadata?.name,css:o.metadata?.css,l:o.metadata?.logoUrl,h:o.metadata?.homepageLink}}),s=new URL(e);return s.pathname="/sso",s.searchParams.set("p",i),s.toString()}let T={dapp:1,press:2,webshop:3,retail:4,referral:30,purchase:31},N=Object.entries(T).reduce((e,[t,n])=>(e[t]=BigInt(1)<<BigInt(n),e),{}),V={press:{openArticle:"0xc0a24ffb",readArticle:"0xd5bd0fbe"},dapp:{proofVerifiableStorageUpdate:"0x2ab2aeef",callableVerifiableStorageUpdate:"0xa07da986"},webshop:{open:"0xb311798f"},referral:{referred:"0x010cc3b9",createLink:"0xb2c0f17c"},purchase:{started:"0xd87e90c3",completed:"0x8403aeb4",unsafeCompleted:"0x4d5b14e0"},retail:{customerMeeting:"0x74489004"}},z="menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800",W="frak-sso";export{u as DebugInfoGatherer,P as FrakContextManager,L as base64urlDecode,k as base64urlEncode,f as baseIframeProps,R as compressJsonToB64,h as createIFrameFrakClient,p as createIframe,v as decompressJsonFromB64,g as findIframeInOpener,$ as formatAmount,A as generateSsoUrl,D as getCurrencyAmountKey,b as getSupportedCurrency,q as getSupportedLocale,V as interactionTypes,y as locales,T as productTypes,N as productTypesMask,S as setupClient,z as ssoPopupFeatures,W as ssoPopupName,O as trackEvent};
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "https://twitter.com/QNivelais"
|
|
12
12
|
}
|
|
13
13
|
],
|
|
14
|
-
"version": "0.0.
|
|
14
|
+
"version": "0.1.0-beta.6e0d8026",
|
|
15
15
|
"description": "Core SDK of the Frak wallet, low level library to interact directly with the frak ecosystem.",
|
|
16
16
|
"repository": {
|
|
17
17
|
"url": "https://github.com/frak-id/wallet",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"browser": "./cdn/bundle.js",
|
|
40
40
|
"exports": {
|
|
41
41
|
".": {
|
|
42
|
+
"development": "./src/index.ts",
|
|
42
43
|
"import": {
|
|
43
44
|
"types": "./dist/index.d.ts",
|
|
44
45
|
"default": "./dist/index.js"
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
}
|
|
50
51
|
},
|
|
51
52
|
"./actions": {
|
|
53
|
+
"development": "./src/actions/index.ts",
|
|
52
54
|
"import": {
|
|
53
55
|
"types": "./dist/actions.d.ts",
|
|
54
56
|
"default": "./dist/actions.js"
|
|
@@ -59,6 +61,7 @@
|
|
|
59
61
|
}
|
|
60
62
|
},
|
|
61
63
|
"./interactions": {
|
|
64
|
+
"development": "./src/interactions/index.ts",
|
|
62
65
|
"import": {
|
|
63
66
|
"types": "./dist/interactions.d.ts",
|
|
64
67
|
"default": "./dist/interactions.js"
|
|
@@ -95,6 +98,7 @@
|
|
|
95
98
|
"viem": "^2.23.14"
|
|
96
99
|
},
|
|
97
100
|
"dependencies": {
|
|
101
|
+
"@frak-labs/frame-connector": "0.1.0",
|
|
98
102
|
"@jsonjoy.com/json-pack": "^1.2.0",
|
|
99
103
|
"@openpanel/web": "^1.0.1"
|
|
100
104
|
},
|