@frak-labs/core-sdk 0.2.1-beta.b38eef2e → 0.2.1-beta.d04602ec
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/README.md +1 -2
- package/cdn/bundle.js +55 -3
- 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/{computeLegacyProductId-CCAZvLa5.d.cts → computeLegacyProductId-fKvxbC4k.d.ts} +91 -37
- package/dist/{computeLegacyProductId-b5cUWdAm.d.ts → computeLegacyProductId-rYIvY4c3.d.cts} +91 -37
- 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-B0g7-807.d.cts → openSso-CMZM06uR.d.ts} +258 -46
- package/dist/{openSso-CMzwvaCa.d.ts → openSso-CebB8mFv.d.cts} +258 -46
- package/dist/setupClient-B_XMB52l.cjs +13 -0
- package/dist/setupClient-jYx-fbxB.js +13 -0
- package/dist/siweAuthenticate-CWcVvP-G.cjs +1 -0
- package/dist/siweAuthenticate-DQfdb5UQ.js +1 -0
- package/dist/{siweAuthenticate-CnCZ7mok.d.ts → siweAuthenticate-Dc_Yg9Bg.d.cts} +102 -8
- package/dist/{siweAuthenticate-CVigMOxz.d.cts → siweAuthenticate-Ddhl-o4N.d.ts} +102 -8
- package/dist/trackEvent-Ce1XlsIE.js +1 -0
- package/dist/trackEvent-CvbJTTqA.cjs +1 -0
- package/package.json +8 -8
- package/src/actions/displayEmbeddedWallet.ts +6 -2
- package/src/actions/displayModal.ts +6 -2
- package/src/actions/displaySharingPage.ts +49 -0
- package/src/actions/ensureIdentity.ts +2 -2
- package/src/actions/getMerchantInformation.test.ts +13 -1
- package/src/actions/getMerchantInformation.ts +20 -5
- package/src/actions/getUserReferralStatus.ts +42 -0
- package/src/actions/index.ts +7 -1
- package/src/actions/referral/setupReferral.test.ts +79 -0
- package/src/actions/referral/setupReferral.ts +32 -0
- package/src/actions/trackPurchaseStatus.test.ts +32 -20
- package/src/actions/trackPurchaseStatus.ts +3 -5
- package/src/actions/wrapper/modalBuilder.test.ts +4 -2
- package/src/actions/wrapper/modalBuilder.ts +6 -8
- package/src/clients/createIFrameFrakClient.ts +148 -25
- package/src/clients/transports/iframeLifecycleManager.test.ts +0 -80
- package/src/clients/transports/iframeLifecycleManager.ts +0 -44
- package/src/index.ts +17 -4
- package/src/types/config.ts +10 -3
- package/src/types/index.ts +13 -1
- package/src/types/lifecycle/client.ts +22 -27
- package/src/types/lifecycle/iframe.ts +0 -8
- package/src/types/resolvedConfig.ts +122 -0
- package/src/types/rpc/displaySharingPage.ts +77 -0
- package/src/types/rpc/interaction.ts +4 -0
- package/src/types/rpc/userReferralStatus.ts +20 -0
- package/src/types/rpc.ts +42 -5
- package/src/utils/backendUrl.test.ts +2 -2
- package/src/utils/backendUrl.ts +1 -1
- package/src/utils/cache/index.ts +7 -0
- package/src/utils/cache/lruMap.test.ts +55 -0
- package/src/utils/cache/lruMap.ts +38 -0
- package/src/utils/cache/withCache.test.ts +162 -0
- package/src/utils/cache/withCache.ts +105 -0
- package/src/utils/inAppBrowser.ts +60 -0
- package/src/utils/index.ts +6 -4
- package/src/utils/sdkConfigStore.test.ts +405 -0
- package/src/utils/sdkConfigStore.ts +263 -0
- package/src/utils/sso.ts +3 -7
- package/dist/setupClient-CqTHGvVa.cjs +0 -13
- package/dist/setupClient-DTyvAPgh.js +0 -13
- package/dist/siweAuthenticate-BWmI2_TN.cjs +0 -1
- package/dist/siweAuthenticate-zczqxm0a.js +0 -1
- package/dist/trackEvent-CeLFVzZn.js +0 -1
- package/dist/trackEvent-Ew5r5zfI.cjs +0 -1
- package/src/utils/merchantId.test.ts +0 -653
- package/src/utils/merchantId.ts +0 -143
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Address, Hex } from "viem";
|
|
2
|
-
import { LifecycleMessage, RpcClient } from "@frak-labs/frame-connector";
|
|
3
1
|
import { OpenPanel } from "@openpanel/web";
|
|
2
|
+
import { LifecycleMessage, RpcClient } from "@frak-labs/frame-connector";
|
|
3
|
+
import { Address, Hex } from "viem";
|
|
4
4
|
import { SiweMessage } from "viem/siwe";
|
|
5
5
|
|
|
6
6
|
//#region src/types/config.d.ts
|
|
@@ -31,7 +31,7 @@ type FrakWalletSdkConfig = {
|
|
|
31
31
|
/**
|
|
32
32
|
* Your application name (will be displayed in a few modals and in SSO)
|
|
33
33
|
*/
|
|
34
|
-
name
|
|
34
|
+
name?: string;
|
|
35
35
|
/**
|
|
36
36
|
* Your merchant ID from the Frak dashboard (UUID format)
|
|
37
37
|
* Used for referral tracking and analytics
|
|
@@ -75,6 +75,13 @@ type FrakWalletSdkConfig = {
|
|
|
75
75
|
* @defaultValue window.location.host
|
|
76
76
|
*/
|
|
77
77
|
domain?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Wait for backend config before rendering components.
|
|
80
|
+
* When true (default), components show a spinner until backend config is resolved.
|
|
81
|
+
* When false, components render immediately with SDK static config / HTML attributes.
|
|
82
|
+
* @defaultValue true
|
|
83
|
+
*/
|
|
84
|
+
waitForBackendConfig?: boolean;
|
|
78
85
|
};
|
|
79
86
|
/**
|
|
80
87
|
* Custom i18n configuration for the modal
|
|
@@ -111,19 +118,115 @@ type FrakWalletSdkConfig = {
|
|
|
111
118
|
*/
|
|
112
119
|
type I18nConfig = Record<Language, LocalizedI18nConfig> | LocalizedI18nConfig;
|
|
113
120
|
/**
|
|
114
|
-
* A localized i18n config
|
|
121
|
+
* A localized i18n config (inline objects only — URL-based i18n removed)
|
|
115
122
|
* @category Config
|
|
116
123
|
*/
|
|
117
|
-
type LocalizedI18nConfig =
|
|
124
|
+
type LocalizedI18nConfig = {
|
|
118
125
|
[key: string]: string;
|
|
119
126
|
};
|
|
120
127
|
//#endregion
|
|
128
|
+
//#region src/types/resolvedConfig.d.ts
|
|
129
|
+
/**
|
|
130
|
+
* Response from the merchant resolve endpoint
|
|
131
|
+
* @category Config
|
|
132
|
+
*/
|
|
133
|
+
type MerchantConfigResponse = {
|
|
134
|
+
merchantId: string;
|
|
135
|
+
name: string;
|
|
136
|
+
domain: string;
|
|
137
|
+
allowedDomains: string[];
|
|
138
|
+
sdkConfig?: ResolvedSdkConfig;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Resolved placement config from backend
|
|
142
|
+
* Translations already flattened: default + lang-specific merged into one record
|
|
143
|
+
* @category Config
|
|
144
|
+
*/
|
|
145
|
+
type ResolvedPlacement = {
|
|
146
|
+
/** Per-component configuration within this placement */components?: {
|
|
147
|
+
buttonShare?: {
|
|
148
|
+
text?: string;
|
|
149
|
+
noRewardText?: string;
|
|
150
|
+
clickAction?: "embedded-wallet" | "share-modal" | "sharing-page";
|
|
151
|
+
useReward?: boolean;
|
|
152
|
+
css?: string;
|
|
153
|
+
};
|
|
154
|
+
buttonWallet?: {
|
|
155
|
+
position?: "right" | "left";
|
|
156
|
+
css?: string;
|
|
157
|
+
};
|
|
158
|
+
openInApp?: {
|
|
159
|
+
text?: string;
|
|
160
|
+
css?: string;
|
|
161
|
+
};
|
|
162
|
+
postPurchase?: {
|
|
163
|
+
refereeText?: string;
|
|
164
|
+
refereeNoRewardText?: string;
|
|
165
|
+
referrerText?: string;
|
|
166
|
+
referrerNoRewardText?: string;
|
|
167
|
+
ctaText?: string;
|
|
168
|
+
ctaNoRewardText?: string;
|
|
169
|
+
css?: string;
|
|
170
|
+
};
|
|
171
|
+
banner?: {
|
|
172
|
+
referralTitle?: string;
|
|
173
|
+
referralDescription?: string;
|
|
174
|
+
referralCta?: string;
|
|
175
|
+
inappTitle?: string;
|
|
176
|
+
inappDescription?: string;
|
|
177
|
+
inappCta?: string;
|
|
178
|
+
css?: string;
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
targetInteraction?: string; /** Already flattened: default + lang-specific merged into one record */
|
|
182
|
+
translations?: Record<string, string>; /** Global placement CSS (applied to modals/listener) */
|
|
183
|
+
css?: string;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Resolved SDK config from backend `/resolve` endpoint
|
|
187
|
+
* Language resolution and translation merging already applied
|
|
188
|
+
* @category Config
|
|
189
|
+
*/
|
|
190
|
+
type ResolvedSdkConfig = {
|
|
191
|
+
name?: string;
|
|
192
|
+
logoUrl?: string;
|
|
193
|
+
homepageLink?: string;
|
|
194
|
+
currency?: Currency;
|
|
195
|
+
lang?: Language; /** When true, all SDK components should be hidden */
|
|
196
|
+
hidden?: boolean;
|
|
197
|
+
css?: string;
|
|
198
|
+
translations?: Record<string, string>;
|
|
199
|
+
placements?: Record<string, ResolvedPlacement>;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Internal SDK config store state
|
|
203
|
+
* Merged config: backend > SDK static > defaults
|
|
204
|
+
* Components subscribe to this reactively
|
|
205
|
+
* @category Config
|
|
206
|
+
*/
|
|
207
|
+
type SdkResolvedConfig = {
|
|
208
|
+
/** Whether the backend config has been resolved */isResolved: boolean; /** Merchant ID from resolution */
|
|
209
|
+
merchantId: string; /** Domain returned by the resolve endpoint */
|
|
210
|
+
domain?: string; /** Domains allowed for this merchant (used by iframe trust check) */
|
|
211
|
+
allowedDomains?: string[]; /** Whether the resolve returned a backend sdkConfig object */
|
|
212
|
+
hasRawSdkConfig?: boolean; /** Merged metadata fields */
|
|
213
|
+
name?: string;
|
|
214
|
+
logoUrl?: string;
|
|
215
|
+
homepageLink?: string;
|
|
216
|
+
lang?: Language;
|
|
217
|
+
currency?: Currency; /** When true, all SDK components should be hidden */
|
|
218
|
+
hidden?: boolean; /** Global CSS from backend config (passed to iframe) */
|
|
219
|
+
css?: string; /** Global translations (for reference / component fallback) */
|
|
220
|
+
translations?: Record<string, string>; /** Named placements (keyed by placement ID) */
|
|
221
|
+
placements?: Record<string, ResolvedPlacement>;
|
|
222
|
+
};
|
|
223
|
+
//#endregion
|
|
121
224
|
//#region src/types/lifecycle/client.d.ts
|
|
122
225
|
/**
|
|
123
226
|
* Event related to the iframe lifecycle
|
|
124
227
|
* @ignore
|
|
125
228
|
*/
|
|
126
|
-
type ClientLifecycleEvent = CustomCssEvent | CustomI18nEvent | RestoreBackupEvent | HearbeatEvent |
|
|
229
|
+
type ClientLifecycleEvent = CustomCssEvent | CustomI18nEvent | RestoreBackupEvent | HearbeatEvent | SsoRedirectCompleteEvent | DeepLinkFailedEvent | ResolvedConfigEvent;
|
|
127
230
|
type CustomCssEvent = {
|
|
128
231
|
clientLifecycle: "modal-css";
|
|
129
232
|
data: {
|
|
@@ -146,30 +249,6 @@ type HearbeatEvent = {
|
|
|
146
249
|
clientLifecycle: "heartbeat";
|
|
147
250
|
data?: never;
|
|
148
251
|
};
|
|
149
|
-
type HandshakeResponse = {
|
|
150
|
-
clientLifecycle: "handshake-response";
|
|
151
|
-
data: {
|
|
152
|
-
token: string;
|
|
153
|
-
currentUrl: string;
|
|
154
|
-
/**
|
|
155
|
-
* Pending merge token extracted from URL (?fmt= parameter)
|
|
156
|
-
* When present, listener should execute identity merge in background
|
|
157
|
-
* URL is cleaned after handshake response is sent
|
|
158
|
-
*/
|
|
159
|
-
pendingMergeToken?: string;
|
|
160
|
-
/**
|
|
161
|
-
* Client ID for identity tracking (belt & suspenders fallback)
|
|
162
|
-
* Primary delivery is via iframe URL query param; handshake is backup for SSR
|
|
163
|
-
*/
|
|
164
|
-
clientId?: string;
|
|
165
|
-
/**
|
|
166
|
-
* Explicit domain from SDK config (FrakWalletSdkConfig.domain)
|
|
167
|
-
* When present, listener should prefer this over URL-derived domain
|
|
168
|
-
* for merchant resolution (handles proxied/tunneled environments)
|
|
169
|
-
*/
|
|
170
|
-
configDomain?: string;
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
252
|
type SsoRedirectCompleteEvent = {
|
|
174
253
|
clientLifecycle: "sso-redirect-complete";
|
|
175
254
|
data: {
|
|
@@ -182,6 +261,21 @@ type DeepLinkFailedEvent = {
|
|
|
182
261
|
originalUrl: string;
|
|
183
262
|
};
|
|
184
263
|
};
|
|
264
|
+
type ResolvedConfigEvent = {
|
|
265
|
+
clientLifecycle: "resolved-config";
|
|
266
|
+
data: {
|
|
267
|
+
merchantId: string; /** The domain the backend resolved this config for */
|
|
268
|
+
domain: string; /** All domains registered for this merchant (for domain proof) */
|
|
269
|
+
allowedDomains: string[]; /** Full URL of the parent page (for interaction tracking) */
|
|
270
|
+
sourceUrl: string;
|
|
271
|
+
/**
|
|
272
|
+
* Pending merge token extracted from URL (?fmt= parameter).
|
|
273
|
+
* When present, listener should execute identity merge in background.
|
|
274
|
+
*/
|
|
275
|
+
pendingMergeToken?: string;
|
|
276
|
+
sdkConfig?: ResolvedSdkConfig;
|
|
277
|
+
};
|
|
278
|
+
};
|
|
185
279
|
//#endregion
|
|
186
280
|
//#region src/types/lifecycle/iframe.d.ts
|
|
187
281
|
/**
|
|
@@ -191,19 +285,13 @@ type DeepLinkFailedEvent = {
|
|
|
191
285
|
type IFrameLifecycleEvent = {
|
|
192
286
|
iframeLifecycle: "connected" | "show" | "hide" | "remove-backup";
|
|
193
287
|
data?: never;
|
|
194
|
-
} | DoBackupEvent |
|
|
288
|
+
} | DoBackupEvent | RedirectRequestEvent;
|
|
195
289
|
type DoBackupEvent = {
|
|
196
290
|
iframeLifecycle: "do-backup";
|
|
197
291
|
data: {
|
|
198
292
|
backup?: string;
|
|
199
293
|
};
|
|
200
294
|
};
|
|
201
|
-
type HandshakeRequestEvent = {
|
|
202
|
-
iframeLifecycle: "handshake";
|
|
203
|
-
data: {
|
|
204
|
-
token: string;
|
|
205
|
-
};
|
|
206
|
-
};
|
|
207
295
|
type RedirectRequestEvent = {
|
|
208
296
|
iframeLifecycle: "redirect";
|
|
209
297
|
data: {
|
|
@@ -534,6 +622,80 @@ type DisplayModalParamsType<T extends ModalStepTypes[]> = {
|
|
|
534
622
|
metadata?: ModalRpcMetadata;
|
|
535
623
|
};
|
|
536
624
|
//#endregion
|
|
625
|
+
//#region src/types/rpc/displaySharingPage.d.ts
|
|
626
|
+
/**
|
|
627
|
+
* Product information to display on the sharing page
|
|
628
|
+
* @group Sharing Page
|
|
629
|
+
*/
|
|
630
|
+
type SharingPageProduct = {
|
|
631
|
+
/**
|
|
632
|
+
* The product title / name
|
|
633
|
+
*/
|
|
634
|
+
title: string;
|
|
635
|
+
/**
|
|
636
|
+
* Optional product image URL
|
|
637
|
+
*/
|
|
638
|
+
imageUrl?: string;
|
|
639
|
+
};
|
|
640
|
+
/**
|
|
641
|
+
* Parameters to display the sharing page
|
|
642
|
+
* @group Sharing Page
|
|
643
|
+
* @group RPC Schema
|
|
644
|
+
*/
|
|
645
|
+
type DisplaySharingPageParamsType = {
|
|
646
|
+
/**
|
|
647
|
+
* Products to showcase on the sharing page
|
|
648
|
+
* If provided, they will be displayed in a product card section
|
|
649
|
+
*/
|
|
650
|
+
products?: SharingPageProduct[];
|
|
651
|
+
/**
|
|
652
|
+
* Optional link override for sharing
|
|
653
|
+
* If not provided, the sharing link will be generated from the current page URL + merchant context
|
|
654
|
+
*/
|
|
655
|
+
link?: string;
|
|
656
|
+
/**
|
|
657
|
+
* Optional metadata overrides for the sharing page
|
|
658
|
+
*/
|
|
659
|
+
metadata?: {
|
|
660
|
+
/**
|
|
661
|
+
* Logo override for the sharing page header
|
|
662
|
+
*/
|
|
663
|
+
logo?: string;
|
|
664
|
+
/**
|
|
665
|
+
* Link to the homepage of the calling website
|
|
666
|
+
*/
|
|
667
|
+
homepageLink?: string;
|
|
668
|
+
/**
|
|
669
|
+
* The target interaction behind this sharing page
|
|
670
|
+
*/
|
|
671
|
+
targetInteraction?: InteractionTypeKey;
|
|
672
|
+
/**
|
|
673
|
+
* i18n overrides for the sharing page
|
|
674
|
+
*/
|
|
675
|
+
i18n?: I18nConfig;
|
|
676
|
+
};
|
|
677
|
+
};
|
|
678
|
+
/**
|
|
679
|
+
* Result of the sharing page display
|
|
680
|
+
* @group Sharing Page
|
|
681
|
+
* @group RPC Schema
|
|
682
|
+
*/
|
|
683
|
+
type DisplaySharingPageResultType = {
|
|
684
|
+
/**
|
|
685
|
+
* The action the user took
|
|
686
|
+
* - "shared": User used the native share dialog
|
|
687
|
+
* - "copied": User copied the link to clipboard
|
|
688
|
+
* - "dismissed": User dismissed the sharing page without acting
|
|
689
|
+
*/
|
|
690
|
+
action: "shared" | "copied" | "dismissed";
|
|
691
|
+
/**
|
|
692
|
+
* The install URL for the Frak app
|
|
693
|
+
* Can be used as a fallback to redirect the user to the install page
|
|
694
|
+
* from the merchant's top-level page (e.g. via `window.location.href`)
|
|
695
|
+
*/
|
|
696
|
+
installUrl?: string;
|
|
697
|
+
};
|
|
698
|
+
//#endregion
|
|
537
699
|
//#region src/types/rpc/embedded/loggedIn.d.ts
|
|
538
700
|
/**
|
|
539
701
|
* The different type of action we can have on the embedded view (once the user is logged in)
|
|
@@ -691,7 +853,9 @@ type SendInteractionParamsType = {
|
|
|
691
853
|
utmTerm?: string;
|
|
692
854
|
utmContent?: string;
|
|
693
855
|
} | {
|
|
694
|
-
type: "sharing";
|
|
856
|
+
type: "sharing"; /** Epoch seconds timestamp matching the V2 context `t` field embedded in the referral link URL, used for backend correlation */
|
|
857
|
+
sharingTimestamp?: number; /** Merchant order ID linking this sharing event to a purchase (stays server-side, never in URL) */
|
|
858
|
+
purchaseId?: string;
|
|
695
859
|
} | {
|
|
696
860
|
type: "custom";
|
|
697
861
|
customType: string;
|
|
@@ -769,6 +933,28 @@ type GetMerchantInformationReturnType = {
|
|
|
769
933
|
}[];
|
|
770
934
|
};
|
|
771
935
|
//#endregion
|
|
936
|
+
//#region src/types/rpc/userReferralStatus.d.ts
|
|
937
|
+
/**
|
|
938
|
+
* User referral status returned by `frak_getUserReferralStatus`.
|
|
939
|
+
*
|
|
940
|
+
* Generic referral context for the current user on a merchant.
|
|
941
|
+
* Used by components like `<frak-post-purchase>` and `<frak-referred-banner>`
|
|
942
|
+
* to adapt their display based on the user's referral relationship.
|
|
943
|
+
*
|
|
944
|
+
* Returns `null` when the user's identity cannot be resolved
|
|
945
|
+
* (e.g. no clientId and no wallet session).
|
|
946
|
+
*
|
|
947
|
+
* @group RPC Schema
|
|
948
|
+
*/
|
|
949
|
+
type UserReferralStatusType = {
|
|
950
|
+
/**
|
|
951
|
+
* Whether the user was referred to this merchant by someone else.
|
|
952
|
+
*
|
|
953
|
+
* `true` means a referral link exists where this user is the referee.
|
|
954
|
+
*/
|
|
955
|
+
isReferred: boolean;
|
|
956
|
+
};
|
|
957
|
+
//#endregion
|
|
772
958
|
//#region src/types/rpc/walletStatus.d.ts
|
|
773
959
|
/**
|
|
774
960
|
* RPC Response for the method `frak_listenToWalletStatus`
|
|
@@ -815,7 +1001,7 @@ type WalletNotConnected = {
|
|
|
815
1001
|
* - Response Type: stream (emits updates when wallet status changes)
|
|
816
1002
|
*
|
|
817
1003
|
* #### frak_displayModal
|
|
818
|
-
* - Params: [requests: {@link ModalRpcStepsInput}, metadata?: {@link ModalRpcMetadata}, configMetadata: {@link FrakWalletSdkConfig}["metadata"]]
|
|
1004
|
+
* - Params: [requests: {@link ModalRpcStepsInput}, metadata?: {@link ModalRpcMetadata}, configMetadata: {@link FrakWalletSdkConfig}["metadata"], placement?: string]
|
|
819
1005
|
* - Returns: {@link ModalRpcStepsResultType}
|
|
820
1006
|
* - Response Type: promise (one-shot)
|
|
821
1007
|
*
|
|
@@ -830,9 +1016,14 @@ type WalletNotConnected = {
|
|
|
830
1016
|
* - Response Type: promise (one-shot)
|
|
831
1017
|
*
|
|
832
1018
|
* #### frak_displayEmbeddedWallet
|
|
833
|
-
* - Params: [request: {@link DisplayEmbeddedWalletParamsType}, metadata: {@link FrakWalletSdkConfig}["metadata"]]
|
|
1019
|
+
* - Params: [request: {@link DisplayEmbeddedWalletParamsType}, metadata: {@link FrakWalletSdkConfig}["metadata"], placement?: string]
|
|
834
1020
|
* - Returns: {@link DisplayEmbeddedWalletResultType}
|
|
835
1021
|
* - Response Type: promise (one-shot)
|
|
1022
|
+
*
|
|
1023
|
+
* #### frak_displaySharingPage
|
|
1024
|
+
* - Params: [request: {@link DisplaySharingPageParamsType}, configMetadata: {@link FrakWalletSdkConfig}["metadata"], placement?: string]
|
|
1025
|
+
* - Returns: {@link DisplaySharingPageResultType}
|
|
1026
|
+
* - Response Type: promise (one-shot)
|
|
836
1027
|
*/
|
|
837
1028
|
type IFrameRpcSchema = [
|
|
838
1029
|
/**
|
|
@@ -850,7 +1041,7 @@ type IFrameRpcSchema = [
|
|
|
850
1041
|
*/
|
|
851
1042
|
{
|
|
852
1043
|
Method: "frak_displayModal";
|
|
853
|
-
Parameters: [requests: ModalRpcStepsInput, metadata: ModalRpcMetadata | undefined, configMetadata: FrakWalletSdkConfig["metadata"]];
|
|
1044
|
+
Parameters: [requests: ModalRpcStepsInput, metadata: ModalRpcMetadata | undefined, configMetadata: FrakWalletSdkConfig["metadata"], placement?: string];
|
|
854
1045
|
ReturnType: ModalRpcStepsResultType;
|
|
855
1046
|
},
|
|
856
1047
|
/**
|
|
@@ -860,7 +1051,7 @@ type IFrameRpcSchema = [
|
|
|
860
1051
|
*/
|
|
861
1052
|
{
|
|
862
1053
|
Method: "frak_prepareSso";
|
|
863
|
-
Parameters: [params: PrepareSsoParamsType, name
|
|
1054
|
+
Parameters: [params: PrepareSsoParamsType, name?: string, customCss?: string];
|
|
864
1055
|
ReturnType: PrepareSsoReturnType;
|
|
865
1056
|
},
|
|
866
1057
|
/**
|
|
@@ -871,7 +1062,7 @@ type IFrameRpcSchema = [
|
|
|
871
1062
|
*/
|
|
872
1063
|
{
|
|
873
1064
|
Method: "frak_openSso";
|
|
874
|
-
Parameters: [params: OpenSsoParamsType, name
|
|
1065
|
+
Parameters: [params: OpenSsoParamsType, name?: string, customCss?: string];
|
|
875
1066
|
ReturnType: OpenSsoReturnType;
|
|
876
1067
|
},
|
|
877
1068
|
/**
|
|
@@ -892,14 +1083,14 @@ type IFrameRpcSchema = [
|
|
|
892
1083
|
*/
|
|
893
1084
|
{
|
|
894
1085
|
Method: "frak_displayEmbeddedWallet";
|
|
895
|
-
Parameters: [request: DisplayEmbeddedWalletParamsType, metadata: FrakWalletSdkConfig["metadata"]];
|
|
1086
|
+
Parameters: [request: DisplayEmbeddedWalletParamsType, metadata: FrakWalletSdkConfig["metadata"], placement?: string];
|
|
896
1087
|
ReturnType: DisplayEmbeddedWalletResultType;
|
|
897
1088
|
},
|
|
898
1089
|
/**
|
|
899
1090
|
* Method to send interactions (arrival, sharing, custom events)
|
|
900
1091
|
* Fire-and-forget method - no return value expected
|
|
901
1092
|
* merchantId is resolved from context
|
|
902
|
-
* clientId is passed via metadata as safeguard against
|
|
1093
|
+
* clientId is passed via metadata as safeguard against race conditions
|
|
903
1094
|
*/
|
|
904
1095
|
{
|
|
905
1096
|
Method: "frak_sendInteraction";
|
|
@@ -907,6 +1098,27 @@ type IFrameRpcSchema = [
|
|
|
907
1098
|
clientId?: string;
|
|
908
1099
|
}];
|
|
909
1100
|
ReturnType: undefined;
|
|
1101
|
+
},
|
|
1102
|
+
/**
|
|
1103
|
+
* Method to get the current user's referral status on this merchant.
|
|
1104
|
+
* Returns whether the user was referred (has a referral link as referee).
|
|
1105
|
+
* Returns null when the user's identity cannot be resolved.
|
|
1106
|
+
* This is a one-shot request.
|
|
1107
|
+
*/
|
|
1108
|
+
{
|
|
1109
|
+
Method: "frak_getUserReferralStatus";
|
|
1110
|
+
Parameters?: undefined;
|
|
1111
|
+
ReturnType: UserReferralStatusType | null;
|
|
1112
|
+
},
|
|
1113
|
+
/**
|
|
1114
|
+
* Method to display a sharing page with product info and sharing buttons
|
|
1115
|
+
* Resolves on first user action (share/copy) but the page stays visible
|
|
1116
|
+
* This is a one-shot request
|
|
1117
|
+
*/
|
|
1118
|
+
{
|
|
1119
|
+
Method: "frak_displaySharingPage";
|
|
1120
|
+
Parameters: [request: DisplaySharingPageParamsType, configMetadata: FrakWalletSdkConfig["metadata"], placement?: string];
|
|
1121
|
+
ReturnType: DisplaySharingPageResultType;
|
|
910
1122
|
}];
|
|
911
1123
|
//#endregion
|
|
912
1124
|
//#region src/types/transport.d.ts
|
|
@@ -1052,4 +1264,4 @@ declare const ssoPopupName = "frak-sso";
|
|
|
1052
1264
|
*/
|
|
1053
1265
|
declare function openSso(client: FrakClient, args: OpenSsoParamsType): Promise<OpenSsoReturnType>;
|
|
1054
1266
|
//#endregion
|
|
1055
|
-
export {
|
|
1267
|
+
export { ResolvedPlacement as $, ModalRpcMetadata as A, LoginModalStepType as B, EmbeddedViewActionReferred as C, DisplaySharingPageResultType as D, DisplaySharingPageParamsType as E, SendTransactionReturnType as F, SsoMetadata as G, OpenSsoReturnType as H, SendTransactionTxType as I, ModalStepMetadata as J, FinalActionType as K, SiweAuthenticateModalStepType as L, ModalRpcStepsResultType as M, ModalStepTypes as N, SharingPageProduct as O, SendTransactionModalStepType as P, MerchantConfigResponse as Q, SiweAuthenticateReturnType as R, LoggedOutEmbeddedView as S, LoggedInEmbeddedView as T, PrepareSsoParamsType as U, OpenSsoParamsType as V, PrepareSsoReturnType as W, IFrameLifecycleEvent as X, InteractionTypeKey as Y, ClientLifecycleEvent as Z, RewardTier as _, FrakContextV1 as a, Language as at, DisplayEmbeddedWalletParamsType as b, isV2Context as c, IFrameTransport as d, ResolvedSdkConfig as et, IFrameRpcSchema as f, GetMerchantInformationReturnType as g, EstimatedReward as h, FrakContext as i, I18nConfig as it, ModalRpcStepsInput as j, DisplayModalParamsType as k, FrakClient as l, UserReferralStatusType as m, ssoPopupFeatures as n, Currency as nt, FrakContextV2 as o, LocalizedI18nConfig as ot, WalletStatusReturnType as p, FinalModalStepType as q, ssoPopupName as r, FrakWalletSdkConfig as rt, isV1Context as s, openSso as t, SdkResolvedConfig as tt, FrakLifecycleEvent as u, TokenAmountType as v, EmbeddedViewActionSharing as w, DisplayEmbeddedWalletResultType as x, SendInteractionParamsType as y, SiweAuthenticationParams as z };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const e=require(`./trackEvent-CvbJTTqA.cjs`);let t=require(`@frak-labs/frame-connector`),n=require(`@openpanel/web`);const r=`nexus-wallet-backup`,i=`frakwallet://`;function a(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}function o(e){return`intent://${e.slice(13)}#Intent;scheme=frakwallet;end`}function s(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let s=a()&&c(e)?o(e):e;window.location.href=s,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function c(e){return e.startsWith(i)}const l={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function u(e){return e&&e in l?e:`eur`}function d(e){return e?l[e]??l.eur:l.eur}function f(e,t){let n=d(t),r=u(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function p(e){return e?`${e}Amount`:`eurAmount`}const m={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 h({walletBaseUrl:t,config:n}){let r=document.querySelector(`#frak-wallet`);r&&r.remove();let i=document.createElement(`iframe`);i.id=m.id,i.name=m.name,i.allow=m.allow,i.style.zIndex=m.style.zIndex.toString(),g({iframe:i,isVisible:!1});let a=n?.walletUrl??t??`https://wallet.frak.id`,o=e.y();return i.src=`${a}/listener?clientId=${encodeURIComponent(o)}`,new Promise(e=>{i.addEventListener(`load`,()=>e(i)),document.body.appendChild(i)})}function g({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 _(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 v(){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 y=v();function b(){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 x=b();function S(e){y&&e.startsWith(`https://`)?window.location.href=`x-safari-https://${e.slice(8)}`:y&&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 C(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`))}var w=class e{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?this.iframe.contentDocument.readyState===`complete`?1:0:-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(),i=`Unknown`;return e instanceof t.FrakRpcError?i=`FrakRpcError: ${e.code} '${e.message}'`:e instanceof Error?i=e.message:typeof e==`string`&&(i=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:i}}static empty(){return new e}formatDebugInfo(e){let t=this.gatherDebugInfo(e);return`
|
|
2
|
+
Debug Information:
|
|
3
|
+
-----------------
|
|
4
|
+
Timestamp: ${t.timestamp}
|
|
5
|
+
URL: ${t.encodedUrl}
|
|
6
|
+
Config: ${t.encodedConfig}
|
|
7
|
+
Navigator Info: ${t.navigatorInfo}
|
|
8
|
+
IFrame Status: ${t.iframeStatus}
|
|
9
|
+
Last Request: ${t.lastRequest}
|
|
10
|
+
Last Response: ${t.lastResponse}
|
|
11
|
+
Client Status: ${t.clientStatus}
|
|
12
|
+
Error: ${t.error}
|
|
13
|
+
`.trim()}};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(r,e):localStorage.removeItem(r)}function D(e,t){try{let n=new URL(e);return n.searchParams.has(`u`)?(n.searchParams.delete(`u`),n.searchParams.append(`u`,window.location.href),t&&n.searchParams.append(`fmt`,t),n.toString()):e}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,n,r){if(c(t)){let i=D(t,r);s(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 j({iframe:e,targetOrigin:n}){let i=new t.Deferred;return{handleEvent:async t=>{if(!(`iframeLifecycle`in t))return;let{iframeLifecycle:a,data:o}=t;switch(a){case`connected`:i.resolve(!0);break;case`do-backup`:E(o.backup);break;case`remove-backup`:localStorage.removeItem(r);break;case`show`:case`hide`:g({iframe:e,isVisible:a===`show`});break;case`redirect`:A(e,o.baseRedirectUrl,n,o.mergeToken);break}},isConnected:i.promise}}function M({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.n.setCacheScope(c,s),e.n.reset();let l=e.n.isCacheFresh?void 0:e.n.resolve(r.domain,r.walletUrl,s),u=j({iframe:i,targetOrigin:a}),d=new t.Deferred,f=new w(r,i);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}},{onRequest(e,t){return f.setLastRequest(e),t},onResponse(e,t){return f.setLastResponse(e,t),t}}],lifecycleHandlers:{iframeLifecycle:async(e,t)=>{await u.handleEvent(e)}}}),m=N(p,u),h=async()=>{m(),p.cleanup(),i.remove(),e.s(),e.n.clearCache(),e.n.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||`sdkVersion`in n.properties||(n.properties={...n.properties,sdkVersion:`0.2.1`,userAnonymousClientId:e.y()}),!0)}),g.setGlobalProperties({sdkVersion:`0.2.1`,userAnonymousClientId:e.y()}),g.init();let _=P({config:r,rpcClient:p,lifecycleManager:u,configPromise:l,contextSent:d}).then(()=>f.updateSetupStatus(!0)).catch(e=>{throw d.reject(e),e});return{config:r,debugInfo:f,waitForConnection:u.isConnected,waitForSetup:_,request:p.request,listenerRequest:p.listen,destroy:h,openPanel:g}}function N(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,1e3),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:i,configPromise:a,contextSent:o}){await i.isConnected,C(n,i.isConnected);let s=new URL(window.location.href),c=s.searchParams.get(`fmt`)??void 0;c&&(s.searchParams.delete(`fmt`),window.history.replaceState({},``,s.toString()));let l=n=>{let r=n?.merchantId??t.metadata.merchantId??``,i=n?.domain??``,a=n?.allowedDomains??[],o=n?.sdkConfig;e.n.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}:{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})},u=!1,d=e=>{let t=u?void 0:c;u=!0;let r=e.hasRawSdkConfig?{name:e.name,logoUrl:e.logoUrl,homepageLink:e.homepageLink,lang:e.lang,currency:e.currency,hidden:e.hidden,css:e.css,translations:e.translations,placements:e.placements}:void 0;n.sendLifecycle({clientLifecycle:`resolved-config`,data:{merchantId:e.merchantId,domain:e.domain??``,allowedDomains:e.allowedDomains??[],sourceUrl:window.location.href,...t&&{pendingMergeToken:t},...r&&{sdkConfig:r}}})};e.n.isResolved&&(d(e.n.getConfig()),o.resolve()),a&&(l(await a),d(e.n.getConfig()),o.resolve());async function f(){let e=t.customizations?.css;e&&n.sendLifecycle({clientLifecycle:`modal-css`,data:{cssLink:e}})}async function p(){let e=t.customizations?.i18n;e&&n.sendLifecycle({clientLifecycle:`modal-i18n`,data:{i18n:e}})}async function m(){if(typeof window>`u`)return;let e=window.localStorage.getItem(r);e&&n.sendLifecycle({clientLifecycle:`restore-backup`,data:{backup:e}})}await Promise.allSettled([f(),p(),m()])}async function F({config:e}){let t=I(e),n=await h({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 I(e){let t=u(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return c}}),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 _}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return i}});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import{n as e,s as t,y as n}from"./trackEvent-Ce1XlsIE.js";import{Deferred as r,FrakRpcError as i,RpcErrorCodes as a,createRpcClient as o}from"@frak-labs/frame-connector";import{OpenPanel as s}from"@openpanel/web";const c=`nexus-wallet-backup`,l=`frakwallet://`;function u(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}function d(e){return`intent://${e.slice(13)}#Intent;scheme=frakwallet;end`}function f(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=u()&&p(e)?d(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function p(e){return e.startsWith(l)}const m={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function h(e){return e&&e in m?e:`eur`}function g(e){return e?m[e]??m.eur:m.eur}function _(e,t){let n=g(t),r=h(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function v(e){return e?`${e}Amount`:`eurAmount`}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:e,config:t}){let r=document.querySelector(`#frak-wallet`);r&&r.remove();let i=document.createElement(`iframe`);i.id=y.id,i.name=y.name,i.allow=y.allow,i.style.zIndex=y.style.zIndex.toString(),x({iframe:i,isVisible:!1});let a=t?.walletUrl??e??`https://wallet.frak.id`,o=n();return i.src=`${a}/listener?clientId=${encodeURIComponent(o)}`,new Promise(e=>{i.addEventListener(`load`,()=>e(i)),document.body.appendChild(i)})}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(){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 w=C();function T(){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 E=T();function D(e){w&&e.startsWith(`https://`)?window.location.href=`x-safari-https://${e.slice(8)}`:w&&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 O(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`))}var k=class e{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?this.iframe.contentDocument.readyState===`complete`?1:0:-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 t=this.getIframeStatus(),n=this.getNavigatorInfo(),r=`Unknown`;return e instanceof i?r=`FrakRpcError: ${e.code} '${e.message}'`:e instanceof Error?r=e.message:typeof e==`string`&&(r=e),{timestamp:new Date().toISOString(),encodedUrl:btoa(window.location.href),encodedConfig:this.config?this.base64Encode(this.config):`no-config`,navigatorInfo:n?this.base64Encode(n):`no-navigator`,iframeStatus:t?this.base64Encode(t):`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:r}}static empty(){return new e}formatDebugInfo(e){let t=this.gatherDebugInfo(e);return`
|
|
2
|
+
Debug Information:
|
|
3
|
+
-----------------
|
|
4
|
+
Timestamp: ${t.timestamp}
|
|
5
|
+
URL: ${t.encodedUrl}
|
|
6
|
+
Config: ${t.encodedConfig}
|
|
7
|
+
Navigator Info: ${t.navigatorInfo}
|
|
8
|
+
IFrame Status: ${t.iframeStatus}
|
|
9
|
+
Last Request: ${t.lastRequest}
|
|
10
|
+
Last Response: ${t.lastResponse}
|
|
11
|
+
Client Status: ${t.clientStatus}
|
|
12
|
+
Error: ${t.error}
|
|
13
|
+
`.trim()}};const A=(()=>{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 j(e){e?localStorage.setItem(c,e):localStorage.removeItem(c)}function M(e,t){try{let n=new URL(e);return n.searchParams.has(`u`)?(n.searchParams.delete(`u`),n.searchParams.append(`u`,window.location.href),t&&n.searchParams.append(`fmt`,t),n.toString()):e}catch{return e}}function N(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 P(e){return e.includes(`/common/social`)}function F(e,t,n,r){if(p(t)){let i=M(t,r);f(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(A&&P(t))N(r);else{let e=M(t,r);window.location.href=e}}function I({iframe:e,targetOrigin:t}){let n=new r;return{handleEvent:async r=>{if(!(`iframeLifecycle`in r))return;let{iframeLifecycle:i,data:a}=r;switch(i){case`connected`:n.resolve(!0);break;case`do-backup`:j(a.backup);break;case`remove-backup`:localStorage.removeItem(c);break;case`show`:case`hide`:x({iframe:e,isVisible:i===`show`});break;case`redirect`:F(e,a.baseRedirectUrl,t,a.mergeToken);break}},isConnected:n.promise}}function L({config:c,iframe:l}){let u=c?.walletUrl??`https://wallet.frak.id`,d=typeof navigator<`u`?navigator.language?.split(`-`)[0]:void 0,f=c.metadata.lang??(d===`en`||d===`fr`?d:void 0),p=c.domain??(typeof window<`u`?window.location.hostname:``);e.setCacheScope(p,f),e.reset();let m=e.isCacheFresh?void 0:e.resolve(c.domain,c.walletUrl,f),h=I({iframe:l,targetOrigin:u}),g=new r,_=new k(c,l);if(!l.contentWindow)throw new i(a.configError,`The iframe does not have a content window`);let v=o({emittingTransport:l.contentWindow,listeningTransport:window,targetOrigin:u,middleware:[{async onRequest(e,t){if(!await h.isConnected)throw new i(a.clientNotConnected,`The iframe provider isn't connected yet`);return await g.promise,t}},{onRequest(e,t){return _.setLastRequest(e),t},onResponse(e,t){return _.setLastResponse(e,t),t}}],lifecycleHandlers:{iframeLifecycle:async(e,t)=>{await h.handleEvent(e)}}}),y=R(v,h),b=async()=>{y(),v.cleanup(),l.remove(),t(),e.clearCache(),e.reset()},x;console.log(`[Frak SDK] Initializing OpenPanel`),x=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})=>(e!==`track`||!t?.properties||`sdkVersion`in t.properties||(t.properties={...t.properties,sdkVersion:`0.2.1`,userAnonymousClientId:n()}),!0)}),x.setGlobalProperties({sdkVersion:`0.2.1`,userAnonymousClientId:n()}),x.init();let S=z({config:c,rpcClient:v,lifecycleManager:h,configPromise:m,contextSent:g}).then(()=>_.updateSetupStatus(!0)).catch(e=>{throw g.reject(e),e});return{config:c,debugInfo:_,waitForConnection:h.isConnected,waitForSetup:S,request:v.request,listenerRequest:v.listen,destroy:b,openPanel:x}}function R(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,1e3),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 z({config:t,rpcClient:n,lifecycleManager:r,configPromise:i,contextSent:a}){await r.isConnected,O(n,r.isConnected);let o=new URL(window.location.href),s=o.searchParams.get(`fmt`)??void 0;s&&(o.searchParams.delete(`fmt`),window.history.replaceState({},``,o.toString()));let l=n=>{let r=n?.merchantId??t.metadata.merchantId??``,i=n?.domain??``,a=n?.allowedDomains??[],o=n?.sdkConfig;e.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}:{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})},u=!1,d=e=>{let t=u?void 0:s;u=!0;let r=e.hasRawSdkConfig?{name:e.name,logoUrl:e.logoUrl,homepageLink:e.homepageLink,lang:e.lang,currency:e.currency,hidden:e.hidden,css:e.css,translations:e.translations,placements:e.placements}:void 0;n.sendLifecycle({clientLifecycle:`resolved-config`,data:{merchantId:e.merchantId,domain:e.domain??``,allowedDomains:e.allowedDomains??[],sourceUrl:window.location.href,...t&&{pendingMergeToken:t},...r&&{sdkConfig:r}}})};e.isResolved&&(d(e.getConfig()),a.resolve()),i&&(l(await i),d(e.getConfig()),a.resolve());async function f(){let e=t.customizations?.css;e&&n.sendLifecycle({clientLifecycle:`modal-css`,data:{cssLink:e}})}async function p(){let e=t.customizations?.i18n;e&&n.sendLifecycle({clientLifecycle:`modal-i18n`,data:{i18n:e}})}async function m(){if(typeof window>`u`)return;let e=window.localStorage.getItem(c);e&&n.sendLifecycle({clientLifecycle:`restore-backup`,data:{backup:e}})}await Promise.allSettled([f(),p(),m()])}async function B({config:e}){let t=V(e),n=await b({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=L({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=h(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}export{d as _,E as a,b as c,_ as d,g as f,p as g,u as h,w as i,S as l,m,L as n,D as o,h as p,k as r,y as s,B as t,v as u,f as v,l as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./trackEvent-CvbJTTqA.cjs`);let t=require(`viem`),n=require(`@frak-labs/frame-connector`),r=require(`viem/siwe`);async function i(e,t,n){return await e.request({method:`frak_displayEmbeddedWallet`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function a(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 o(e,t,n){return await e.request({method:`frak_displaySharingPage`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function s(t){if(typeof window>`u`)return;let n=e.y();if(!n)return;let r=await e.n.resolveMerchantId();if(!r)return;let i=`frak-identity-ensured-${r}`;if(!window.sessionStorage.getItem(i))try{let a=e.u();(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 c(t,n){return e.l(()=>t.request({method:`frak_getMerchantInformation`}),{cacheKey:`frak_getMerchantInformation`,cacheTime:n?.cacheTime})}async function l(t,n){return e.l(()=>t.request({method:`frak_getUserReferralStatus`}),{cacheKey:`frak_getUserReferralStatus`,cacheTime:n?.cacheTime})}async function u(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function d(t,n){try{await t.request({method:`frak_sendInteraction`,params:[n,{clientId:e.y()}]})}catch{console.warn(`[Frak SDK] Failed to send interaction:`,n.type)}}function f(t,n,r){let i=typeof window<`u`?window.location.href:void 0;return e.a(n)?(e.t(t,`user_referred_started`,{properties:{referrerClientId:n.c,walletStatus:r?.key}}),d(t,{type:`arrival`,referrerClientId:n.c,referrerMerchantId:n.m,referralTimestamp:n.t,landingUrl:i}),!0):e.i(n)?(e.t(t,`user_referred_started`,{properties:{referrer:n.r,walletStatus:r?.key}}),d(t,{type:`arrival`,referrerWallet:n.r,landingUrl:i}),!0):!1}function p(t){let n=e.y();return n?{v:2,c:n,m:t,t:Math.floor(Date.now()/1e3)}:null}function m(n,r){return e.a(n)?e.y()===n.c:e.i(n)&&r?.wallet?(0,t.isAddressEqual)(n.r,r.wallet):!1}function h(t,{walletStatus:n,frakContext:r,options:i}){if(!r)return`no-referrer`;if(m(r,n))return`self-referral`;if(!f(t,r,n))return`no-referrer`;let a=e.a(r)?r.m:i?.merchantId,o=i?.alwaysAppendUrl&&a?p(a):null;return e.r.replaceUrl({url:window.location?.href,context:o}),e.t(t,`user_referred_completed`,{properties:{status:`success`}}),`success`}async function g(t,{options:n}={}){let r=e.r.parse({url:window.location.href}),i=await b(t);try{return h(t,{walletStatus:i,frakContext:r,options:n})}catch(e){console.warn(`Error processing referral`,{error:e})}}const _=`frak:referral-success`;async function v(e){try{await g(e)===`success`&&window.dispatchEvent(new Event(_))}catch(e){console.warn(`[Frak] Referral setup failed`,e)}}async function y(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.y();if(!n&&!r){console.warn(`[Frak] No identity found, skipping purchase check`);return}let i=t.merchantId??await e.n.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.u();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 b(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(x(e,t),t));let r=new n.Deferred,i=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},n=>{x(e,n),t(n),i||=(r.resolve(n),!0)}),r.promise}function x(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?(window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken),s(t.interactionToken)):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function S(e,{metadata:t,login:n}){return C(e,{steps:{login:n??{}},metadata:t})}function C(e,t){function n(n){return C(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return C(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return C(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function o(n,r){return n&&(t.metadata=n(t.metadata??{})),await a(e,t,r)}return{params:t,sendTx:n,reward:r,sharing:i,display:o}}async function w(e,{tx:t,metadata:n}){return(await a(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}async function T(e,{siwe:t,metadata:n}){let i=e.config?.domain??window.location.host,o=t?.statement??`I confirm that I want to use my Frak wallet on: ${e.config.metadata.name}`;return(await a(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:o,nonce:t?.nonce??(0,r.generateSiweNonce)(),uri:t?.uri??`https://${i}`,version:t?.version??`1`,domain:i}}}})).siweAuthenticate}Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return d}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,i as t,l as n,n as r,r as i,t as a,u as o,y as s}from"./trackEvent-Ce1XlsIE.js";import{isAddressEqual as c}from"viem";import{Deferred as l}from"@frak-labs/frame-connector";import{generateSiweNonce as u}from"viem/siwe";async function d(e,t,n){return await e.request({method:`frak_displayEmbeddedWallet`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function f(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 p(e,t,n){return await e.request({method:`frak_displaySharingPage`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function m(e){if(typeof window>`u`)return;let t=s();if(!t)return;let n=await r.resolveMerchantId();if(!n)return;let i=`frak-identity-ensured-${n}`;if(!window.sessionStorage.getItem(i))try{let r=o();(await fetch(`${r}/user/identity/ensure`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`,"x-wallet-sdk-auth":e,"x-frak-client-id":t},body:JSON.stringify({merchantId:n})})).ok&&window.sessionStorage.setItem(i,`1`)}catch{}}async function h(e,t){return n(()=>e.request({method:`frak_getMerchantInformation`}),{cacheKey:`frak_getMerchantInformation`,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(e,t){try{await e.request({method:`frak_sendInteraction`,params:[t,{clientId:s()}]})}catch{console.warn(`[Frak SDK] Failed to send interaction:`,t.type)}}function y(n,r,i){let o=typeof window<`u`?window.location.href:void 0;return e(r)?(a(n,`user_referred_started`,{properties:{referrerClientId:r.c,walletStatus:i?.key}}),v(n,{type:`arrival`,referrerClientId:r.c,referrerMerchantId:r.m,referralTimestamp:r.t,landingUrl:o}),!0):t(r)?(a(n,`user_referred_started`,{properties:{referrer:r.r,walletStatus:i?.key}}),v(n,{type:`arrival`,referrerWallet:r.r,landingUrl:o}),!0):!1}function b(e){let t=s();return t?{v:2,c:t,m:e,t:Math.floor(Date.now()/1e3)}:null}function x(n,r){return e(n)?s()===n.c:t(n)&&r?.wallet?c(n.r,r.wallet):!1}function S(t,{walletStatus:n,frakContext:r,options:o}){if(!r)return`no-referrer`;if(x(r,n))return`self-referral`;if(!y(t,r,n))return`no-referrer`;let s=e(r)?r.m:o?.merchantId,c=o?.alwaysAppendUrl&&s?b(s):null;return i.replaceUrl({url:window.location?.href,context:c}),a(t,`user_referred_completed`,{properties:{status:`success`}}),`success`}async function C(e,{options:t}={}){let n=i.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(e){if(typeof window>`u`){console.warn(`[Frak] No window found, can't track purchase`);return}let t=window.sessionStorage.getItem(`frak-wallet-interaction-token`),n=s();if(!t&&!n){console.warn(`[Frak] No identity found, skipping purchase check`);return}let i=e.merchantId??await r.resolveMerchantId();if(!i){console.warn(`[Frak] No merchant id found, skipping purchase check`);return}let a={Accept:`application/json`,"Content-Type":`application/json`};t&&(a[`x-wallet-sdk-auth`]=t),n&&(a[`x-frak-client-id`]=n);let c=o();await fetch(`${c}/user/track/purchase`,{method:`POST`,headers:a,body:JSON.stringify({customerId:e.customerId,orderId:e.orderId,token:e.token,merchantId:i})})}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),m(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 f(e,t,r)}return{params:t,sendTx:n,reward:r,sharing:i,display:a}}async function j(e,{tx:t,metadata:n}){return(await f(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}async function M(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 f(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:i,nonce:t?.nonce??u(),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,M as t,v as u};
|