@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/utils/merchantId.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Merchant ID utilities for auto-fetching from backend
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { getBackendUrl } from "./backendUrl";
|
|
6
|
-
|
|
7
|
-
const MERCHANT_ID_STORAGE_KEY = "frak-merchant-id";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Response from the merchant lookup endpoint
|
|
11
|
-
*/
|
|
12
|
-
type MerchantLookupResponse = {
|
|
13
|
-
merchantId: string;
|
|
14
|
-
name: string;
|
|
15
|
-
domain: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* In-memory cache for merchantId lookups
|
|
20
|
-
* Persists for the session to avoid repeated API calls
|
|
21
|
-
*/
|
|
22
|
-
let cachedMerchantId: string | undefined;
|
|
23
|
-
let cachePromise: Promise<string | undefined> | undefined;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Fetch merchantId from backend by domain
|
|
27
|
-
*
|
|
28
|
-
* @param domain - The domain to lookup (defaults to current hostname)
|
|
29
|
-
* @param walletUrl - Optional wallet URL to derive backend URL
|
|
30
|
-
* @returns The merchantId if found, undefined otherwise
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* const merchantId = await fetchMerchantId("shop.example.com");
|
|
35
|
-
* if (merchantId) {
|
|
36
|
-
* // Use merchantId for tracking
|
|
37
|
-
* }
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export async function fetchMerchantId(
|
|
41
|
-
domain?: string,
|
|
42
|
-
walletUrl?: string
|
|
43
|
-
): Promise<string | undefined> {
|
|
44
|
-
// Use in-memory cache if available
|
|
45
|
-
if (cachedMerchantId) {
|
|
46
|
-
return cachedMerchantId;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Check sessionStorage (survives page navigations)
|
|
50
|
-
if (typeof window !== "undefined") {
|
|
51
|
-
const stored = window.sessionStorage.getItem(MERCHANT_ID_STORAGE_KEY);
|
|
52
|
-
if (stored) {
|
|
53
|
-
cachedMerchantId = stored;
|
|
54
|
-
return stored;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// If a fetch is already in progress, wait for it
|
|
59
|
-
if (cachePromise) {
|
|
60
|
-
return cachePromise;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Start the fetch and cache the promise
|
|
64
|
-
cachePromise = fetchMerchantIdInternal(domain, walletUrl);
|
|
65
|
-
const result = await cachePromise;
|
|
66
|
-
cachePromise = undefined;
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Internal fetch logic
|
|
72
|
-
*/
|
|
73
|
-
async function fetchMerchantIdInternal(
|
|
74
|
-
domain?: string,
|
|
75
|
-
walletUrl?: string
|
|
76
|
-
): Promise<string | undefined> {
|
|
77
|
-
const targetDomain =
|
|
78
|
-
domain ??
|
|
79
|
-
(typeof window !== "undefined" ? window.location.hostname : "");
|
|
80
|
-
if (!targetDomain) {
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
const backendUrl = getBackendUrl(walletUrl);
|
|
86
|
-
const response = await fetch(
|
|
87
|
-
`${backendUrl}/user/merchant/resolve?domain=${encodeURIComponent(targetDomain)}`
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
if (!response.ok) {
|
|
91
|
-
console.warn(
|
|
92
|
-
`[Frak SDK] Merchant lookup failed for domain ${targetDomain}: ${response.status}`
|
|
93
|
-
);
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const data = (await response.json()) as MerchantLookupResponse;
|
|
98
|
-
cachedMerchantId = data.merchantId;
|
|
99
|
-
// Persist to sessionStorage so it survives page navigations
|
|
100
|
-
if (typeof window !== "undefined") {
|
|
101
|
-
window.sessionStorage.setItem(
|
|
102
|
-
MERCHANT_ID_STORAGE_KEY,
|
|
103
|
-
data.merchantId
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
return cachedMerchantId;
|
|
107
|
-
} catch (error) {
|
|
108
|
-
console.warn("[Frak SDK] Failed to fetch merchantId:", error);
|
|
109
|
-
return undefined;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Clear the cached merchantId
|
|
115
|
-
* Useful for testing or when switching domains
|
|
116
|
-
*/
|
|
117
|
-
export function clearMerchantIdCache(): void {
|
|
118
|
-
cachedMerchantId = undefined;
|
|
119
|
-
cachePromise = undefined;
|
|
120
|
-
if (typeof window !== "undefined") {
|
|
121
|
-
window.sessionStorage.removeItem(MERCHANT_ID_STORAGE_KEY);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Get merchantId from config or auto-fetch from backend
|
|
127
|
-
*
|
|
128
|
-
* @param config - The SDK config that may contain merchantId
|
|
129
|
-
* @param walletUrl - Optional wallet URL to derive backend URL
|
|
130
|
-
* @returns The merchantId if available (from config or fetch), undefined otherwise
|
|
131
|
-
*/
|
|
132
|
-
export async function resolveMerchantId(
|
|
133
|
-
config: { metadata?: { merchantId?: string } },
|
|
134
|
-
walletUrl?: string
|
|
135
|
-
): Promise<string | undefined> {
|
|
136
|
-
// First, check config
|
|
137
|
-
if (config.metadata?.merchantId) {
|
|
138
|
-
return config.metadata.merchantId;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Otherwise, try to fetch from backend
|
|
142
|
-
return fetchMerchantId(undefined, walletUrl);
|
|
143
|
-
}
|