@frak-labs/core-sdk 1.1.1 → 1.1.3-beta.20a3d2fa
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 +1 -1
- package/dist/actions-BZhtIRpB.cjs +1 -0
- package/dist/actions-D5Lt3pG1.js +1 -0
- package/dist/actions.cjs +1 -1
- package/dist/actions.d.cts +3 -3
- package/dist/actions.d.ts +3 -3
- package/dist/actions.js +1 -1
- package/dist/bundle.cjs +1 -1
- package/dist/bundle.d.cts +4 -4
- package/dist/bundle.d.ts +4 -4
- package/dist/bundle.js +1 -1
- package/dist/{frakContext-_b-_uwgd.cjs → frakContext-Cfp7sSid.cjs} +1 -1
- package/dist/{frakContext-CTKalP6g.js → frakContext-UEOk9Bk4.js} +1 -1
- package/dist/{index-5JycXTk0.d.cts → index-B5_aKV0q.d.ts} +5 -5
- package/dist/{index-RNzVfwrP.d.ts → index-C135c5Ul.d.cts} +5 -5
- package/dist/{index-C2xfJCUg.d.cts → index-DR4n-QOe.d.cts} +1 -1
- package/dist/{index-BD1gOEIo.d.ts → index-lcImYQyL.d.ts} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/{openSso-CtDyvXLM.d.ts → openSso-BErs7_Bg.d.cts} +1 -2
- package/dist/{openSso-DIBN_iiz.d.cts → openSso-DRLH4D9a.d.ts} +1 -2
- package/dist/src-CB7gkP3D.js +1 -0
- package/dist/src-CxIEmNS7.cjs +1 -0
- package/package.json +4 -2
- package/src/actions/referral/processReferral.test.ts +4 -4
- package/src/actions/referral/processReferral.ts +4 -4
- package/src/clients/createIFrameFrakClient.ts +7 -7
- package/src/context/frakContext.test.ts +8 -34
- package/src/context/frakContext.ts +6 -14
- package/src/types/resolvedConfig.ts +0 -1
- package/src/utils/analytics/events/lifecycle.ts +1 -1
- package/src/utils/analytics/events/referral.ts +3 -3
- package/src/utils/iframe/iframeHelper.test.ts +39 -0
- package/src/utils/iframe/iframeHelper.ts +31 -2
- package/dist/actions-BVbAHcBk.cjs +0 -1
- package/dist/actions-dH5NFCj1.js +0 -1
- package/dist/src-BupmzjlU.js +0 -1
- package/dist/src-VC21uAq0.cjs +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { $ as SdkResolvedConfig, A as ModalRpcStepsResultType, B as OpenSsoReturnType, C as LoggedInEmbeddedView, D as DisplayModalParamsType, E as SharingPageProduct, F as SiweAuthenticateModalStepType, G as FinalModalStepType, H as PrepareSsoReturnType, I as SiweAuthenticateReturnType, J as IFrameLifecycleEvent, K as ModalStepMetadata, L as SiweAuthenticationParams, M as SendTransactionModalStepType, N as SendTransactionReturnType, O as ModalRpcMetadata, P as SendTransactionTxType, Q as ResolvedSdkConfig, R as LoginModalStepType, S as EmbeddedViewActionSharing, T as DisplaySharingPageResultType, U as SsoMetadata, V as PrepareSsoParamsType, W as FinalActionType, X as MerchantConfigResponse, Y as ClientLifecycleEvent, Z as ResolvedPlacement, _ as SendInteractionParamsType, a as FrakContextV1, at as LocalizedI18nConfig, b as LoggedOutEmbeddedView, c as FrakLifecycleEvent, ct as TrackArrivalParams, d as WalletStatusReturnType, et as Currency, f as UserReferralStatusType, g as TokenAmountType, h as RewardTier, i as FrakContext, it as ListenerPreloadOption, j as ModalStepTypes, k as ModalRpcStepsInput, l as IFrameTransport, lt as TrackArrivalResult, m as GetMerchantInformationReturnType, n as ssoPopupFeatures, nt as I18nConfig, o as FrakContextV2, ot as AttributionDefaults, p as EstimatedReward, q as InteractionTypeKey, r as ssoPopupName, rt as Language, s as FrakClient, st as AttributionParams, tt as FrakWalletSdkConfig, u as IFrameRpcSchema, ut as UtmParams, v as DisplayEmbeddedWalletParamsType, w as DisplaySharingPageParamsType, x as EmbeddedViewActionReferred, y as DisplayEmbeddedWalletResultType, z as OpenSsoParamsType } from "./openSso-
|
|
2
|
-
import { A as getClientId, C as SdkEventMap, D as FrakContextManager, E as mergeAttribution, F as HashProtectedData, I as KeyProvider, M as setupClient, N as createIFrameFrakClient, O as DEEP_LINK_SCHEME, P as CompressedData, S as trackEvent, T as MergeAttributionInput, _ as isInAppBrowser, a as baseIframeProps, b as DeepLinkFallbackOptions, c as getCurrencyAmountKey, d as compressJsonToB64, f as base64urlDecode, g as isIOS, h as withCache, i as generateSsoUrl, j as getBackendUrl, k as sdkConfigStore, l as formatAmount, m as clearAllCache, n as CompressedSsoData, o as findIframeInOpener, p as base64urlEncode, r as FullSsoParams, s as getSupportedCurrency, t as AppSpecificSsoMetadata, u as decompressJsonFromB64, v as isMobile, w as SdkHandshakeFailureReason, x as triggerDeepLinkWithFallback, y as redirectToExternalBrowser } from "./index-
|
|
3
|
-
export { AppSpecificSsoMetadata, AttributionDefaults, AttributionParams, ClientLifecycleEvent, CompressedData, CompressedSsoData, Currency, DEEP_LINK_SCHEME, DeepLinkFallbackOptions, DisplayEmbeddedWalletParamsType, DisplayEmbeddedWalletResultType, DisplayModalParamsType, DisplaySharingPageParamsType, DisplaySharingPageResultType, EmbeddedViewActionReferred, EmbeddedViewActionSharing, EstimatedReward, FinalActionType, FinalModalStepType, FrakClient, FrakContext, FrakContextManager, FrakContextV1, FrakContextV2, FrakLifecycleEvent, FrakWalletSdkConfig, FullSsoParams, GetMerchantInformationReturnType, HashProtectedData, I18nConfig, IFrameLifecycleEvent, IFrameRpcSchema, IFrameTransport, InteractionTypeKey, KeyProvider, Language, ListenerPreloadOption, LocalizedI18nConfig, LoggedInEmbeddedView, LoggedOutEmbeddedView, LoginModalStepType, MerchantConfigResponse, MergeAttributionInput, ModalRpcMetadata, ModalRpcStepsInput, ModalRpcStepsResultType, ModalStepMetadata, ModalStepTypes, OpenSsoParamsType, OpenSsoReturnType, PrepareSsoParamsType, PrepareSsoReturnType, ResolvedPlacement, ResolvedSdkConfig, RewardTier, SdkEventMap, SdkHandshakeFailureReason, SdkResolvedConfig, SendInteractionParamsType, SendTransactionModalStepType, SendTransactionReturnType, SendTransactionTxType, SharingPageProduct, SiweAuthenticateModalStepType, SiweAuthenticateReturnType, SiweAuthenticationParams, SsoMetadata, TokenAmountType, TrackArrivalParams, TrackArrivalResult, UserReferralStatusType, UtmParams, WalletStatusReturnType, base64urlDecode, base64urlEncode, baseIframeProps, clearAllCache, compressJsonToB64, createIFrameFrakClient, decompressJsonFromB64, findIframeInOpener, formatAmount, generateSsoUrl, getBackendUrl, getClientId, getCurrencyAmountKey, getSupportedCurrency, isIOS, isInAppBrowser, isMobile, mergeAttribution, redirectToExternalBrowser, sdkConfigStore, setupClient, ssoPopupFeatures, ssoPopupName, trackEvent, triggerDeepLinkWithFallback, withCache };
|
|
1
|
+
import { $ as SdkResolvedConfig, A as ModalRpcStepsResultType, B as OpenSsoReturnType, C as LoggedInEmbeddedView, D as DisplayModalParamsType, E as SharingPageProduct, F as SiweAuthenticateModalStepType, G as FinalModalStepType, H as PrepareSsoReturnType, I as SiweAuthenticateReturnType, J as IFrameLifecycleEvent, K as ModalStepMetadata, L as SiweAuthenticationParams, M as SendTransactionModalStepType, N as SendTransactionReturnType, O as ModalRpcMetadata, P as SendTransactionTxType, Q as ResolvedSdkConfig, R as LoginModalStepType, S as EmbeddedViewActionSharing, T as DisplaySharingPageResultType, U as SsoMetadata, V as PrepareSsoParamsType, W as FinalActionType, X as MerchantConfigResponse, Y as ClientLifecycleEvent, Z as ResolvedPlacement, _ as SendInteractionParamsType, a as FrakContextV1, at as LocalizedI18nConfig, b as LoggedOutEmbeddedView, c as FrakLifecycleEvent, ct as TrackArrivalParams, d as WalletStatusReturnType, et as Currency, f as UserReferralStatusType, g as TokenAmountType, h as RewardTier, i as FrakContext, it as ListenerPreloadOption, j as ModalStepTypes, k as ModalRpcStepsInput, l as IFrameTransport, lt as TrackArrivalResult, m as GetMerchantInformationReturnType, n as ssoPopupFeatures, nt as I18nConfig, o as FrakContextV2, ot as AttributionDefaults, p as EstimatedReward, q as InteractionTypeKey, r as ssoPopupName, rt as Language, s as FrakClient, st as AttributionParams, tt as FrakWalletSdkConfig, u as IFrameRpcSchema, ut as UtmParams, v as DisplayEmbeddedWalletParamsType, w as DisplaySharingPageParamsType, x as EmbeddedViewActionReferred, y as DisplayEmbeddedWalletResultType, z as OpenSsoParamsType } from "./openSso-DRLH4D9a.js";
|
|
2
|
+
import { A as getClientId, C as SdkEventMap, D as FrakContextManager, E as mergeAttribution, F as HashProtectedData, I as KeyProvider, M as setupClient, N as createIFrameFrakClient, O as DEEP_LINK_SCHEME, P as CompressedData, S as trackEvent, T as MergeAttributionInput, _ as isInAppBrowser, a as baseIframeProps, b as DeepLinkFallbackOptions, c as getCurrencyAmountKey, d as compressJsonToB64, f as base64urlDecode, g as isIOS, h as withCache, i as generateSsoUrl, j as getBackendUrl, k as sdkConfigStore, l as formatAmount, m as clearAllCache, n as CompressedSsoData, o as findIframeInOpener, p as base64urlEncode, r as FullSsoParams, s as getSupportedCurrency, t as AppSpecificSsoMetadata, u as decompressJsonFromB64, v as isMobile, w as SdkHandshakeFailureReason, x as triggerDeepLinkWithFallback, y as redirectToExternalBrowser } from "./index-B5_aKV0q.js";
|
|
3
|
+
export { type AppSpecificSsoMetadata, type AttributionDefaults, type AttributionParams, type ClientLifecycleEvent, type CompressedData, type CompressedSsoData, type Currency, DEEP_LINK_SCHEME, type DeepLinkFallbackOptions, type DisplayEmbeddedWalletParamsType, type DisplayEmbeddedWalletResultType, type DisplayModalParamsType, type DisplaySharingPageParamsType, type DisplaySharingPageResultType, type EmbeddedViewActionReferred, type EmbeddedViewActionSharing, type EstimatedReward, type FinalActionType, type FinalModalStepType, type FrakClient, type FrakContext, FrakContextManager, type FrakContextV1, type FrakContextV2, type FrakLifecycleEvent, type FrakWalletSdkConfig, type FullSsoParams, type GetMerchantInformationReturnType, type HashProtectedData, type I18nConfig, type IFrameLifecycleEvent, type IFrameRpcSchema, type IFrameTransport, type InteractionTypeKey, type KeyProvider, type Language, type ListenerPreloadOption, type LocalizedI18nConfig, type LoggedInEmbeddedView, type LoggedOutEmbeddedView, type LoginModalStepType, type MerchantConfigResponse, type MergeAttributionInput, type ModalRpcMetadata, type ModalRpcStepsInput, type ModalRpcStepsResultType, type ModalStepMetadata, type ModalStepTypes, type OpenSsoParamsType, type OpenSsoReturnType, type PrepareSsoParamsType, type PrepareSsoReturnType, type ResolvedPlacement, type ResolvedSdkConfig, type RewardTier, type SdkEventMap, type SdkHandshakeFailureReason, type SdkResolvedConfig, type SendInteractionParamsType, type SendTransactionModalStepType, type SendTransactionReturnType, type SendTransactionTxType, type SharingPageProduct, type SiweAuthenticateModalStepType, type SiweAuthenticateReturnType, type SiweAuthenticationParams, type SsoMetadata, type TokenAmountType, type TrackArrivalParams, type TrackArrivalResult, type UserReferralStatusType, type UtmParams, type WalletStatusReturnType, base64urlDecode, base64urlEncode, baseIframeProps, clearAllCache, compressJsonToB64, createIFrameFrakClient, decompressJsonFromB64, findIframeInOpener, formatAmount, generateSsoUrl, getBackendUrl, getClientId, getCurrencyAmountKey, getSupportedCurrency, isIOS, isInAppBrowser, isMobile, mergeAttribution, redirectToExternalBrowser, sdkConfigStore, setupClient, ssoPopupFeatures, ssoPopupName, trackEvent, triggerDeepLinkWithFallback, withCache };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,l as s,m as c,p as l,s as u,t as d,u as f}from"./frakContext-
|
|
1
|
+
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,l as s,m as c,p as l,s as u,t as d,u as f}from"./frakContext-UEOk9Bk4.js";import{a as p,c as m,d as h,f as g,h as _,i as v,l as y,m as b,n as x,o as S,p as C,r as w,s as T,t as E,u as D}from"./src-CB7gkP3D.js";export{_ as DEEP_LINK_SCHEME,d as FrakContextManager,r as base64urlDecode,i as base64urlEncode,g as baseIframeProps,o as clearAllCache,f as compressJsonToB64,h as createIFrameFrakClient,S as decompressJsonFromB64,C as findIframeInOpener,v as formatAmount,s as generateSsoUrl,c as getBackendUrl,e as getClientId,w as getCurrencyAmountKey,p as getSupportedCurrency,T as isIOS,m as isInAppBrowser,y as isMobile,E as mergeAttribution,D as redirectToExternalBrowser,l as sdkConfigStore,x as setupClient,u as ssoPopupFeatures,n as ssoPopupName,t as trackEvent,b as triggerDeepLinkWithFallback,a as withCache};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LifecycleMessage, RpcClient } from "@frak-labs/frame-connector";
|
|
2
1
|
import { OpenPanel } from "@openpanel/web";
|
|
3
2
|
import { Address, Hex } from "viem";
|
|
3
|
+
import { LifecycleMessage, RpcClient } from "@frak-labs/frame-connector";
|
|
4
4
|
import { SiweMessage } from "viem/siwe";
|
|
5
5
|
|
|
6
6
|
//#region src/types/tracking.d.ts
|
|
@@ -220,7 +220,6 @@ type ResolvedPlacement = {
|
|
|
220
220
|
text?: string;
|
|
221
221
|
noRewardText?: string;
|
|
222
222
|
clickAction?: "embedded-wallet" | "share-modal" | "sharing-page";
|
|
223
|
-
useReward?: boolean;
|
|
224
223
|
css?: string;
|
|
225
224
|
};
|
|
226
225
|
buttonWallet?: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { LifecycleMessage, RpcClient } from "@frak-labs/frame-connector";
|
|
1
2
|
import { OpenPanel } from "@openpanel/web";
|
|
2
3
|
import { Address, Hex } from "viem";
|
|
3
|
-
import { LifecycleMessage, RpcClient } from "@frak-labs/frame-connector";
|
|
4
4
|
import { SiweMessage } from "viem/siwe";
|
|
5
5
|
|
|
6
6
|
//#region src/types/tracking.d.ts
|
|
@@ -220,7 +220,6 @@ type ResolvedPlacement = {
|
|
|
220
220
|
text?: string;
|
|
221
221
|
noRewardText?: string;
|
|
222
222
|
clickAction?: "embedded-wallet" | "share-modal" | "sharing-page";
|
|
223
|
-
useReward?: boolean;
|
|
224
223
|
css?: string;
|
|
225
224
|
};
|
|
226
225
|
buttonWallet?: {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as e,d as t,h as n,m as r,p as i}from"./frakContext-UEOk9Bk4.js";import{Deferred as a,FrakRpcError as o,RpcErrorCodes as s,createRpcClient as c,jsonDecode as l}from"@frak-labs/frame-connector";import{OpenPanel as u}from"@openpanel/web";const d=`nexus-wallet-backup`,f=`frakwallet://`;function p(e,t){if(typeof window>`u`)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`))}function m(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}const h=f.replace(`://`,``);function g(e){return`intent://${e.slice(13)}#Intent;scheme=${h};end`}function _(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=m()&&v(e)?g(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function v(e){return e.startsWith(f)}const y={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 b({walletBaseUrl:t,config:n}){let i=document.querySelector(`#frak-wallet`);i&&i.remove();let a=document.createElement(`iframe`);a.id=y.id,a.name=y.name,a.allow=y.allow,a.style.zIndex=y.style.zIndex.toString(),S({iframe:a,isVisible:!1});let o=n?.walletUrl??t??`https://wallet.frak.id`,s=e();return w(o),w(r(o)),a.src=x({walletUrl:o,clientId:s,preload:n?.preload}),new Promise(e=>{a.addEventListener(`load`,()=>e(a)),document.body.appendChild(a)})}function x({walletUrl:e,clientId:t,preload:n}){let r=`${e}/listener?clientId=${encodeURIComponent(t)}`;return!n||n.length===0?r:`${r}#preload=${n.join(`,`)}`}function S({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 C(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 w(e){if(!(typeof document>`u`))try{let t=new URL(e).origin,n=`link[rel="preconnect"][data-frak-preconnect="${t}"]`;if(document.head.querySelector(n))return;let r=document.createElement(`link`);r.rel=`preconnect`,r.href=t,r.crossOrigin=``,r.dataset.frakPreconnect=t,document.head.appendChild(r)}catch{}}const T=(()=>{if(typeof navigator>`u`)return!1;let e=navigator.userAgent;if(!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1))return!1;let t=e.toLowerCase();return t.includes(`instagram`)||t.includes(`fban`)||t.includes(`fbav`)||t.includes(`facebook`)})();function E(e){e?localStorage.setItem(d,e):localStorage.removeItem(d)}function D(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=A(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function O(e){let t=new URL(window.location.href);e&&t.searchParams.set(`fmt`,e);let n=t.protocol===`http:`?`x-safari-http`:`x-safari-https`;window.location.href=`${n}://${t.host}${t.pathname}${t.search}${t.hash}`}function k(e){return e.includes(`/common/social`)}function A(e,t){if(!t)return e;try{let n=new URL(e);return n.searchParams.set(`fmt`,t),n.toString()}catch{return`${e}${e.includes(`?`)?`&`:`?`}fmt=${encodeURIComponent(t)}`}}function j(e,t,n,r,i){if(i){let e=D(t,r);window.open(e,`_blank`);return}if(v(t)){let i=D(t,r);_(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(T&&k(t))O(r);else{let e=D(t,r);window.location.href=e}}function M({iframe:e,targetOrigin:t}){let n=new a;return{handleEvent:r=>{if(!(`iframeLifecycle`in r))return;let{iframeLifecycle:i,data:a}=r;switch(i){case`connected`:n.resolve(!0);break;case`do-backup`:E(a.backup);break;case`remove-backup`:localStorage.removeItem(d);break;case`show`:case`hide`:S({iframe:e,isVisible:i===`show`});break;case`redirect`:j(e,a.baseRedirectUrl,t,a.mergeToken,a.openInNewTab);break}},isConnected:n.promise}}function N({config:t,iframe:r}){let l=t?.walletUrl??`https://wallet.frak.id`,d=typeof navigator<`u`?navigator.language?.split(`-`)[0]:void 0,f=t.metadata.lang??(d===`en`||d===`fr`?d:void 0),p=t.domain??(typeof window<`u`?window.location.hostname:``);i.setCacheScope(p,f),i.reset();let m=i.isCacheFresh?void 0:i.resolve(t.domain,t.walletUrl,f),h=M({iframe:r,targetOrigin:l}),g=new a,_=Date.now();if(!r.contentWindow)throw new o(s.configError,`The iframe does not have a content window`);let v=c({emittingTransport:r.contentWindow,listeningTransport:window,targetOrigin:l,middleware:[{async onRequest(e,t){if(!await h.isConnected)throw new o(s.clientNotConnected,`The iframe provider isn't connected yet`);return await g.promise,t}}],lifecycleHandlers:{iframeLifecycle:(e,t)=>{h.handleEvent(e)}}}),y=P(v,h),b=async()=>{y(),v.cleanup(),r.remove(),n(),i.clearCache(),i.reset()},x;{console.log(`[Frak SDK] Initializing OpenPanel`),x=new u({apiUrl:`https://op-api.gcp.frak.id`,clientId:`6eacc8d7-49ac-4936-95e9-81ef29449570`,trackScreenViews:!0,trackOutgoingLinks:!0,trackAttributes:!1,filter:({type:t,payload:n})=>(t!==`track`||!n?.properties||`sdk_version`in n.properties||(n.properties={...n.properties,sdk_version:`1.1.3`,user_anonymous_client_id:e()}),!0)}),x.setGlobalProperties({sdk_version:`1.1.3`,user_anonymous_client_id:e()}),x.init(),x.track(`sdk_initialized`,{sdk_version:`1.1.3`});let t=!1,n=setTimeout(()=>{t||(t=!0,x?.track(`sdk_iframe_handshake_failed`,{reason:`timeout`}))},3e4);h.isConnected.then(()=>{t||(t=!0,clearTimeout(n),x?.track(`sdk_iframe_connected`,{handshake_duration_ms:Date.now()-_}))}).catch(()=>{t||(t=!0,clearTimeout(n),x?.track(`sdk_iframe_handshake_failed`,{reason:`unknown`}))})}let S=F({config:t,rpcClient:v,lifecycleManager:h,configPromise:m,contextSent:g,openPanel:x}).then(()=>{}).catch(e=>{throw g.reject(e),e});return{config:t,waitForConnection:h.isConnected,waitForSetup:S,request:v.request,listenerRequest:v.listen,destroy:b,openPanel:x}}function P(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,250),r=setTimeout(()=>{o(),console.log(`Heartbeat timeout: connection failed`)},3e4),await t.isConnected,o()}function o(){n&&clearInterval(n),r&&clearTimeout(r)}return a(),o}async function F({config:t,rpcClient:n,lifecycleManager:r,configPromise:a,contextSent:o,openPanel:s}){await r.isConnected,p(n,r.isConnected);let c=new URL(window.location.href),l=c.searchParams.get(`fmt`)??void 0;l&&(c.searchParams.delete(`fmt`),window.history.replaceState({},``,c.toString()));let u=e=>{let n=e?.merchantId??t.metadata.merchantId??``,r=e?.domain??``,a=e?.allowedDomains??[],o=e?.sdkConfig,s=o?.attribution||t.attribution?{...t.attribution,...o?.attribution}:void 0;i.setConfig(o?{isResolved:!0,merchantId:n,domain:r,allowedDomains:a,hasRawSdkConfig:!0,name:o.name??t.metadata.name,logoUrl:o.logoUrl??t.metadata.logoUrl,homepageLink:o.homepageLink??t.metadata.homepageLink,lang:o.lang??t.metadata.lang,currency:o.currency??t.metadata.currency,hidden:o.hidden,css:o.css,translations:o.translations,placements:o.placements,components:o.components,attribution:s}:{isResolved:!0,merchantId:n,domain:r,allowedDomains:a,name:t.metadata.name,logoUrl:t.metadata.logoUrl,homepageLink:t.metadata.homepageLink,lang:t.metadata.lang,currency:t.metadata.currency,attribution:s})},f=!1,m=t=>{let r=f?void 0:l;f=!0;let i=t.hasRawSdkConfig?{name:t.name,logoUrl:t.logoUrl,homepageLink:t.homepageLink,lang:t.lang,currency:t.currency,hidden:t.hidden,css:t.css,translations:t.translations,placements:t.placements,attribution:t.attribution}:t.attribution?{attribution:t.attribution}:void 0,a=e();if(s){let e=s.global??{};s.setGlobalProperties({...e,merchant_id:t.merchantId,domain:t.domain??``})}n.sendLifecycle({clientLifecycle:`resolved-config`,data:{merchantId:t.merchantId,domain:t.domain??``,allowedDomains:t.allowedDomains??[],sourceUrl:window.location.href,...a&&{sdkAnonymousId:a},...r&&{pendingMergeToken:r},...i&&{sdkConfig:i}}})};i.isResolved&&(m(i.getConfig()),o.resolve()),a&&(u(await a),m(i.getConfig()),o.resolve());async function h(){let e=t.customizations?.css;e&&n.sendLifecycle({clientLifecycle:`modal-css`,data:{cssLink:e}})}async function g(){let e=t.customizations?.i18n;e&&n.sendLifecycle({clientLifecycle:`modal-i18n`,data:{i18n:e}})}async function _(){if(typeof window>`u`)return;let e=window.localStorage.getItem(d);e&&n.sendLifecycle({clientLifecycle:`restore-backup`,data:{backup:e}})}(await Promise.allSettled([h(),g(),_()])).some(e=>e.status===`rejected`)&&s?.track(`sdk_iframe_handshake_failed`,{reason:`asset_push`})}function I(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent;return!!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1)}const L=I();function R(){return typeof navigator>`u`?!1:L?!0:/Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}function z(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent.toLowerCase();return e.includes(`instagram`)||e.includes(`fban`)||e.includes(`fbav`)||e.includes(`facebook`)}const B=z();function V(e){L&&e.startsWith(`https://`)?window.location.href=`x-safari-https://${e.slice(8)}`:L&&e.startsWith(`http://`)?window.location.href=`x-safari-http://${e.slice(7)}`:window.location.href=`https://backend.frak.id/common/social?u=${encodeURIComponent(e)}`}function H(e){return l(t(e))}const U={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function W(e){return e&&e in U?e:`eur`}function G(e){return e?U[e]??U.eur:U.eur}function K(e,t){let n=G(t),r=W(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function q(e){return e?`${e}Amount`:`eurAmount`}async function J({config:e}){let t=Y(e),n=await b({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=N({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function Y(e){let t=W(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}function X({perCall:e,defaults:t,productUtmContent:n}){if(e===null)return;let r=e!==void 0,i=t!==void 0&&Object.keys(t).length>0;if(!r&&!i&&!(n!==void 0&&n!==``))return;let a={...t,...e??{}},o=n??e?.utmContent;return o!==void 0&&o!==``?a.utmContent=o:delete a.utmContent,a}export{W as a,B as c,N as d,y as f,f as h,K as i,R as l,_ as m,J as n,H as o,C as p,q as r,L as s,X as t,V as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./frakContext-Cfp7sSid.cjs`);let t=require(`@frak-labs/frame-connector`),n=require(`@openpanel/web`);const r=`nexus-wallet-backup`,i=`frakwallet://`;function a(e,t){if(typeof window>`u`)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`))}function o(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}const s=i.replace(`://`,``);function c(e){return`intent://${e.slice(13)}#Intent;scheme=${s};end`}function l(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=o()&&u(e)?c(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function u(e){return e.startsWith(i)}const d={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 f({walletBaseUrl:t,config:n}){let r=document.querySelector(`#frak-wallet`);r&&r.remove();let i=document.createElement(`iframe`);i.id=d.id,i.name=d.name,i.allow=d.allow,i.style.zIndex=d.style.zIndex.toString(),m({iframe:i,isVisible:!1});let a=n?.walletUrl??t??`https://wallet.frak.id`,o=e._();return g(a),g(e.m(a)),i.src=p({walletUrl:a,clientId:o,preload:n?.preload}),new Promise(e=>{i.addEventListener(`load`,()=>e(i)),document.body.appendChild(i)})}function p({walletUrl:e,clientId:t,preload:n}){let r=`${e}/listener?clientId=${encodeURIComponent(t)}`;return!n||n.length===0?r:`${r}#preload=${n.join(`,`)}`}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 h(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 g(e){if(!(typeof document>`u`))try{let t=new URL(e).origin,n=`link[rel="preconnect"][data-frak-preconnect="${t}"]`;if(document.head.querySelector(n))return;let r=document.createElement(`link`);r.rel=`preconnect`,r.href=t,r.crossOrigin=``,r.dataset.frakPreconnect=t,document.head.appendChild(r)}catch{}}const _=(()=>{if(typeof navigator>`u`)return!1;let e=navigator.userAgent;if(!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1))return!1;let t=e.toLowerCase();return t.includes(`instagram`)||t.includes(`fban`)||t.includes(`fbav`)||t.includes(`facebook`)})();function v(e){e?localStorage.setItem(r,e):localStorage.removeItem(r)}function y(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=S(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function b(e){let t=new URL(window.location.href);e&&t.searchParams.set(`fmt`,e);let n=t.protocol===`http:`?`x-safari-http`:`x-safari-https`;window.location.href=`${n}://${t.host}${t.pathname}${t.search}${t.hash}`}function x(e){return e.includes(`/common/social`)}function S(e,t){if(!t)return e;try{let n=new URL(e);return n.searchParams.set(`fmt`,t),n.toString()}catch{return`${e}${e.includes(`?`)?`&`:`?`}fmt=${encodeURIComponent(t)}`}}function C(e,t,n,r,i){if(i){let e=y(t,r);window.open(e,`_blank`);return}if(u(t)){let i=y(t,r);l(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(_&&x(t))b(r);else{let e=y(t,r);window.location.href=e}}function w({iframe:e,targetOrigin:n}){let i=new t.Deferred;return{handleEvent:t=>{if(!(`iframeLifecycle`in t))return;let{iframeLifecycle:a,data:o}=t;switch(a){case`connected`:i.resolve(!0);break;case`do-backup`:v(o.backup);break;case`remove-backup`:localStorage.removeItem(r);break;case`show`:case`hide`:m({iframe:e,isVisible:a===`show`});break;case`redirect`:C(e,o.baseRedirectUrl,n,o.mergeToken,o.openInNewTab);break}},isConnected:i.promise}}function T({config:r,iframe:i}){let a=r?.walletUrl??`https://wallet.frak.id`,o=typeof navigator<`u`?navigator.language?.split(`-`)[0]:void 0,s=r.metadata.lang??(o===`en`||o===`fr`?o:void 0),c=r.domain??(typeof window<`u`?window.location.hostname:``);e.p.setCacheScope(c,s),e.p.reset();let l=e.p.isCacheFresh?void 0:e.p.resolve(r.domain,r.walletUrl,s),u=w({iframe:i,targetOrigin:a}),d=new t.Deferred,f=Date.now();if(!i.contentWindow)throw new t.FrakRpcError(t.RpcErrorCodes.configError,`The iframe does not have a content window`);let p=(0,t.createRpcClient)({emittingTransport:i.contentWindow,listeningTransport:window,targetOrigin:a,middleware:[{async onRequest(e,n){if(!await u.isConnected)throw new t.FrakRpcError(t.RpcErrorCodes.clientNotConnected,`The iframe provider isn't connected yet`);return await d.promise,n}}],lifecycleHandlers:{iframeLifecycle:(e,t)=>{u.handleEvent(e)}}}),m=E(p,u),h=async()=>{m(),p.cleanup(),i.remove(),e.h(),e.p.clearCache(),e.p.reset()},g;{console.log(`[Frak SDK] Initializing OpenPanel`),g=new n.OpenPanel({apiUrl:`https://op-api.gcp.frak.id`,clientId:`6eacc8d7-49ac-4936-95e9-81ef29449570`,trackScreenViews:!0,trackOutgoingLinks:!0,trackAttributes:!1,filter:({type:t,payload:n})=>(t!==`track`||!n?.properties||`sdk_version`in n.properties||(n.properties={...n.properties,sdk_version:`1.1.3`,user_anonymous_client_id:e._()}),!0)}),g.setGlobalProperties({sdk_version:`1.1.3`,user_anonymous_client_id:e._()}),g.init(),g.track(`sdk_initialized`,{sdk_version:`1.1.3`});let t=!1,r=setTimeout(()=>{t||(t=!0,g?.track(`sdk_iframe_handshake_failed`,{reason:`timeout`}))},3e4);u.isConnected.then(()=>{t||(t=!0,clearTimeout(r),g?.track(`sdk_iframe_connected`,{handshake_duration_ms:Date.now()-f}))}).catch(()=>{t||(t=!0,clearTimeout(r),g?.track(`sdk_iframe_handshake_failed`,{reason:`unknown`}))})}let _=D({config:r,rpcClient:p,lifecycleManager:u,configPromise:l,contextSent:d,openPanel:g}).then(()=>{}).catch(e=>{throw d.reject(e),e});return{config:r,waitForConnection:u.isConnected,waitForSetup:_,request:p.request,listenerRequest:p.listen,destroy:h,openPanel:g}}function E(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,250),r=setTimeout(()=>{o(),console.log(`Heartbeat timeout: connection failed`)},3e4),await t.isConnected,o()}function o(){n&&clearInterval(n),r&&clearTimeout(r)}return a(),o}async function D({config:t,rpcClient:n,lifecycleManager:i,configPromise:o,contextSent:s,openPanel:c}){await i.isConnected,a(n,i.isConnected);let l=new URL(window.location.href),u=l.searchParams.get(`fmt`)??void 0;u&&(l.searchParams.delete(`fmt`),window.history.replaceState({},``,l.toString()));let d=n=>{let r=n?.merchantId??t.metadata.merchantId??``,i=n?.domain??``,a=n?.allowedDomains??[],o=n?.sdkConfig,s=o?.attribution||t.attribution?{...t.attribution,...o?.attribution}:void 0;e.p.setConfig(o?{isResolved:!0,merchantId:r,domain:i,allowedDomains:a,hasRawSdkConfig:!0,name:o.name??t.metadata.name,logoUrl:o.logoUrl??t.metadata.logoUrl,homepageLink:o.homepageLink??t.metadata.homepageLink,lang:o.lang??t.metadata.lang,currency:o.currency??t.metadata.currency,hidden:o.hidden,css:o.css,translations:o.translations,placements:o.placements,components:o.components,attribution:s}:{isResolved:!0,merchantId:r,domain:i,allowedDomains:a,name:t.metadata.name,logoUrl:t.metadata.logoUrl,homepageLink:t.metadata.homepageLink,lang:t.metadata.lang,currency:t.metadata.currency,attribution:s})},f=!1,p=t=>{let r=f?void 0:u;f=!0;let i=t.hasRawSdkConfig?{name:t.name,logoUrl:t.logoUrl,homepageLink:t.homepageLink,lang:t.lang,currency:t.currency,hidden:t.hidden,css:t.css,translations:t.translations,placements:t.placements,attribution:t.attribution}:t.attribution?{attribution:t.attribution}:void 0,a=e._();if(c){let e=c.global??{};c.setGlobalProperties({...e,merchant_id:t.merchantId,domain:t.domain??``})}n.sendLifecycle({clientLifecycle:`resolved-config`,data:{merchantId:t.merchantId,domain:t.domain??``,allowedDomains:t.allowedDomains??[],sourceUrl:window.location.href,...a&&{sdkAnonymousId:a},...r&&{pendingMergeToken:r},...i&&{sdkConfig:i}}})};e.p.isResolved&&(p(e.p.getConfig()),s.resolve()),o&&(d(await o),p(e.p.getConfig()),s.resolve());async function m(){let e=t.customizations?.css;e&&n.sendLifecycle({clientLifecycle:`modal-css`,data:{cssLink:e}})}async function h(){let e=t.customizations?.i18n;e&&n.sendLifecycle({clientLifecycle:`modal-i18n`,data:{i18n:e}})}async function g(){if(typeof window>`u`)return;let e=window.localStorage.getItem(r);e&&n.sendLifecycle({clientLifecycle:`restore-backup`,data:{backup:e}})}(await Promise.allSettled([m(),h(),g()])).some(e=>e.status===`rejected`)&&c?.track(`sdk_iframe_handshake_failed`,{reason:`asset_push`})}function O(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent;return!!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1)}const k=O();function A(){return typeof navigator>`u`?!1:k?!0:/Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}function j(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent.toLowerCase();return e.includes(`instagram`)||e.includes(`fban`)||e.includes(`fbav`)||e.includes(`facebook`)}const M=j();function N(e){k&&e.startsWith(`https://`)?window.location.href=`x-safari-https://${e.slice(8)}`:k&&e.startsWith(`http://`)?window.location.href=`x-safari-http://${e.slice(7)}`:window.location.href=`https://backend.frak.id/common/social?u=${encodeURIComponent(e)}`}function P(n){return(0,t.jsonDecode)(e.d(n))}const F={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function I(e){return e&&e in F?e:`eur`}function L(e){return e?F[e]??F.eur:F.eur}function R(e,t){let n=L(t),r=I(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function z(e){return e?`${e}Amount`:`eurAmount`}async function B({config:e}){let t=V(e),n=await f({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=T({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function V(e){let t=I(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}function H({perCall:e,defaults:t,productUtmContent:n}){if(e===null)return;let r=e!==void 0,i=t!==void 0&&Object.keys(t).length>0;if(!r&&!i&&!(n!==void 0&&n!==``))return;let a={...t,...e??{}},o=n??e?.utmContent;return o!==void 0&&o!==``?a.utmContent=o:delete a.utmContent,a}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return N}});
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "https://twitter.com/QNivelais"
|
|
12
12
|
}
|
|
13
13
|
],
|
|
14
|
-
"version": "1.1.
|
|
14
|
+
"version": "1.1.3-beta.20a3d2fa",
|
|
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",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"exports": {
|
|
42
42
|
".": {
|
|
43
43
|
"development": "./src/index.ts",
|
|
44
|
+
"production": "./src/index.ts",
|
|
44
45
|
"import": {
|
|
45
46
|
"types": "./dist/index.d.ts",
|
|
46
47
|
"default": "./dist/index.js"
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
},
|
|
53
54
|
"./actions": {
|
|
54
55
|
"development": "./src/actions/index.ts",
|
|
56
|
+
"production": "./src/actions/index.ts",
|
|
55
57
|
"import": {
|
|
56
58
|
"types": "./dist/actions.d.ts",
|
|
57
59
|
"default": "./dist/actions.js"
|
|
@@ -91,7 +93,7 @@
|
|
|
91
93
|
"viem": "^2.x"
|
|
92
94
|
},
|
|
93
95
|
"dependencies": {
|
|
94
|
-
"@frak-labs/frame-connector": "0.2.0",
|
|
96
|
+
"@frak-labs/frame-connector": "0.2.0-beta.20a3d2fa",
|
|
95
97
|
"@openpanel/web": "^1.4.1"
|
|
96
98
|
},
|
|
97
99
|
"devDependencies": {
|
|
@@ -105,9 +105,9 @@ describe("processReferral", () => {
|
|
|
105
105
|
mockClient,
|
|
106
106
|
"user_referred_started",
|
|
107
107
|
{
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
referrer_client_id: "referrer-client-id",
|
|
109
|
+
referrer_wallet: undefined,
|
|
110
|
+
wallet_status: "connected",
|
|
111
111
|
}
|
|
112
112
|
);
|
|
113
113
|
|
|
@@ -235,7 +235,7 @@ describe("processReferral", () => {
|
|
|
235
235
|
"user_referred_started",
|
|
236
236
|
{
|
|
237
237
|
referrer: "0xabcdefabcdefabcdefabcdefabcdefabcdefabcd",
|
|
238
|
-
|
|
238
|
+
wallet_status: "connected",
|
|
239
239
|
}
|
|
240
240
|
);
|
|
241
241
|
});
|
|
@@ -53,9 +53,9 @@ function trackArrivalIfValid(
|
|
|
53
53
|
): boolean {
|
|
54
54
|
if (isV2Context(frakContext)) {
|
|
55
55
|
trackEvent(client, "user_referred_started", {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
referrer_client_id: frakContext.c,
|
|
57
|
+
referrer_wallet: frakContext.w,
|
|
58
|
+
wallet_status: walletStatus?.key,
|
|
59
59
|
});
|
|
60
60
|
sendInteraction(client, {
|
|
61
61
|
type: "arrival",
|
|
@@ -70,7 +70,7 @@ function trackArrivalIfValid(
|
|
|
70
70
|
if (isV1Context(frakContext)) {
|
|
71
71
|
trackEvent(client, "user_referred_started", {
|
|
72
72
|
referrer: frakContext.r,
|
|
73
|
-
|
|
73
|
+
wallet_status: walletStatus?.key,
|
|
74
74
|
});
|
|
75
75
|
sendInteraction(client, {
|
|
76
76
|
type: "arrival",
|
|
@@ -153,11 +153,11 @@ export function createIFrameFrakClient({
|
|
|
153
153
|
if (!payload?.properties) return true;
|
|
154
154
|
|
|
155
155
|
// Check if we we got the properties once initialized
|
|
156
|
-
if (!("
|
|
156
|
+
if (!("sdk_version" in payload.properties)) {
|
|
157
157
|
payload.properties = {
|
|
158
158
|
...payload.properties,
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
sdk_version: process.env.SDK_VERSION,
|
|
160
|
+
user_anonymous_client_id: getClientId(),
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
163
|
|
|
@@ -165,12 +165,12 @@ export function createIFrameFrakClient({
|
|
|
165
165
|
},
|
|
166
166
|
});
|
|
167
167
|
openPanel.setGlobalProperties({
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
sdk_version: process.env.SDK_VERSION,
|
|
169
|
+
user_anonymous_client_id: getClientId(),
|
|
170
170
|
});
|
|
171
171
|
openPanel.init();
|
|
172
172
|
openPanel.track("sdk_initialized", {
|
|
173
|
-
|
|
173
|
+
sdk_version: process.env.SDK_VERSION,
|
|
174
174
|
});
|
|
175
175
|
|
|
176
176
|
// Race the connection against the heartbeat timeout so we can
|
|
@@ -398,7 +398,7 @@ async function postConnectionSetup({
|
|
|
398
398
|
const current = openPanel.global ?? {};
|
|
399
399
|
openPanel.setGlobalProperties({
|
|
400
400
|
...current,
|
|
401
|
-
|
|
401
|
+
merchant_id: resolved.merchantId,
|
|
402
402
|
domain: resolved.domain ?? "",
|
|
403
403
|
});
|
|
404
404
|
}
|
|
@@ -218,14 +218,6 @@ describe("FrakContextManager", () => {
|
|
|
218
218
|
expect(parsedUrl.searchParams.get("utm_source")).toBe(
|
|
219
219
|
"frak"
|
|
220
220
|
);
|
|
221
|
-
expect(parsedUrl.searchParams.get("utm_medium")).toBe(
|
|
222
|
-
"referral"
|
|
223
|
-
);
|
|
224
|
-
expect(parsedUrl.searchParams.get("utm_campaign")).toBe(
|
|
225
|
-
v2Context.m
|
|
226
|
-
);
|
|
227
|
-
expect(parsedUrl.searchParams.get("via")).toBe("frak");
|
|
228
|
-
expect(parsedUrl.searchParams.get("ref")).toBe(v2Context.c);
|
|
229
221
|
});
|
|
230
222
|
|
|
231
223
|
it("should apply default attribution params when attribution is an empty object", () => {
|
|
@@ -240,18 +232,6 @@ describe("FrakContextManager", () => {
|
|
|
240
232
|
expect(parsedUrl.searchParams.get("utm_source")).toBe(
|
|
241
233
|
"frak"
|
|
242
234
|
);
|
|
243
|
-
expect(parsedUrl.searchParams.get("utm_medium")).toBe(
|
|
244
|
-
"referral"
|
|
245
|
-
);
|
|
246
|
-
expect(parsedUrl.searchParams.get("utm_campaign")).toBe(
|
|
247
|
-
v2Context.m
|
|
248
|
-
);
|
|
249
|
-
expect(parsedUrl.searchParams.get("via")).toBe("frak");
|
|
250
|
-
expect(parsedUrl.searchParams.get("ref")).toBe(v2Context.c);
|
|
251
|
-
expect(
|
|
252
|
-
parsedUrl.searchParams.get("utm_content")
|
|
253
|
-
).toBeNull();
|
|
254
|
-
expect(parsedUrl.searchParams.get("utm_term")).toBeNull();
|
|
255
235
|
});
|
|
256
236
|
|
|
257
237
|
it("should honor overrides over defaults", () => {
|
|
@@ -306,11 +286,6 @@ describe("FrakContextManager", () => {
|
|
|
306
286
|
expect(parsedUrl.searchParams.get("utm_campaign")).toBe(
|
|
307
287
|
"merchant-spring"
|
|
308
288
|
);
|
|
309
|
-
// Missing ones filled by Frak defaults
|
|
310
|
-
expect(parsedUrl.searchParams.get("utm_medium")).toBe(
|
|
311
|
-
"referral"
|
|
312
|
-
);
|
|
313
|
-
expect(parsedUrl.searchParams.get("ref")).toBe(v2Context.c);
|
|
314
289
|
});
|
|
315
290
|
|
|
316
291
|
it("should skip fields with empty-string overrides", () => {
|
|
@@ -325,6 +300,14 @@ describe("FrakContextManager", () => {
|
|
|
325
300
|
false
|
|
326
301
|
);
|
|
327
302
|
expect(parsedUrl.searchParams.has("utm_term")).toBe(false);
|
|
303
|
+
expect(parsedUrl.searchParams.has("utm_medium")).toBe(
|
|
304
|
+
false
|
|
305
|
+
);
|
|
306
|
+
expect(parsedUrl.searchParams.has("utm_campaign")).toBe(
|
|
307
|
+
false
|
|
308
|
+
);
|
|
309
|
+
expect(parsedUrl.searchParams.has("via")).toBe(false);
|
|
310
|
+
expect(parsedUrl.searchParams.has("ref")).toBe(false);
|
|
328
311
|
});
|
|
329
312
|
|
|
330
313
|
it("should skip context-derived defaults for V1 (no merchantId/clientId)", () => {
|
|
@@ -342,15 +325,6 @@ describe("FrakContextManager", () => {
|
|
|
342
325
|
expect(parsedUrl.searchParams.get("utm_source")).toBe(
|
|
343
326
|
"frak"
|
|
344
327
|
);
|
|
345
|
-
expect(parsedUrl.searchParams.get("utm_medium")).toBe(
|
|
346
|
-
"referral"
|
|
347
|
-
);
|
|
348
|
-
expect(parsedUrl.searchParams.get("via")).toBe("frak");
|
|
349
|
-
// No derivable values from V1
|
|
350
|
-
expect(parsedUrl.searchParams.has("utm_campaign")).toBe(
|
|
351
|
-
false
|
|
352
|
-
);
|
|
353
|
-
expect(parsedUrl.searchParams.has("ref")).toBe(false);
|
|
354
328
|
});
|
|
355
329
|
});
|
|
356
330
|
});
|
|
@@ -91,11 +91,6 @@ function parse({ url }: { url: string }): FrakContext | null | undefined {
|
|
|
91
91
|
return decompress(frakContext);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
/**
|
|
95
|
-
* Default UTM medium value when attribution is requested.
|
|
96
|
-
*/
|
|
97
|
-
const DEFAULT_UTM_MEDIUM = "referral";
|
|
98
|
-
|
|
99
94
|
/**
|
|
100
95
|
* Default utm_source / via value when attribution is requested.
|
|
101
96
|
*/
|
|
@@ -110,18 +105,16 @@ const DEFAULT_ATTRIBUTION_SOURCE = "frak";
|
|
|
110
105
|
* addresses leaking into UTM params. V1 contexts have no equivalent.
|
|
111
106
|
*/
|
|
112
107
|
function resolveAttributionValues(
|
|
113
|
-
context: FrakContextV1 | FrakContextV2,
|
|
114
108
|
overrides: AttributionParams
|
|
115
109
|
): Record<string, string | undefined> {
|
|
116
|
-
const isV2 = isV2Context(context);
|
|
117
110
|
return {
|
|
118
111
|
utm_source: overrides.utmSource ?? DEFAULT_ATTRIBUTION_SOURCE,
|
|
119
|
-
utm_medium: overrides.utmMedium ??
|
|
120
|
-
utm_campaign: overrides.utmCampaign ??
|
|
112
|
+
utm_medium: overrides.utmMedium ?? undefined,
|
|
113
|
+
utm_campaign: overrides.utmCampaign ?? undefined,
|
|
121
114
|
utm_content: overrides.utmContent,
|
|
122
115
|
utm_term: overrides.utmTerm,
|
|
123
|
-
via: overrides.via ??
|
|
124
|
-
ref: overrides.ref ??
|
|
116
|
+
via: overrides.via ?? undefined,
|
|
117
|
+
ref: overrides.ref ?? undefined,
|
|
125
118
|
};
|
|
126
119
|
}
|
|
127
120
|
|
|
@@ -133,10 +126,9 @@ function resolveAttributionValues(
|
|
|
133
126
|
*/
|
|
134
127
|
function applyAttributionParams(
|
|
135
128
|
urlObj: URL,
|
|
136
|
-
context: FrakContextV1 | FrakContextV2,
|
|
137
129
|
attribution?: AttributionParams
|
|
138
130
|
): void {
|
|
139
|
-
const values = resolveAttributionValues(
|
|
131
|
+
const values = resolveAttributionValues(attribution ?? {});
|
|
140
132
|
for (const [key, value] of Object.entries(values)) {
|
|
141
133
|
if (value === undefined || value === "") continue;
|
|
142
134
|
if (urlObj.searchParams.has(key)) continue;
|
|
@@ -174,7 +166,7 @@ function update({
|
|
|
174
166
|
|
|
175
167
|
const urlObj = new URL(url);
|
|
176
168
|
urlObj.searchParams.set(contextKey, compressedContext);
|
|
177
|
-
applyAttributionParams(urlObj,
|
|
169
|
+
applyAttributionParams(urlObj, attribution);
|
|
178
170
|
return urlObj.toString();
|
|
179
171
|
}
|
|
180
172
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export type SdkReferralEventMap = {
|
|
2
2
|
user_referred_started: {
|
|
3
3
|
referrer?: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
referrer_client_id?: string;
|
|
5
|
+
referrer_wallet?: string;
|
|
6
|
+
wallet_status?: string;
|
|
7
7
|
};
|
|
8
8
|
user_referred_completed: {
|
|
9
9
|
status: "success";
|
|
@@ -185,6 +185,45 @@ describe("iframeHelper", () => {
|
|
|
185
185
|
|
|
186
186
|
expect(mockIframe.style.zIndex).toBe("2000001");
|
|
187
187
|
});
|
|
188
|
+
|
|
189
|
+
it("should append #preload=... when config.preload is non-empty", async () => {
|
|
190
|
+
const config: FrakWalletSdkConfig = {
|
|
191
|
+
metadata: { name: "Test" },
|
|
192
|
+
preload: ["sharing"],
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
await createIframe({ config });
|
|
196
|
+
|
|
197
|
+
expect(mockIframe.src).toBe(
|
|
198
|
+
"https://wallet.frak.id/listener?clientId=mock-client-id-for-test#preload=sharing"
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("should join multiple preload options with comma", async () => {
|
|
203
|
+
const config: FrakWalletSdkConfig = {
|
|
204
|
+
metadata: { name: "Test" },
|
|
205
|
+
preload: ["sharing", "modal"],
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
await createIframe({ config });
|
|
209
|
+
|
|
210
|
+
expect(mockIframe.src).toBe(
|
|
211
|
+
"https://wallet.frak.id/listener?clientId=mock-client-id-for-test#preload=sharing,modal"
|
|
212
|
+
);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("should omit the preload hash when config.preload is an empty array", async () => {
|
|
216
|
+
const config: FrakWalletSdkConfig = {
|
|
217
|
+
metadata: { name: "Test" },
|
|
218
|
+
preload: [],
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
await createIframe({ config });
|
|
222
|
+
|
|
223
|
+
expect(mockIframe.src).toBe(
|
|
224
|
+
"https://wallet.frak.id/listener?clientId=mock-client-id-for-test"
|
|
225
|
+
);
|
|
226
|
+
});
|
|
188
227
|
});
|
|
189
228
|
|
|
190
229
|
describe("changeIframeVisibility", () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getBackendUrl } from "../../config/backendUrl";
|
|
2
2
|
import { getClientId } from "../../config/clientId";
|
|
3
|
-
import type { FrakWalletSdkConfig } from "../../types";
|
|
3
|
+
import type { FrakWalletSdkConfig, ListenerPreloadOption } from "../../types";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Base props for the iframe
|
|
@@ -64,7 +64,11 @@ export function createIframe({
|
|
|
64
64
|
preconnect(walletUrl);
|
|
65
65
|
preconnect(getBackendUrl(walletUrl));
|
|
66
66
|
|
|
67
|
-
iframe.src =
|
|
67
|
+
iframe.src = buildListenerUrl({
|
|
68
|
+
walletUrl,
|
|
69
|
+
clientId,
|
|
70
|
+
preload: config?.preload,
|
|
71
|
+
});
|
|
68
72
|
|
|
69
73
|
return new Promise((resolve) => {
|
|
70
74
|
iframe.addEventListener("load", () => resolve(iframe));
|
|
@@ -72,6 +76,31 @@ export function createIframe({
|
|
|
72
76
|
});
|
|
73
77
|
}
|
|
74
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Build the listener iframe URL.
|
|
81
|
+
*
|
|
82
|
+
* Query params:
|
|
83
|
+
* - `clientId` — anonymous SDK client identifier used for funnel joining.
|
|
84
|
+
*
|
|
85
|
+
* Hash params (consumed by `apps/listener/app/bootstrap.ts#setupPreloadHints`):
|
|
86
|
+
* - `preload=modal,sharing` — idle-warms the matching Ring 1 + Ring 2 chunks.
|
|
87
|
+
* Skipped entirely when no preload hints are provided so the listener
|
|
88
|
+
* doesn't pay for warm-ups that nobody asked for.
|
|
89
|
+
*/
|
|
90
|
+
function buildListenerUrl({
|
|
91
|
+
walletUrl,
|
|
92
|
+
clientId,
|
|
93
|
+
preload,
|
|
94
|
+
}: {
|
|
95
|
+
walletUrl: string;
|
|
96
|
+
clientId: string;
|
|
97
|
+
preload?: ListenerPreloadOption[];
|
|
98
|
+
}): string {
|
|
99
|
+
const base = `${walletUrl}/listener?clientId=${encodeURIComponent(clientId)}`;
|
|
100
|
+
if (!preload || preload.length === 0) return base;
|
|
101
|
+
return `${base}#preload=${preload.join(",")}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
75
104
|
/**
|
|
76
105
|
* Change the visibility of the given iframe
|
|
77
106
|
* @ignore
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=require(`./frakContext-_b-_uwgd.cjs`);let t=require(`@frak-labs/frame-connector`);async function n(e,t,n){return await e.request({method:`frak_displayEmbeddedWallet`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function r(e,{steps:t,metadata:n},r){return await e.request({method:`frak_displayModal`,params:r?[t,n,e.config.metadata,r]:[t,n,e.config.metadata]})}async function i(e,t,n){return await e.request({method:`frak_displaySharingPage`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function a(t){if(typeof window>`u`)return;let n=e._();if(!n)return;let r=await e.p.resolveMerchantId();if(!r)return;let i=`frak-identity-ensured-${r}`;if(!window.sessionStorage.getItem(i))try{let a=e.m();(await fetch(`${a}/user/identity/ensure`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`,"x-wallet-sdk-auth":t,"x-frak-client-id":n},body:JSON.stringify({merchantId:r})})).ok&&window.sessionStorage.setItem(i,`1`)}catch{}}async function o(t,n){return e.g(()=>t.request({method:`frak_getMerchantInformation`}),{cacheKey:`frak_getMerchantInformation`,cacheTime:n?.cacheTime})}async function s(t,n){return e.g(()=>t.request({method:`frak_getMergeToken`}),{cacheKey:`frak_getMergeToken`,cacheTime:n?.cacheTime})}async function c(t,n){return e.g(()=>t.request({method:`frak_getUserReferralStatus`}),{cacheKey:`frak_getUserReferralStatus`,cacheTime:n?.cacheTime})}async function l(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function u(t,n){try{await t.request({method:`frak_sendInteraction`,params:[n,{clientId:e._()}]})}catch{console.warn(`[Frak SDK] Failed to send interaction:`,n.type)}}function d(t,n,r){return e.r(n)?(e.a(t,`user_referred_started`,{referrerClientId:n.c,referrerWallet:n.w,walletStatus:r?.key}),u(t,{type:`arrival`,referrerClientId:n.c,referrerMerchantId:n.m,referrerWallet:n.w,referralTimestamp:n.t}),!0):e.n(n)?(e.a(t,`user_referred_started`,{referrer:n.r,walletStatus:r?.key}),u(t,{type:`arrival`,referrerWallet:n.r}),!0):!1}function f(t,n){let r=e._();return!r&&!n?null:{v:2,m:t,t:Math.floor(Date.now()/1e3),...r?{c:r}:{},...n?{w:n}:{}}}function p(t,n){return e.r(t)?t.w&&n?.wallet?e.i(t.w,n.wallet):t.c?e._()===t.c:!1:e.n(t)&&n?.wallet?e.i(t.r,n.wallet):!1}function m(t,{walletStatus:n,frakContext:r,options:i}){if(!r)return`no-referrer`;if(p(r,n))return`self-referral`;if(!d(t,r,n))return`no-referrer`;let a=e.r(r)?r.m:i?.merchantId,o=i?.alwaysAppendUrl&&a?f(a,n?.wallet):null;return e.t.replaceUrl({url:window.location?.href,context:o}),e.a(t,`user_referred_completed`,{status:`success`}),`success`}async function h(t,{options:n}={}){let r=e.t.parse({url:window.location.href}),i=await y(t);try{return m(t,{walletStatus:i,frakContext:r,options:n})}catch(e){console.warn(`Error processing referral`,{error:e})}}const g=`frak:referral-success`;async function _(e){try{await h(e)===`success`&&window.dispatchEvent(new Event(g))}catch(e){console.warn(`[Frak] Referral setup failed`,e)}}async function v(t){if(typeof window>`u`){console.warn(`[Frak] No window found, can't track purchase`);return}let n=window.sessionStorage.getItem(`frak-wallet-interaction-token`),r=e._();if(!n&&!r){console.warn(`[Frak] No identity found, skipping purchase check`);return}let i=t.merchantId??await e.p.resolveMerchantId();if(!i){console.warn(`[Frak] No merchant id found, skipping purchase check`);return}let a={Accept:`application/json`,"Content-Type":`application/json`};n&&(a[`x-wallet-sdk-auth`]=n),r&&(a[`x-frak-client-id`]=r);let o=e.m();await fetch(`${o}/user/track/purchase`,{method:`POST`,headers:a,body:JSON.stringify({customerId:t.customerId,orderId:t.orderId,token:t.token,merchantId:i})})}function y(e,n){if(!n)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(b(e,t),t));let r=new t.Deferred,i=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},t=>{b(e,t),n(t),i||=(r.resolve(t),!0)}),r.promise}function b(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?(window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken),a(t.interactionToken)):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function x(e,{metadata:t,login:n}){return S(e,{steps:{login:n??{}},metadata:t})}function S(e,t){function n(n){return S(e,{...t,steps:{...t.steps,sendTransaction:n}})}function i(n){return S(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function a(n,r){return S(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function o(n,i){return n&&(t.metadata=n(t.metadata??{})),await r(e,t,i)}return{params:t,sendTx:n,reward:i,sharing:a,display:o}}async function C(e,{tx:t,metadata:n}){return(await r(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}function w(e=96){let t=Math.ceil(e/2),n=``;if(typeof crypto<`u`&&crypto.getRandomValues){let e=new Uint8Array(t);crypto.getRandomValues(e);for(let t=0;t<e.length;t++)n+=e[t].toString(16).padStart(2,`0`)}else for(let e=0;e<t;e++)n+=(Math.random()*256|0).toString(16).padStart(2,`0`);return n.substring(0,e)}async function T(e,{siwe:t,metadata:n}){let i=e.config?.domain??window.location.host,a=t?.statement??`I confirm that I want to use my Frak wallet on: ${e.config.metadata.name}`;return(await r(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:a,nonce:t?.nonce??w(),uri:t?.uri??`https://${i}`,version:t?.version??`1`,domain:i}}}})).siweAuthenticate}Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return n}});
|
package/dist/actions-dH5NFCj1.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_ as e,a as t,g as n,i as r,m as i,n as a,p as o,r as s,t as c}from"./frakContext-CTKalP6g.js";import{Deferred as l}from"@frak-labs/frame-connector";async function u(e,t,n){return await e.request({method:`frak_displayEmbeddedWallet`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function d(e,{steps:t,metadata:n},r){return await e.request({method:`frak_displayModal`,params:r?[t,n,e.config.metadata,r]:[t,n,e.config.metadata]})}async function f(e,t,n){return await e.request({method:`frak_displaySharingPage`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function p(t){if(typeof window>`u`)return;let n=e();if(!n)return;let r=await o.resolveMerchantId();if(!r)return;let a=`frak-identity-ensured-${r}`;if(!window.sessionStorage.getItem(a))try{let e=i();(await fetch(`${e}/user/identity/ensure`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`,"x-wallet-sdk-auth":t,"x-frak-client-id":n},body:JSON.stringify({merchantId:r})})).ok&&window.sessionStorage.setItem(a,`1`)}catch{}}async function m(e,t){return n(()=>e.request({method:`frak_getMerchantInformation`}),{cacheKey:`frak_getMerchantInformation`,cacheTime:t?.cacheTime})}async function h(e,t){return n(()=>e.request({method:`frak_getMergeToken`}),{cacheKey:`frak_getMergeToken`,cacheTime:t?.cacheTime})}async function g(e,t){return n(()=>e.request({method:`frak_getUserReferralStatus`}),{cacheKey:`frak_getUserReferralStatus`,cacheTime:t?.cacheTime})}async function _(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function v(t,n){try{await t.request({method:`frak_sendInteraction`,params:[n,{clientId:e()}]})}catch{console.warn(`[Frak SDK] Failed to send interaction:`,n.type)}}function y(e,n,r){return s(n)?(t(e,`user_referred_started`,{referrerClientId:n.c,referrerWallet:n.w,walletStatus:r?.key}),v(e,{type:`arrival`,referrerClientId:n.c,referrerMerchantId:n.m,referrerWallet:n.w,referralTimestamp:n.t}),!0):a(n)?(t(e,`user_referred_started`,{referrer:n.r,walletStatus:r?.key}),v(e,{type:`arrival`,referrerWallet:n.r}),!0):!1}function b(t,n){let r=e();return!r&&!n?null:{v:2,m:t,t:Math.floor(Date.now()/1e3),...r?{c:r}:{},...n?{w:n}:{}}}function x(t,n){return s(t)?t.w&&n?.wallet?r(t.w,n.wallet):t.c?e()===t.c:!1:a(t)&&n?.wallet?r(t.r,n.wallet):!1}function S(e,{walletStatus:n,frakContext:r,options:i}){if(!r)return`no-referrer`;if(x(r,n))return`self-referral`;if(!y(e,r,n))return`no-referrer`;let a=s(r)?r.m:i?.merchantId,o=i?.alwaysAppendUrl&&a?b(a,n?.wallet):null;return c.replaceUrl({url:window.location?.href,context:o}),t(e,`user_referred_completed`,{status:`success`}),`success`}async function C(e,{options:t}={}){let n=c.parse({url:window.location.href}),r=await D(e);try{return S(e,{walletStatus:r,frakContext:n,options:t})}catch(e){console.warn(`Error processing referral`,{error:e})}}const w=`frak:referral-success`;async function T(e){try{await C(e)===`success`&&window.dispatchEvent(new Event(w))}catch(e){console.warn(`[Frak] Referral setup failed`,e)}}async function E(t){if(typeof window>`u`){console.warn(`[Frak] No window found, can't track purchase`);return}let n=window.sessionStorage.getItem(`frak-wallet-interaction-token`),r=e();if(!n&&!r){console.warn(`[Frak] No identity found, skipping purchase check`);return}let a=t.merchantId??await o.resolveMerchantId();if(!a){console.warn(`[Frak] No merchant id found, skipping purchase check`);return}let s={Accept:`application/json`,"Content-Type":`application/json`};n&&(s[`x-wallet-sdk-auth`]=n),r&&(s[`x-frak-client-id`]=r);let c=i();await fetch(`${c}/user/track/purchase`,{method:`POST`,headers:s,body:JSON.stringify({customerId:t.customerId,orderId:t.orderId,token:t.token,merchantId:a})})}function D(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(O(e,t),t));let n=new l,r=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},i=>{O(e,i),t(i),r||=(n.resolve(i),!0)}),n.promise}function O(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?(window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken),p(t.interactionToken)):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function k(e,{metadata:t,login:n}){return A(e,{steps:{login:n??{}},metadata:t})}function A(e,t){function n(n){return A(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return A(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return A(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function a(n,r){return n&&(t.metadata=n(t.metadata??{})),await d(e,t,r)}return{params:t,sendTx:n,reward:r,sharing:i,display:a}}async function j(e,{tx:t,metadata:n}){return(await d(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}function M(e=96){let t=Math.ceil(e/2),n=``;if(typeof crypto<`u`&&crypto.getRandomValues){let e=new Uint8Array(t);crypto.getRandomValues(e);for(let t=0;t<e.length;t++)n+=e[t].toString(16).padStart(2,`0`)}else for(let e=0;e<t;e++)n+=(Math.random()*256|0).toString(16).padStart(2,`0`);return n.substring(0,e)}async function N(e,{siwe:t,metadata:n}){let r=e.config?.domain??window.location.host,i=t?.statement??`I confirm that I want to use my Frak wallet on: ${e.config.metadata.name}`;return(await d(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:i,nonce:t?.nonce??M(),uri:t?.uri??`https://${r}`,version:t?.version??`1`,domain:r}}}})).siweAuthenticate}export{d as _,E as a,C as c,_ as d,g as f,f as g,p as h,D as i,S as l,m,j as n,w as o,h as p,k as r,T as s,N as t,v as u,u as v};
|
package/dist/src-BupmzjlU.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_ as e,d as t,h as n,m as r,p as i}from"./frakContext-CTKalP6g.js";import{Deferred as a,FrakRpcError as o,RpcErrorCodes as s,createRpcClient as c,jsonDecode as l}from"@frak-labs/frame-connector";import{OpenPanel as u}from"@openpanel/web";const d=`nexus-wallet-backup`,f=`frakwallet://`;function p(e,t){if(typeof window>`u`)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`))}function m(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}const h=f.replace(`://`,``);function g(e){return`intent://${e.slice(13)}#Intent;scheme=${h};end`}function _(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=m()&&v(e)?g(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function v(e){return e.startsWith(f)}const y={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 b({walletBaseUrl:t,config:n}){let i=document.querySelector(`#frak-wallet`);i&&i.remove();let a=document.createElement(`iframe`);a.id=y.id,a.name=y.name,a.allow=y.allow,a.style.zIndex=y.style.zIndex.toString(),x({iframe:a,isVisible:!1});let o=n?.walletUrl??t??`https://wallet.frak.id`,s=e();return C(o),C(r(o)),a.src=`${o}/listener?clientId=${encodeURIComponent(s)}`,new Promise(e=>{a.addEventListener(`load`,()=>e(a)),document.body.appendChild(a)})}function x({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 S(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 C(e){if(!(typeof document>`u`))try{let t=new URL(e).origin,n=`link[rel="preconnect"][data-frak-preconnect="${t}"]`;if(document.head.querySelector(n))return;let r=document.createElement(`link`);r.rel=`preconnect`,r.href=t,r.crossOrigin=``,r.dataset.frakPreconnect=t,document.head.appendChild(r)}catch{}}const w=(()=>{if(typeof navigator>`u`)return!1;let e=navigator.userAgent;if(!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1))return!1;let t=e.toLowerCase();return t.includes(`instagram`)||t.includes(`fban`)||t.includes(`fbav`)||t.includes(`facebook`)})();function T(e){e?localStorage.setItem(d,e):localStorage.removeItem(d)}function E(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=k(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function D(e){let t=new URL(window.location.href);e&&t.searchParams.set(`fmt`,e);let n=t.protocol===`http:`?`x-safari-http`:`x-safari-https`;window.location.href=`${n}://${t.host}${t.pathname}${t.search}${t.hash}`}function O(e){return e.includes(`/common/social`)}function k(e,t){if(!t)return e;try{let n=new URL(e);return n.searchParams.set(`fmt`,t),n.toString()}catch{return`${e}${e.includes(`?`)?`&`:`?`}fmt=${encodeURIComponent(t)}`}}function A(e,t,n,r,i){if(i){let e=E(t,r);window.open(e,`_blank`);return}if(v(t)){let i=E(t,r);_(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(w&&O(t))D(r);else{let e=E(t,r);window.location.href=e}}function j({iframe:e,targetOrigin:t}){let n=new a;return{handleEvent:r=>{if(!(`iframeLifecycle`in r))return;let{iframeLifecycle:i,data:a}=r;switch(i){case`connected`:n.resolve(!0);break;case`do-backup`:T(a.backup);break;case`remove-backup`:localStorage.removeItem(d);break;case`show`:case`hide`:x({iframe:e,isVisible:i===`show`});break;case`redirect`:A(e,a.baseRedirectUrl,t,a.mergeToken,a.openInNewTab);break}},isConnected:n.promise}}function M({config:t,iframe:r}){let l=t?.walletUrl??`https://wallet.frak.id`,d=typeof navigator<`u`?navigator.language?.split(`-`)[0]:void 0,f=t.metadata.lang??(d===`en`||d===`fr`?d:void 0),p=t.domain??(typeof window<`u`?window.location.hostname:``);i.setCacheScope(p,f),i.reset();let m=i.isCacheFresh?void 0:i.resolve(t.domain,t.walletUrl,f),h=j({iframe:r,targetOrigin:l}),g=new a,_=Date.now();if(!r.contentWindow)throw new o(s.configError,`The iframe does not have a content window`);let v=c({emittingTransport:r.contentWindow,listeningTransport:window,targetOrigin:l,middleware:[{async onRequest(e,t){if(!await h.isConnected)throw new o(s.clientNotConnected,`The iframe provider isn't connected yet`);return await g.promise,t}}],lifecycleHandlers:{iframeLifecycle:(e,t)=>{h.handleEvent(e)}}}),y=N(v,h),b=async()=>{y(),v.cleanup(),r.remove(),n(),i.clearCache(),i.reset()},x;{console.log(`[Frak SDK] Initializing OpenPanel`),x=new u({apiUrl:`https://op-api.gcp.frak.id`,clientId:`f305d11d-b93b-487c-80d4-92deb7903e98`,trackScreenViews:!0,trackOutgoingLinks:!0,trackAttributes:!1,filter:({type:t,payload:n})=>(t!==`track`||!n?.properties||`sdkVersion`in n.properties||(n.properties={...n.properties,sdkVersion:`1.1.1`,userAnonymousClientId:e()}),!0)}),x.setGlobalProperties({sdkVersion:`1.1.1`,userAnonymousClientId:e()}),x.init(),x.track(`sdk_initialized`,{sdkVersion:`1.1.1`});let t=!1,n=setTimeout(()=>{t||(t=!0,x?.track(`sdk_iframe_handshake_failed`,{reason:`timeout`}))},3e4);h.isConnected.then(()=>{t||(t=!0,clearTimeout(n),x?.track(`sdk_iframe_connected`,{handshake_duration_ms:Date.now()-_}))}).catch(()=>{t||(t=!0,clearTimeout(n),x?.track(`sdk_iframe_handshake_failed`,{reason:`unknown`}))})}let S=P({config:t,rpcClient:v,lifecycleManager:h,configPromise:m,contextSent:g,openPanel:x}).then(()=>{}).catch(e=>{throw g.reject(e),e});return{config:t,waitForConnection:h.isConnected,waitForSetup:S,request:v.request,listenerRequest:v.listen,destroy:b,openPanel:x}}function N(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,250),r=setTimeout(()=>{o(),console.log(`Heartbeat timeout: connection failed`)},3e4),await t.isConnected,o()}function o(){n&&clearInterval(n),r&&clearTimeout(r)}return a(),o}async function P({config:t,rpcClient:n,lifecycleManager:r,configPromise:a,contextSent:o,openPanel:s}){await r.isConnected,p(n,r.isConnected);let c=new URL(window.location.href),l=c.searchParams.get(`fmt`)??void 0;l&&(c.searchParams.delete(`fmt`),window.history.replaceState({},``,c.toString()));let u=e=>{let n=e?.merchantId??t.metadata.merchantId??``,r=e?.domain??``,a=e?.allowedDomains??[],o=e?.sdkConfig,s=o?.attribution||t.attribution?{...t.attribution,...o?.attribution}:void 0;i.setConfig(o?{isResolved:!0,merchantId:n,domain:r,allowedDomains:a,hasRawSdkConfig:!0,name:o.name??t.metadata.name,logoUrl:o.logoUrl??t.metadata.logoUrl,homepageLink:o.homepageLink??t.metadata.homepageLink,lang:o.lang??t.metadata.lang,currency:o.currency??t.metadata.currency,hidden:o.hidden,css:o.css,translations:o.translations,placements:o.placements,components:o.components,attribution:s}:{isResolved:!0,merchantId:n,domain:r,allowedDomains:a,name:t.metadata.name,logoUrl:t.metadata.logoUrl,homepageLink:t.metadata.homepageLink,lang:t.metadata.lang,currency:t.metadata.currency,attribution:s})},f=!1,m=t=>{let r=f?void 0:l;f=!0;let i=t.hasRawSdkConfig?{name:t.name,logoUrl:t.logoUrl,homepageLink:t.homepageLink,lang:t.lang,currency:t.currency,hidden:t.hidden,css:t.css,translations:t.translations,placements:t.placements,attribution:t.attribution}:t.attribution?{attribution:t.attribution}:void 0,a=e();if(s){let e=s.global??{};s.setGlobalProperties({...e,merchantId:t.merchantId,domain:t.domain??``})}n.sendLifecycle({clientLifecycle:`resolved-config`,data:{merchantId:t.merchantId,domain:t.domain??``,allowedDomains:t.allowedDomains??[],sourceUrl:window.location.href,...a&&{sdkAnonymousId:a},...r&&{pendingMergeToken:r},...i&&{sdkConfig:i}}})};i.isResolved&&(m(i.getConfig()),o.resolve()),a&&(u(await a),m(i.getConfig()),o.resolve());async function h(){let e=t.customizations?.css;e&&n.sendLifecycle({clientLifecycle:`modal-css`,data:{cssLink:e}})}async function g(){let e=t.customizations?.i18n;e&&n.sendLifecycle({clientLifecycle:`modal-i18n`,data:{i18n:e}})}async function _(){if(typeof window>`u`)return;let e=window.localStorage.getItem(d);e&&n.sendLifecycle({clientLifecycle:`restore-backup`,data:{backup:e}})}(await Promise.allSettled([h(),g(),_()])).some(e=>e.status===`rejected`)&&s?.track(`sdk_iframe_handshake_failed`,{reason:`asset_push`})}function F(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent;return!!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1)}const I=F();function L(){return typeof navigator>`u`?!1:I?!0:/Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}function R(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent.toLowerCase();return e.includes(`instagram`)||e.includes(`fban`)||e.includes(`fbav`)||e.includes(`facebook`)}const z=R();function B(e){I&&e.startsWith(`https://`)?window.location.href=`x-safari-https://${e.slice(8)}`:I&&e.startsWith(`http://`)?window.location.href=`x-safari-http://${e.slice(7)}`:window.location.href=`https://backend.frak.id/common/social?u=${encodeURIComponent(e)}`}function V(e){return l(t(e))}const H={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function U(e){return e&&e in H?e:`eur`}function W(e){return e?H[e]??H.eur:H.eur}function G(e,t){let n=W(t),r=U(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function K(e){return e?`${e}Amount`:`eurAmount`}async function q({config:e}){let t=J(e),n=await b({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=M({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function J(e){let t=U(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}function Y({perCall:e,defaults:t,productUtmContent:n}){if(e===null)return;let r=e!==void 0,i=t!==void 0&&Object.keys(t).length>0;if(!r&&!i&&!(n!==void 0&&n!==``))return;let a={...t,...e??{}},o=n??e?.utmContent;return o!==void 0&&o!==``?a.utmContent=o:delete a.utmContent,a}export{U as a,z as c,M as d,y as f,f as h,G as i,L as l,_ as m,q as n,V as o,S as p,K as r,I as s,Y as t,B as u};
|
package/dist/src-VC21uAq0.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=require(`./frakContext-_b-_uwgd.cjs`);let t=require(`@frak-labs/frame-connector`),n=require(`@openpanel/web`);const r=`nexus-wallet-backup`,i=`frakwallet://`;function a(e,t){if(typeof window>`u`)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`))}function o(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}const s=i.replace(`://`,``);function c(e){return`intent://${e.slice(13)}#Intent;scheme=${s};end`}function l(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=o()&&u(e)?c(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function u(e){return e.startsWith(i)}const d={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 f({walletBaseUrl:t,config:n}){let r=document.querySelector(`#frak-wallet`);r&&r.remove();let i=document.createElement(`iframe`);i.id=d.id,i.name=d.name,i.allow=d.allow,i.style.zIndex=d.style.zIndex.toString(),p({iframe:i,isVisible:!1});let a=n?.walletUrl??t??`https://wallet.frak.id`,o=e._();return h(a),h(e.m(a)),i.src=`${a}/listener?clientId=${encodeURIComponent(o)}`,new Promise(e=>{i.addEventListener(`load`,()=>e(i)),document.body.appendChild(i)})}function p({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 m(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(e){if(!(typeof document>`u`))try{let t=new URL(e).origin,n=`link[rel="preconnect"][data-frak-preconnect="${t}"]`;if(document.head.querySelector(n))return;let r=document.createElement(`link`);r.rel=`preconnect`,r.href=t,r.crossOrigin=``,r.dataset.frakPreconnect=t,document.head.appendChild(r)}catch{}}const g=(()=>{if(typeof navigator>`u`)return!1;let e=navigator.userAgent;if(!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1))return!1;let t=e.toLowerCase();return t.includes(`instagram`)||t.includes(`fban`)||t.includes(`fbav`)||t.includes(`facebook`)})();function _(e){e?localStorage.setItem(r,e):localStorage.removeItem(r)}function v(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=x(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function y(e){let t=new URL(window.location.href);e&&t.searchParams.set(`fmt`,e);let n=t.protocol===`http:`?`x-safari-http`:`x-safari-https`;window.location.href=`${n}://${t.host}${t.pathname}${t.search}${t.hash}`}function b(e){return e.includes(`/common/social`)}function x(e,t){if(!t)return e;try{let n=new URL(e);return n.searchParams.set(`fmt`,t),n.toString()}catch{return`${e}${e.includes(`?`)?`&`:`?`}fmt=${encodeURIComponent(t)}`}}function S(e,t,n,r,i){if(i){let e=v(t,r);window.open(e,`_blank`);return}if(u(t)){let i=v(t,r);l(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(g&&b(t))y(r);else{let e=v(t,r);window.location.href=e}}function C({iframe:e,targetOrigin:n}){let i=new t.Deferred;return{handleEvent:t=>{if(!(`iframeLifecycle`in t))return;let{iframeLifecycle:a,data:o}=t;switch(a){case`connected`:i.resolve(!0);break;case`do-backup`:_(o.backup);break;case`remove-backup`:localStorage.removeItem(r);break;case`show`:case`hide`:p({iframe:e,isVisible:a===`show`});break;case`redirect`:S(e,o.baseRedirectUrl,n,o.mergeToken,o.openInNewTab);break}},isConnected:i.promise}}function w({config:r,iframe:i}){let a=r?.walletUrl??`https://wallet.frak.id`,o=typeof navigator<`u`?navigator.language?.split(`-`)[0]:void 0,s=r.metadata.lang??(o===`en`||o===`fr`?o:void 0),c=r.domain??(typeof window<`u`?window.location.hostname:``);e.p.setCacheScope(c,s),e.p.reset();let l=e.p.isCacheFresh?void 0:e.p.resolve(r.domain,r.walletUrl,s),u=C({iframe:i,targetOrigin:a}),d=new t.Deferred,f=Date.now();if(!i.contentWindow)throw new t.FrakRpcError(t.RpcErrorCodes.configError,`The iframe does not have a content window`);let p=(0,t.createRpcClient)({emittingTransport:i.contentWindow,listeningTransport:window,targetOrigin:a,middleware:[{async onRequest(e,n){if(!await u.isConnected)throw new t.FrakRpcError(t.RpcErrorCodes.clientNotConnected,`The iframe provider isn't connected yet`);return await d.promise,n}}],lifecycleHandlers:{iframeLifecycle:(e,t)=>{u.handleEvent(e)}}}),m=T(p,u),h=async()=>{m(),p.cleanup(),i.remove(),e.h(),e.p.clearCache(),e.p.reset()},g;{console.log(`[Frak SDK] Initializing OpenPanel`),g=new n.OpenPanel({apiUrl:`https://op-api.gcp.frak.id`,clientId:`f305d11d-b93b-487c-80d4-92deb7903e98`,trackScreenViews:!0,trackOutgoingLinks:!0,trackAttributes:!1,filter:({type:t,payload:n})=>(t!==`track`||!n?.properties||`sdkVersion`in n.properties||(n.properties={...n.properties,sdkVersion:`1.1.1`,userAnonymousClientId:e._()}),!0)}),g.setGlobalProperties({sdkVersion:`1.1.1`,userAnonymousClientId:e._()}),g.init(),g.track(`sdk_initialized`,{sdkVersion:`1.1.1`});let t=!1,r=setTimeout(()=>{t||(t=!0,g?.track(`sdk_iframe_handshake_failed`,{reason:`timeout`}))},3e4);u.isConnected.then(()=>{t||(t=!0,clearTimeout(r),g?.track(`sdk_iframe_connected`,{handshake_duration_ms:Date.now()-f}))}).catch(()=>{t||(t=!0,clearTimeout(r),g?.track(`sdk_iframe_handshake_failed`,{reason:`unknown`}))})}let _=E({config:r,rpcClient:p,lifecycleManager:u,configPromise:l,contextSent:d,openPanel:g}).then(()=>{}).catch(e=>{throw d.reject(e),e});return{config:r,waitForConnection:u.isConnected,waitForSetup:_,request:p.request,listenerRequest:p.listen,destroy:h,openPanel:g}}function T(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,250),r=setTimeout(()=>{o(),console.log(`Heartbeat timeout: connection failed`)},3e4),await t.isConnected,o()}function o(){n&&clearInterval(n),r&&clearTimeout(r)}return a(),o}async function E({config:t,rpcClient:n,lifecycleManager:i,configPromise:o,contextSent:s,openPanel:c}){await i.isConnected,a(n,i.isConnected);let l=new URL(window.location.href),u=l.searchParams.get(`fmt`)??void 0;u&&(l.searchParams.delete(`fmt`),window.history.replaceState({},``,l.toString()));let d=n=>{let r=n?.merchantId??t.metadata.merchantId??``,i=n?.domain??``,a=n?.allowedDomains??[],o=n?.sdkConfig,s=o?.attribution||t.attribution?{...t.attribution,...o?.attribution}:void 0;e.p.setConfig(o?{isResolved:!0,merchantId:r,domain:i,allowedDomains:a,hasRawSdkConfig:!0,name:o.name??t.metadata.name,logoUrl:o.logoUrl??t.metadata.logoUrl,homepageLink:o.homepageLink??t.metadata.homepageLink,lang:o.lang??t.metadata.lang,currency:o.currency??t.metadata.currency,hidden:o.hidden,css:o.css,translations:o.translations,placements:o.placements,components:o.components,attribution:s}:{isResolved:!0,merchantId:r,domain:i,allowedDomains:a,name:t.metadata.name,logoUrl:t.metadata.logoUrl,homepageLink:t.metadata.homepageLink,lang:t.metadata.lang,currency:t.metadata.currency,attribution:s})},f=!1,p=t=>{let r=f?void 0:u;f=!0;let i=t.hasRawSdkConfig?{name:t.name,logoUrl:t.logoUrl,homepageLink:t.homepageLink,lang:t.lang,currency:t.currency,hidden:t.hidden,css:t.css,translations:t.translations,placements:t.placements,attribution:t.attribution}:t.attribution?{attribution:t.attribution}:void 0,a=e._();if(c){let e=c.global??{};c.setGlobalProperties({...e,merchantId:t.merchantId,domain:t.domain??``})}n.sendLifecycle({clientLifecycle:`resolved-config`,data:{merchantId:t.merchantId,domain:t.domain??``,allowedDomains:t.allowedDomains??[],sourceUrl:window.location.href,...a&&{sdkAnonymousId:a},...r&&{pendingMergeToken:r},...i&&{sdkConfig:i}}})};e.p.isResolved&&(p(e.p.getConfig()),s.resolve()),o&&(d(await o),p(e.p.getConfig()),s.resolve());async function m(){let e=t.customizations?.css;e&&n.sendLifecycle({clientLifecycle:`modal-css`,data:{cssLink:e}})}async function h(){let e=t.customizations?.i18n;e&&n.sendLifecycle({clientLifecycle:`modal-i18n`,data:{i18n:e}})}async function g(){if(typeof window>`u`)return;let e=window.localStorage.getItem(r);e&&n.sendLifecycle({clientLifecycle:`restore-backup`,data:{backup:e}})}(await Promise.allSettled([m(),h(),g()])).some(e=>e.status===`rejected`)&&c?.track(`sdk_iframe_handshake_failed`,{reason:`asset_push`})}function D(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent;return!!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1)}const O=D();function k(){return typeof navigator>`u`?!1:O?!0:/Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}function A(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent.toLowerCase();return e.includes(`instagram`)||e.includes(`fban`)||e.includes(`fbav`)||e.includes(`facebook`)}const j=A();function M(e){O&&e.startsWith(`https://`)?window.location.href=`x-safari-https://${e.slice(8)}`:O&&e.startsWith(`http://`)?window.location.href=`x-safari-http://${e.slice(7)}`:window.location.href=`https://backend.frak.id/common/social?u=${encodeURIComponent(e)}`}function N(n){return(0,t.jsonDecode)(e.d(n))}const P={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function F(e){return e&&e in P?e:`eur`}function I(e){return e?P[e]??P.eur:P.eur}function L(e,t){let n=I(t),r=F(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function R(e){return e?`${e}Amount`:`eurAmount`}async function z({config:e}){let t=B(e),n=await f({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=w({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function B(e){let t=F(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}function V({perCall:e,defaults:t,productUtmContent:n}){if(e===null)return;let r=e!==void 0,i=t!==void 0&&Object.keys(t).length>0;if(!r&&!i&&!(n!==void 0&&n!==``))return;let a={...t,...e??{}},o=n??e?.utmContent;return o!==void 0&&o!==``?a.utmContent=o:delete a.utmContent,a}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return M}});
|