@frak-labs/core-sdk 0.2.1 → 1.0.0
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 +3 -3
- package/dist/actions-D4aBXbdp.cjs +1 -0
- package/dist/actions-Dq_uN-wn.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/{computeLegacyProductId-CCAZvLa5.d.cts → index-BV5D9DsW.d.ts} +91 -37
- package/dist/{siweAuthenticate-CnCZ7mok.d.ts → index-BphwTmKA.d.cts} +122 -8
- package/dist/{computeLegacyProductId-b5cUWdAm.d.ts → index-Dwmo109y.d.cts} +91 -37
- package/dist/{siweAuthenticate-CVigMOxz.d.cts → index-_f8EuN_1.d.ts} +122 -8
- 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-BwEK2M98.d.cts} +283 -44
- package/dist/{openSso-CMzwvaCa.d.ts → openSso-C1Wzl5-i.d.ts} +283 -44
- package/dist/src-B1eliIi6.cjs +13 -0
- package/dist/src-C0UH1GsN.js +13 -0
- package/dist/trackEvent-BqJqRZ-u.cjs +1 -0
- package/dist/trackEvent-Bqq4jd6R.js +1 -0
- package/package.json +11 -12
- 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/getMergeToken.ts +33 -0
- package/src/actions/getUserReferralStatus.ts +42 -0
- package/src/actions/index.ts +8 -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 +151 -27
- package/src/clients/transports/iframeLifecycleManager.test.ts +14 -94
- package/src/clients/transports/iframeLifecycleManager.ts +35 -53
- package/src/index.ts +17 -4
- package/src/stubs/rrweb.ts +9 -0
- 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 +7 -8
- package/src/types/resolvedConfig.ts +128 -0
- package/src/types/rpc/displaySharingPage.ts +82 -0
- package/src/types/rpc/embedded/index.ts +1 -1
- package/src/types/rpc/interaction.ts +4 -0
- package/src/types/rpc/userReferralStatus.ts +20 -0
- package/src/types/rpc.ts +54 -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 +168 -0
- package/src/utils/cache/withCache.ts +124 -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-BduY6Sym.cjs +0 -13
- package/dist/setupClient-ftmdQ-I8.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
package/src/index.ts
CHANGED
|
@@ -19,6 +19,9 @@ export type {
|
|
|
19
19
|
DisplayEmbeddedWalletParamsType,
|
|
20
20
|
DisplayEmbeddedWalletResultType,
|
|
21
21
|
DisplayModalParamsType,
|
|
22
|
+
// RPC Sharing page
|
|
23
|
+
DisplaySharingPageParamsType,
|
|
24
|
+
DisplaySharingPageResultType,
|
|
22
25
|
EmbeddedViewActionReferred,
|
|
23
26
|
EmbeddedViewActionSharing,
|
|
24
27
|
EstimatedReward,
|
|
@@ -47,6 +50,7 @@ export type {
|
|
|
47
50
|
LoggedInEmbeddedView,
|
|
48
51
|
LoggedOutEmbeddedView,
|
|
49
52
|
LoginModalStepType,
|
|
53
|
+
MerchantConfigResponse,
|
|
50
54
|
ModalRpcMetadata,
|
|
51
55
|
ModalRpcStepsInput,
|
|
52
56
|
ModalRpcStepsResultType,
|
|
@@ -58,12 +62,16 @@ export type {
|
|
|
58
62
|
OpenSsoReturnType,
|
|
59
63
|
PrepareSsoParamsType,
|
|
60
64
|
PrepareSsoReturnType,
|
|
65
|
+
ResolvedPlacement,
|
|
66
|
+
ResolvedSdkConfig,
|
|
61
67
|
RewardTier,
|
|
68
|
+
SdkResolvedConfig,
|
|
62
69
|
// RPC Interaction
|
|
63
70
|
SendInteractionParamsType,
|
|
64
71
|
SendTransactionModalStepType,
|
|
65
72
|
SendTransactionReturnType,
|
|
66
73
|
SendTransactionTxType,
|
|
74
|
+
SharingPageProduct,
|
|
67
75
|
SiweAuthenticateModalStepType,
|
|
68
76
|
SiweAuthenticateReturnType,
|
|
69
77
|
SiweAuthenticationParams,
|
|
@@ -72,8 +80,9 @@ export type {
|
|
|
72
80
|
// Tracking
|
|
73
81
|
TrackArrivalParams,
|
|
74
82
|
TrackArrivalResult,
|
|
75
|
-
UtmParams,
|
|
76
83
|
// Rpc
|
|
84
|
+
UserReferralStatusType,
|
|
85
|
+
UtmParams,
|
|
77
86
|
WalletStatusReturnType,
|
|
78
87
|
} from "./types";
|
|
79
88
|
export { isV1Context, isV2Context } from "./types";
|
|
@@ -84,7 +93,7 @@ export {
|
|
|
84
93
|
base64urlEncode,
|
|
85
94
|
baseIframeProps,
|
|
86
95
|
type CompressedSsoData,
|
|
87
|
-
|
|
96
|
+
clearAllCache,
|
|
88
97
|
compressJsonToB64,
|
|
89
98
|
createIframe,
|
|
90
99
|
DEEP_LINK_SCHEME,
|
|
@@ -93,20 +102,24 @@ export {
|
|
|
93
102
|
FrakContextManager,
|
|
94
103
|
type FrakEvent,
|
|
95
104
|
type FullSsoParams,
|
|
96
|
-
fetchMerchantId,
|
|
97
105
|
findIframeInOpener,
|
|
98
106
|
formatAmount,
|
|
99
107
|
generateSsoUrl,
|
|
100
108
|
getBackendUrl,
|
|
109
|
+
getCache,
|
|
101
110
|
getClientId,
|
|
102
111
|
getCurrencyAmountKey,
|
|
103
112
|
getSupportedCurrency,
|
|
104
113
|
getSupportedLocale,
|
|
105
114
|
isChromiumAndroid,
|
|
106
115
|
isFrakDeepLink,
|
|
107
|
-
|
|
116
|
+
isInAppBrowser,
|
|
117
|
+
isIOS,
|
|
118
|
+
redirectToExternalBrowser,
|
|
119
|
+
sdkConfigStore,
|
|
108
120
|
toAndroidIntentUrl,
|
|
109
121
|
trackEvent,
|
|
110
122
|
triggerDeepLinkWithFallback,
|
|
123
|
+
withCache,
|
|
111
124
|
} from "./utils";
|
|
112
125
|
export { computeLegacyProductId } from "./utils/computeLegacyProductId";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stub for rrweb. The @openpanel/web package statically imports `record` from
|
|
3
|
+
* rrweb even when session replay is disabled. This stub replaces the module so
|
|
4
|
+
* that rrweb is not included in the bundle.
|
|
5
|
+
* @see https://github.com/Openpanel-dev/openpanel/issues/336
|
|
6
|
+
*/
|
|
7
|
+
export function record() {
|
|
8
|
+
return () => {};
|
|
9
|
+
}
|
package/src/types/config.ts
CHANGED
|
@@ -27,7 +27,7 @@ export type FrakWalletSdkConfig = {
|
|
|
27
27
|
/**
|
|
28
28
|
* Your application name (will be displayed in a few modals and in SSO)
|
|
29
29
|
*/
|
|
30
|
-
name
|
|
30
|
+
name?: string;
|
|
31
31
|
/**
|
|
32
32
|
* Your merchant ID from the Frak dashboard (UUID format)
|
|
33
33
|
* Used for referral tracking and analytics
|
|
@@ -71,6 +71,13 @@ export type FrakWalletSdkConfig = {
|
|
|
71
71
|
* @defaultValue window.location.host
|
|
72
72
|
*/
|
|
73
73
|
domain?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Wait for backend config before rendering components.
|
|
76
|
+
* When true (default), components show a spinner until backend config is resolved.
|
|
77
|
+
* When false, components render immediately with SDK static config / HTML attributes.
|
|
78
|
+
* @defaultValue true
|
|
79
|
+
*/
|
|
80
|
+
waitForBackendConfig?: boolean;
|
|
74
81
|
};
|
|
75
82
|
|
|
76
83
|
/**
|
|
@@ -111,7 +118,7 @@ export type I18nConfig =
|
|
|
111
118
|
| LocalizedI18nConfig;
|
|
112
119
|
|
|
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
|
-
export type LocalizedI18nConfig =
|
|
124
|
+
export type LocalizedI18nConfig = { [key: string]: string };
|
package/src/types/index.ts
CHANGED
|
@@ -17,11 +17,16 @@ export type {
|
|
|
17
17
|
// Utils
|
|
18
18
|
export type { FrakContext, FrakContextV1, FrakContextV2 } from "./context";
|
|
19
19
|
export { isV1Context, isV2Context } from "./context";
|
|
20
|
-
|
|
21
20
|
export type {
|
|
22
21
|
ClientLifecycleEvent,
|
|
23
22
|
IFrameLifecycleEvent,
|
|
24
23
|
} from "./lifecycle";
|
|
24
|
+
export type {
|
|
25
|
+
MerchantConfigResponse,
|
|
26
|
+
ResolvedPlacement,
|
|
27
|
+
ResolvedSdkConfig,
|
|
28
|
+
SdkResolvedConfig,
|
|
29
|
+
} from "./resolvedConfig";
|
|
25
30
|
export type { IFrameRpcSchema } from "./rpc";
|
|
26
31
|
// Modal related
|
|
27
32
|
export type {
|
|
@@ -31,6 +36,12 @@ export type {
|
|
|
31
36
|
ModalRpcStepsResultType,
|
|
32
37
|
ModalStepTypes,
|
|
33
38
|
} from "./rpc/displayModal";
|
|
39
|
+
// Sharing page related
|
|
40
|
+
export type {
|
|
41
|
+
DisplaySharingPageParamsType,
|
|
42
|
+
DisplaySharingPageResultType,
|
|
43
|
+
SharingPageProduct,
|
|
44
|
+
} from "./rpc/displaySharingPage";
|
|
34
45
|
export type {
|
|
35
46
|
DisplayEmbeddedWalletParamsType,
|
|
36
47
|
DisplayEmbeddedWalletResultType,
|
|
@@ -65,6 +76,7 @@ export type {
|
|
|
65
76
|
PrepareSsoReturnType,
|
|
66
77
|
SsoMetadata,
|
|
67
78
|
} from "./rpc/sso";
|
|
79
|
+
export type { UserReferralStatusType } from "./rpc/userReferralStatus";
|
|
68
80
|
export type { WalletStatusReturnType } from "./rpc/walletStatus";
|
|
69
81
|
// Tracking
|
|
70
82
|
export type {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { I18nConfig } from "../config";
|
|
2
|
+
import type { ResolvedSdkConfig } from "../resolvedConfig";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Event related to the iframe lifecycle
|
|
@@ -9,9 +10,9 @@ export type ClientLifecycleEvent =
|
|
|
9
10
|
| CustomI18nEvent
|
|
10
11
|
| RestoreBackupEvent
|
|
11
12
|
| HearbeatEvent
|
|
12
|
-
| HandshakeResponse
|
|
13
13
|
| SsoRedirectCompleteEvent
|
|
14
|
-
| DeepLinkFailedEvent
|
|
14
|
+
| DeepLinkFailedEvent
|
|
15
|
+
| ResolvedConfigEvent;
|
|
15
16
|
|
|
16
17
|
type CustomCssEvent = {
|
|
17
18
|
clientLifecycle: "modal-css";
|
|
@@ -33,31 +34,6 @@ type HearbeatEvent = {
|
|
|
33
34
|
data?: never;
|
|
34
35
|
};
|
|
35
36
|
|
|
36
|
-
type HandshakeResponse = {
|
|
37
|
-
clientLifecycle: "handshake-response";
|
|
38
|
-
data: {
|
|
39
|
-
token: string;
|
|
40
|
-
currentUrl: string;
|
|
41
|
-
/**
|
|
42
|
-
* Pending merge token extracted from URL (?fmt= parameter)
|
|
43
|
-
* When present, listener should execute identity merge in background
|
|
44
|
-
* URL is cleaned after handshake response is sent
|
|
45
|
-
*/
|
|
46
|
-
pendingMergeToken?: string;
|
|
47
|
-
/**
|
|
48
|
-
* Client ID for identity tracking (belt & suspenders fallback)
|
|
49
|
-
* Primary delivery is via iframe URL query param; handshake is backup for SSR
|
|
50
|
-
*/
|
|
51
|
-
clientId?: string;
|
|
52
|
-
/**
|
|
53
|
-
* Explicit domain from SDK config (FrakWalletSdkConfig.domain)
|
|
54
|
-
* When present, listener should prefer this over URL-derived domain
|
|
55
|
-
* for merchant resolution (handles proxied/tunneled environments)
|
|
56
|
-
*/
|
|
57
|
-
configDomain?: string;
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
|
|
61
37
|
type SsoRedirectCompleteEvent = {
|
|
62
38
|
clientLifecycle: "sso-redirect-complete";
|
|
63
39
|
data: { compressed: string };
|
|
@@ -67,3 +43,22 @@ type DeepLinkFailedEvent = {
|
|
|
67
43
|
clientLifecycle: "deep-link-failed";
|
|
68
44
|
data: { originalUrl: string };
|
|
69
45
|
};
|
|
46
|
+
|
|
47
|
+
type ResolvedConfigEvent = {
|
|
48
|
+
clientLifecycle: "resolved-config";
|
|
49
|
+
data: {
|
|
50
|
+
merchantId: string;
|
|
51
|
+
/** The domain the backend resolved this config for */
|
|
52
|
+
domain: string;
|
|
53
|
+
/** All domains registered for this merchant (for domain proof) */
|
|
54
|
+
allowedDomains: string[];
|
|
55
|
+
/** Full URL of the parent page (for interaction tracking) */
|
|
56
|
+
sourceUrl: string;
|
|
57
|
+
/**
|
|
58
|
+
* Pending merge token extracted from URL (?fmt= parameter).
|
|
59
|
+
* When present, listener should execute identity merge in background.
|
|
60
|
+
*/
|
|
61
|
+
pendingMergeToken?: string;
|
|
62
|
+
sdkConfig?: ResolvedSdkConfig;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
@@ -8,7 +8,6 @@ export type IFrameLifecycleEvent =
|
|
|
8
8
|
data?: never;
|
|
9
9
|
}
|
|
10
10
|
| DoBackupEvent
|
|
11
|
-
| HandshakeRequestEvent
|
|
12
11
|
| RedirectRequestEvent;
|
|
13
12
|
|
|
14
13
|
type DoBackupEvent = {
|
|
@@ -16,13 +15,6 @@ type DoBackupEvent = {
|
|
|
16
15
|
data: { backup?: string };
|
|
17
16
|
};
|
|
18
17
|
|
|
19
|
-
type HandshakeRequestEvent = {
|
|
20
|
-
iframeLifecycle: "handshake";
|
|
21
|
-
data: {
|
|
22
|
-
token: string;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
18
|
type RedirectRequestEvent = {
|
|
27
19
|
iframeLifecycle: "redirect";
|
|
28
20
|
data: {
|
|
@@ -37,5 +29,12 @@ type RedirectRequestEvent = {
|
|
|
37
29
|
* Used when redirecting out of social browsers to preserve identity across contexts
|
|
38
30
|
*/
|
|
39
31
|
mergeToken?: string;
|
|
32
|
+
/**
|
|
33
|
+
* When true, open the URL in a new tab via window.open(_blank)
|
|
34
|
+
* instead of navigating the current page.
|
|
35
|
+
* Requires the postMessage to include user activation delegation
|
|
36
|
+
* (includeUserActivation: true) so Safari allows the popup.
|
|
37
|
+
*/
|
|
38
|
+
openInNewTab?: boolean;
|
|
40
39
|
};
|
|
41
40
|
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { Currency, Language } from "./config";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Response from the merchant resolve endpoint
|
|
5
|
+
* @category Config
|
|
6
|
+
*/
|
|
7
|
+
export type MerchantConfigResponse = {
|
|
8
|
+
merchantId: string;
|
|
9
|
+
name: string;
|
|
10
|
+
domain: string;
|
|
11
|
+
allowedDomains: string[];
|
|
12
|
+
sdkConfig?: ResolvedSdkConfig;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Resolved placement config from backend
|
|
17
|
+
* Translations already flattened: default + lang-specific merged into one record
|
|
18
|
+
* @category Config
|
|
19
|
+
*/
|
|
20
|
+
export type ResolvedPlacement = {
|
|
21
|
+
/** Per-component configuration within this placement */
|
|
22
|
+
components?: {
|
|
23
|
+
buttonShare?: {
|
|
24
|
+
text?: string;
|
|
25
|
+
noRewardText?: string;
|
|
26
|
+
clickAction?: "embedded-wallet" | "share-modal" | "sharing-page";
|
|
27
|
+
useReward?: boolean;
|
|
28
|
+
css?: string;
|
|
29
|
+
};
|
|
30
|
+
buttonWallet?: {
|
|
31
|
+
position?: "right" | "left";
|
|
32
|
+
css?: string;
|
|
33
|
+
};
|
|
34
|
+
openInApp?: {
|
|
35
|
+
text?: string;
|
|
36
|
+
css?: string;
|
|
37
|
+
};
|
|
38
|
+
postPurchase?: {
|
|
39
|
+
badgeText?: string;
|
|
40
|
+
refereeText?: string;
|
|
41
|
+
refereeNoRewardText?: string;
|
|
42
|
+
referrerText?: string;
|
|
43
|
+
referrerNoRewardText?: string;
|
|
44
|
+
ctaText?: string;
|
|
45
|
+
ctaNoRewardText?: string;
|
|
46
|
+
css?: string;
|
|
47
|
+
};
|
|
48
|
+
banner?: {
|
|
49
|
+
referralTitle?: string;
|
|
50
|
+
referralDescription?: string;
|
|
51
|
+
referralCta?: string;
|
|
52
|
+
inappTitle?: string;
|
|
53
|
+
inappDescription?: string;
|
|
54
|
+
inappCta?: string;
|
|
55
|
+
css?: string;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
targetInteraction?: string;
|
|
59
|
+
/** Already flattened: default + lang-specific merged into one record */
|
|
60
|
+
translations?: Record<string, string>;
|
|
61
|
+
/** Global placement CSS (applied to modals/listener) */
|
|
62
|
+
css?: string;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Resolved SDK config from backend `/resolve` endpoint
|
|
67
|
+
* Language resolution and translation merging already applied
|
|
68
|
+
* @category Config
|
|
69
|
+
*/
|
|
70
|
+
export type ResolvedSdkConfig = {
|
|
71
|
+
name?: string;
|
|
72
|
+
logoUrl?: string;
|
|
73
|
+
homepageLink?: string;
|
|
74
|
+
currency?: Currency;
|
|
75
|
+
lang?: Language;
|
|
76
|
+
/** When true, all SDK components should be hidden */
|
|
77
|
+
hidden?: boolean;
|
|
78
|
+
css?: string;
|
|
79
|
+
translations?: Record<string, string>;
|
|
80
|
+
placements?: Record<string, ResolvedPlacement>;
|
|
81
|
+
/** Global component defaults (used when no placement override exists) */
|
|
82
|
+
components?: ResolvedPlacement["components"];
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Internal SDK config store state
|
|
87
|
+
* Merged config: backend > SDK static > defaults
|
|
88
|
+
* Components subscribe to this reactively
|
|
89
|
+
* @category Config
|
|
90
|
+
*/
|
|
91
|
+
export type SdkResolvedConfig = {
|
|
92
|
+
/** Whether the backend config has been resolved */
|
|
93
|
+
isResolved: boolean;
|
|
94
|
+
|
|
95
|
+
/** Merchant ID from resolution */
|
|
96
|
+
merchantId: string;
|
|
97
|
+
|
|
98
|
+
/** Domain returned by the resolve endpoint */
|
|
99
|
+
domain?: string;
|
|
100
|
+
|
|
101
|
+
/** Domains allowed for this merchant (used by iframe trust check) */
|
|
102
|
+
allowedDomains?: string[];
|
|
103
|
+
|
|
104
|
+
/** Whether the resolve returned a backend sdkConfig object */
|
|
105
|
+
hasRawSdkConfig?: boolean;
|
|
106
|
+
|
|
107
|
+
/** Merged metadata fields */
|
|
108
|
+
name?: string;
|
|
109
|
+
logoUrl?: string;
|
|
110
|
+
homepageLink?: string;
|
|
111
|
+
lang?: Language;
|
|
112
|
+
currency?: Currency;
|
|
113
|
+
|
|
114
|
+
/** When true, all SDK components should be hidden */
|
|
115
|
+
hidden?: boolean;
|
|
116
|
+
|
|
117
|
+
/** Global CSS from backend config (passed to iframe) */
|
|
118
|
+
css?: string;
|
|
119
|
+
|
|
120
|
+
/** Global translations (for reference / component fallback) */
|
|
121
|
+
translations?: Record<string, string>;
|
|
122
|
+
|
|
123
|
+
/** Named placements (keyed by placement ID) */
|
|
124
|
+
placements?: Record<string, ResolvedPlacement>;
|
|
125
|
+
|
|
126
|
+
/** Global component defaults (fallback for placement-level overrides) */
|
|
127
|
+
components?: ResolvedPlacement["components"];
|
|
128
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { InteractionTypeKey } from "../../constants/interactionTypes";
|
|
2
|
+
import type { I18nConfig } from "../config";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Product information to display on the sharing page
|
|
6
|
+
* @group Sharing Page
|
|
7
|
+
*/
|
|
8
|
+
export type SharingPageProduct = {
|
|
9
|
+
/**
|
|
10
|
+
* The product title / name
|
|
11
|
+
*/
|
|
12
|
+
title: string;
|
|
13
|
+
/**
|
|
14
|
+
* Optional product image URL
|
|
15
|
+
*/
|
|
16
|
+
imageUrl?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Optional product-specific sharing link
|
|
19
|
+
* When provided and the product is selected, this link is used instead of the default sharing link
|
|
20
|
+
*/
|
|
21
|
+
link?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Parameters to display the sharing page
|
|
26
|
+
* @group Sharing Page
|
|
27
|
+
* @group RPC Schema
|
|
28
|
+
*/
|
|
29
|
+
export type DisplaySharingPageParamsType = {
|
|
30
|
+
/**
|
|
31
|
+
* Products to showcase on the sharing page
|
|
32
|
+
* If provided, they will be displayed in a product card section
|
|
33
|
+
*/
|
|
34
|
+
products?: SharingPageProduct[];
|
|
35
|
+
/**
|
|
36
|
+
* Optional link override for sharing
|
|
37
|
+
* If not provided, the sharing link will be generated from the current page URL + merchant context
|
|
38
|
+
*/
|
|
39
|
+
link?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Optional metadata overrides for the sharing page
|
|
42
|
+
*/
|
|
43
|
+
metadata?: {
|
|
44
|
+
/**
|
|
45
|
+
* Logo override for the sharing page header
|
|
46
|
+
*/
|
|
47
|
+
logo?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Link to the homepage of the calling website
|
|
50
|
+
*/
|
|
51
|
+
homepageLink?: string;
|
|
52
|
+
/**
|
|
53
|
+
* The target interaction behind this sharing page
|
|
54
|
+
*/
|
|
55
|
+
targetInteraction?: InteractionTypeKey;
|
|
56
|
+
/**
|
|
57
|
+
* i18n overrides for the sharing page
|
|
58
|
+
*/
|
|
59
|
+
i18n?: I18nConfig;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Result of the sharing page display
|
|
65
|
+
* @group Sharing Page
|
|
66
|
+
* @group RPC Schema
|
|
67
|
+
*/
|
|
68
|
+
export type DisplaySharingPageResultType = {
|
|
69
|
+
/**
|
|
70
|
+
* The action the user took
|
|
71
|
+
* - "shared": User used the native share dialog
|
|
72
|
+
* - "copied": User copied the link to clipboard
|
|
73
|
+
* - "dismissed": User dismissed the sharing page without acting
|
|
74
|
+
*/
|
|
75
|
+
action: "shared" | "copied" | "dismissed";
|
|
76
|
+
/**
|
|
77
|
+
* The install URL for the Frak app
|
|
78
|
+
* Can be used as a fallback to redirect the user to the install page
|
|
79
|
+
* from the merchant's top-level page (e.g. via `window.location.href`)
|
|
80
|
+
*/
|
|
81
|
+
installUrl?: string;
|
|
82
|
+
};
|
|
@@ -9,10 +9,10 @@ import type {
|
|
|
9
9
|
import type { LoggedOutEmbeddedView } from "./loggedOut";
|
|
10
10
|
|
|
11
11
|
export type {
|
|
12
|
+
EmbeddedViewActionReferred,
|
|
12
13
|
EmbeddedViewActionSharing,
|
|
13
14
|
LoggedInEmbeddedView,
|
|
14
15
|
LoggedOutEmbeddedView,
|
|
15
|
-
EmbeddedViewActionReferred,
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -26,6 +26,10 @@ export type SendInteractionParamsType =
|
|
|
26
26
|
}
|
|
27
27
|
| {
|
|
28
28
|
type: "sharing";
|
|
29
|
+
/** Epoch seconds timestamp matching the V2 context `t` field embedded in the referral link URL, used for backend correlation */
|
|
30
|
+
sharingTimestamp?: number;
|
|
31
|
+
/** Merchant order ID linking this sharing event to a purchase (stays server-side, never in URL) */
|
|
32
|
+
purchaseId?: string;
|
|
29
33
|
}
|
|
30
34
|
| {
|
|
31
35
|
type: "custom";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User referral status returned by `frak_getUserReferralStatus`.
|
|
3
|
+
*
|
|
4
|
+
* Generic referral context for the current user on a merchant.
|
|
5
|
+
* Used by components like `<frak-post-purchase>` and `<frak-referred-banner>`
|
|
6
|
+
* to adapt their display based on the user's referral relationship.
|
|
7
|
+
*
|
|
8
|
+
* Returns `null` when the user's identity cannot be resolved
|
|
9
|
+
* (e.g. no clientId and no wallet session).
|
|
10
|
+
*
|
|
11
|
+
* @group RPC Schema
|
|
12
|
+
*/
|
|
13
|
+
export type UserReferralStatusType = {
|
|
14
|
+
/**
|
|
15
|
+
* Whether the user was referred to this merchant by someone else.
|
|
16
|
+
*
|
|
17
|
+
* `true` means a referral link exists where this user is the referee.
|
|
18
|
+
*/
|
|
19
|
+
isReferred: boolean;
|
|
20
|
+
};
|
package/src/types/rpc.ts
CHANGED
|
@@ -4,6 +4,10 @@ import type {
|
|
|
4
4
|
ModalRpcStepsInput,
|
|
5
5
|
ModalRpcStepsResultType,
|
|
6
6
|
} from "./rpc/displayModal";
|
|
7
|
+
import type {
|
|
8
|
+
DisplaySharingPageParamsType,
|
|
9
|
+
DisplaySharingPageResultType,
|
|
10
|
+
} from "./rpc/displaySharingPage";
|
|
7
11
|
import type {
|
|
8
12
|
DisplayEmbeddedWalletParamsType,
|
|
9
13
|
DisplayEmbeddedWalletResultType,
|
|
@@ -16,6 +20,7 @@ import type {
|
|
|
16
20
|
PrepareSsoParamsType,
|
|
17
21
|
PrepareSsoReturnType,
|
|
18
22
|
} from "./rpc/sso";
|
|
23
|
+
import type { UserReferralStatusType } from "./rpc/userReferralStatus";
|
|
19
24
|
import type { WalletStatusReturnType } from "./rpc/walletStatus";
|
|
20
25
|
|
|
21
26
|
/**
|
|
@@ -38,7 +43,7 @@ import type { WalletStatusReturnType } from "./rpc/walletStatus";
|
|
|
38
43
|
* - Response Type: stream (emits updates when wallet status changes)
|
|
39
44
|
*
|
|
40
45
|
* #### frak_displayModal
|
|
41
|
-
* - Params: [requests: {@link ModalRpcStepsInput}, metadata?: {@link ModalRpcMetadata}, configMetadata: {@link FrakWalletSdkConfig}["metadata"]]
|
|
46
|
+
* - Params: [requests: {@link ModalRpcStepsInput}, metadata?: {@link ModalRpcMetadata}, configMetadata: {@link FrakWalletSdkConfig}["metadata"], placement?: string]
|
|
42
47
|
* - Returns: {@link ModalRpcStepsResultType}
|
|
43
48
|
* - Response Type: promise (one-shot)
|
|
44
49
|
*
|
|
@@ -53,9 +58,14 @@ import type { WalletStatusReturnType } from "./rpc/walletStatus";
|
|
|
53
58
|
* - Response Type: promise (one-shot)
|
|
54
59
|
*
|
|
55
60
|
* #### frak_displayEmbeddedWallet
|
|
56
|
-
* - Params: [request: {@link DisplayEmbeddedWalletParamsType}, metadata: {@link FrakWalletSdkConfig}["metadata"]]
|
|
61
|
+
* - Params: [request: {@link DisplayEmbeddedWalletParamsType}, metadata: {@link FrakWalletSdkConfig}["metadata"], placement?: string]
|
|
57
62
|
* - Returns: {@link DisplayEmbeddedWalletResultType}
|
|
58
63
|
* - Response Type: promise (one-shot)
|
|
64
|
+
*
|
|
65
|
+
* #### frak_displaySharingPage
|
|
66
|
+
* - Params: [request: {@link DisplaySharingPageParamsType}, configMetadata: {@link FrakWalletSdkConfig}["metadata"], placement?: string]
|
|
67
|
+
* - Returns: {@link DisplaySharingPageResultType}
|
|
68
|
+
* - Response Type: promise (one-shot)
|
|
59
69
|
*/
|
|
60
70
|
export type IFrameRpcSchema = [
|
|
61
71
|
/**
|
|
@@ -77,6 +87,7 @@ export type IFrameRpcSchema = [
|
|
|
77
87
|
requests: ModalRpcStepsInput,
|
|
78
88
|
metadata: ModalRpcMetadata | undefined,
|
|
79
89
|
configMetadata: FrakWalletSdkConfig["metadata"],
|
|
90
|
+
placement?: string,
|
|
80
91
|
];
|
|
81
92
|
ReturnType: ModalRpcStepsResultType;
|
|
82
93
|
},
|
|
@@ -89,7 +100,7 @@ export type IFrameRpcSchema = [
|
|
|
89
100
|
Method: "frak_prepareSso";
|
|
90
101
|
Parameters: [
|
|
91
102
|
params: PrepareSsoParamsType,
|
|
92
|
-
name
|
|
103
|
+
name?: string,
|
|
93
104
|
customCss?: string,
|
|
94
105
|
];
|
|
95
106
|
ReturnType: PrepareSsoReturnType;
|
|
@@ -104,7 +115,7 @@ export type IFrameRpcSchema = [
|
|
|
104
115
|
Method: "frak_openSso";
|
|
105
116
|
Parameters: [
|
|
106
117
|
params: OpenSsoParamsType,
|
|
107
|
-
name
|
|
118
|
+
name?: string,
|
|
108
119
|
customCss?: string,
|
|
109
120
|
];
|
|
110
121
|
ReturnType: OpenSsoReturnType;
|
|
@@ -130,6 +141,7 @@ export type IFrameRpcSchema = [
|
|
|
130
141
|
Parameters: [
|
|
131
142
|
request: DisplayEmbeddedWalletParamsType,
|
|
132
143
|
metadata: FrakWalletSdkConfig["metadata"],
|
|
144
|
+
placement?: string,
|
|
133
145
|
];
|
|
134
146
|
ReturnType: DisplayEmbeddedWalletResultType;
|
|
135
147
|
},
|
|
@@ -137,7 +149,7 @@ export type IFrameRpcSchema = [
|
|
|
137
149
|
* Method to send interactions (arrival, sharing, custom events)
|
|
138
150
|
* Fire-and-forget method - no return value expected
|
|
139
151
|
* merchantId is resolved from context
|
|
140
|
-
* clientId is passed via metadata as safeguard against
|
|
152
|
+
* clientId is passed via metadata as safeguard against race conditions
|
|
141
153
|
*/
|
|
142
154
|
{
|
|
143
155
|
Method: "frak_sendInteraction";
|
|
@@ -147,4 +159,41 @@ export type IFrameRpcSchema = [
|
|
|
147
159
|
];
|
|
148
160
|
ReturnType: undefined;
|
|
149
161
|
},
|
|
162
|
+
/**
|
|
163
|
+
* Method to get the current user's referral status on this merchant.
|
|
164
|
+
* Returns whether the user was referred (has a referral link as referee).
|
|
165
|
+
* Returns null when the user's identity cannot be resolved.
|
|
166
|
+
* This is a one-shot request.
|
|
167
|
+
*/
|
|
168
|
+
{
|
|
169
|
+
Method: "frak_getUserReferralStatus";
|
|
170
|
+
Parameters?: undefined;
|
|
171
|
+
ReturnType: UserReferralStatusType | null;
|
|
172
|
+
},
|
|
173
|
+
/**
|
|
174
|
+
* Method to display a sharing page with product info and sharing buttons
|
|
175
|
+
* Resolves on first user action (share/copy) but the page stays visible
|
|
176
|
+
* This is a one-shot request
|
|
177
|
+
*/
|
|
178
|
+
{
|
|
179
|
+
Method: "frak_displaySharingPage";
|
|
180
|
+
Parameters: [
|
|
181
|
+
request: DisplaySharingPageParamsType,
|
|
182
|
+
configMetadata: FrakWalletSdkConfig["metadata"],
|
|
183
|
+
placement?: string,
|
|
184
|
+
];
|
|
185
|
+
ReturnType: DisplaySharingPageResultType;
|
|
186
|
+
},
|
|
187
|
+
/**
|
|
188
|
+
* Method to get a merge token for the current anonymous identity.
|
|
189
|
+
* Used by in-app browser redirect flows to preserve identity
|
|
190
|
+
* when switching from a WebView to the system browser.
|
|
191
|
+
* Returns the merge token string, or null if unavailable.
|
|
192
|
+
* This is a one-shot request.
|
|
193
|
+
*/
|
|
194
|
+
{
|
|
195
|
+
Method: "frak_getMergeToken";
|
|
196
|
+
Parameters?: undefined;
|
|
197
|
+
ReturnType: string | null;
|
|
198
|
+
},
|
|
150
199
|
];
|
|
@@ -15,13 +15,13 @@ describe("getBackendUrl", () => {
|
|
|
15
15
|
describe("with explicit walletUrl", () => {
|
|
16
16
|
test("should return localhost backend for localhost:3000", () => {
|
|
17
17
|
expect(getBackendUrl("https://localhost:3000")).toBe(
|
|
18
|
-
"
|
|
18
|
+
"https://localhost:3030"
|
|
19
19
|
);
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
test("should return localhost backend for localhost:3010", () => {
|
|
23
23
|
expect(getBackendUrl("https://localhost:3010")).toBe(
|
|
24
|
-
"
|
|
24
|
+
"https://localhost:3030"
|
|
25
25
|
);
|
|
26
26
|
});
|
|
27
27
|
|
package/src/utils/backendUrl.ts
CHANGED
|
@@ -19,7 +19,7 @@ function isLocalDevelopment(walletUrl: string): boolean {
|
|
|
19
19
|
*/
|
|
20
20
|
function deriveBackendUrl(walletUrl: string): string {
|
|
21
21
|
if (isLocalDevelopment(walletUrl)) {
|
|
22
|
-
return "
|
|
22
|
+
return "https://localhost:3030";
|
|
23
23
|
}
|
|
24
24
|
// Dev environment
|
|
25
25
|
if (
|