@frak-labs/core-sdk 0.1.1 → 0.2.0-beta.7898df5b
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 +58 -0
- package/cdn/bundle.js +14 -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 -6
- package/dist/bundle.d.ts +4 -6
- package/dist/bundle.js +1 -1
- package/dist/computeLegacyProductId-CCAZvLa5.d.cts +537 -0
- package/dist/computeLegacyProductId-b5cUWdAm.d.ts +537 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +1 -1
- package/dist/{openSso-D--Airj6.d.cts → openSso-B0g7-807.d.cts} +173 -136
- package/dist/{openSso-DsKJ4y0j.d.ts → openSso-CMzwvaCa.d.ts} +173 -136
- package/dist/setupClient-BICl5fdX.js +13 -0
- package/dist/setupClient-nl8Dhh4V.cjs +13 -0
- package/dist/siweAuthenticate-BWmI2_TN.cjs +1 -0
- package/dist/{index-d8xS4ryI.d.ts → siweAuthenticate-CVigMOxz.d.cts} +113 -92
- package/dist/{index-C6FxkWPC.d.cts → siweAuthenticate-CnCZ7mok.d.ts} +113 -92
- package/dist/siweAuthenticate-zczqxm0a.js +1 -0
- package/dist/trackEvent-CeLFVzZn.js +1 -0
- package/dist/trackEvent-Ew5r5zfI.cjs +1 -0
- package/package.json +11 -22
- package/src/actions/displayEmbeddedWallet.ts +1 -0
- package/src/actions/displayModal.test.ts +12 -11
- package/src/actions/displayModal.ts +7 -18
- package/src/actions/ensureIdentity.ts +68 -0
- package/src/actions/{getProductInformation.test.ts → getMerchantInformation.test.ts} +33 -50
- package/src/actions/getMerchantInformation.ts +16 -0
- package/src/actions/index.ts +3 -2
- package/src/actions/openSso.ts +4 -2
- package/src/actions/referral/processReferral.test.ts +117 -242
- package/src/actions/referral/processReferral.ts +134 -204
- package/src/actions/referral/referralInteraction.test.ts +4 -12
- package/src/actions/referral/referralInteraction.ts +3 -13
- package/src/actions/sendInteraction.ts +46 -22
- package/src/actions/trackPurchaseStatus.test.ts +354 -141
- package/src/actions/trackPurchaseStatus.ts +48 -11
- package/src/actions/watchWalletStatus.ts +2 -3
- package/src/actions/wrapper/modalBuilder.test.ts +0 -14
- package/src/actions/wrapper/modalBuilder.ts +3 -12
- package/src/bundle.ts +0 -1
- package/src/clients/createIFrameFrakClient.ts +10 -5
- package/src/clients/transports/iframeLifecycleManager.test.ts +163 -4
- package/src/clients/transports/iframeLifecycleManager.ts +172 -33
- package/src/constants/interactionTypes.ts +12 -41
- package/src/index.ts +27 -16
- package/src/types/config.ts +6 -0
- package/src/types/context.ts +48 -6
- package/src/types/index.ts +15 -11
- package/src/types/lifecycle/client.ts +24 -1
- package/src/types/lifecycle/iframe.ts +6 -0
- package/src/types/rpc/displayModal.ts +2 -4
- package/src/types/rpc/embedded/index.ts +2 -2
- package/src/types/rpc/interaction.ts +31 -39
- package/src/types/rpc/merchantInformation.ts +77 -0
- package/src/types/rpc/modal/index.ts +0 -4
- package/src/types/rpc/modal/login.ts +5 -1
- package/src/types/rpc/walletStatus.ts +1 -7
- package/src/types/rpc.ts +22 -30
- package/src/types/tracking.ts +31 -0
- package/src/utils/FrakContext.test.ts +270 -186
- package/src/utils/FrakContext.ts +78 -56
- package/src/utils/backendUrl.test.ts +83 -0
- package/src/utils/backendUrl.ts +62 -0
- package/src/utils/clientId.test.ts +41 -0
- package/src/utils/clientId.ts +43 -0
- package/src/utils/compression/compress.test.ts +1 -1
- package/src/utils/compression/compress.ts +2 -2
- package/src/utils/compression/decompress.test.ts +8 -4
- package/src/utils/compression/decompress.ts +2 -2
- package/src/utils/{computeProductId.ts → computeLegacyProductId.ts} +2 -2
- package/src/utils/constants.ts +5 -0
- package/src/utils/deepLinkWithFallback.test.ts +243 -0
- package/src/utils/deepLinkWithFallback.ts +103 -0
- package/src/utils/formatAmount.ts +6 -0
- package/src/utils/iframeHelper.test.ts +18 -5
- package/src/utils/iframeHelper.ts +10 -3
- package/src/utils/index.ts +16 -1
- package/src/utils/merchantId.test.ts +653 -0
- package/src/utils/merchantId.ts +143 -0
- package/src/utils/sso.ts +18 -11
- package/src/utils/trackEvent.test.ts +23 -5
- package/src/utils/trackEvent.ts +13 -0
- package/cdn/bundle.iife.js +0 -14
- package/dist/actions-B5j-i1p0.cjs +0 -1
- package/dist/actions-q090Z0oR.js +0 -1
- package/dist/index-7OZ39x1U.d.ts +0 -195
- package/dist/index-CRsQWnTs.d.cts +0 -351
- package/dist/index-Ck1hudEi.d.ts +0 -351
- package/dist/index-zDq-VlKx.d.cts +0 -195
- package/dist/interaction-DMJ3ZfaF.d.cts +0 -45
- package/dist/interaction-KX1h9a7V.d.ts +0 -45
- package/dist/interactions-DnfM3oe0.js +0 -1
- package/dist/interactions-EIXhNLf6.cjs +0 -1
- package/dist/interactions.cjs +0 -1
- package/dist/interactions.d.cts +0 -2
- package/dist/interactions.d.ts +0 -2
- package/dist/interactions.js +0 -1
- package/dist/productTypes-BUkXJKZ7.cjs +0 -1
- package/dist/productTypes-CGb1MmBF.js +0 -1
- package/dist/src-1LQ4eLq5.js +0 -13
- package/dist/src-hW71KjPN.cjs +0 -13
- package/dist/trackEvent-CHnYa85W.js +0 -1
- package/dist/trackEvent-GuQm_1Nm.cjs +0 -1
- package/src/actions/getProductInformation.ts +0 -14
- package/src/actions/openSso.test.ts +0 -407
- package/src/actions/sendInteraction.test.ts +0 -219
- package/src/constants/interactionTypes.test.ts +0 -128
- package/src/constants/productTypes.test.ts +0 -130
- package/src/constants/productTypes.ts +0 -33
- package/src/interactions/index.ts +0 -5
- package/src/interactions/pressEncoder.test.ts +0 -215
- package/src/interactions/pressEncoder.ts +0 -53
- package/src/interactions/purchaseEncoder.test.ts +0 -291
- package/src/interactions/purchaseEncoder.ts +0 -99
- package/src/interactions/referralEncoder.test.ts +0 -170
- package/src/interactions/referralEncoder.ts +0 -47
- package/src/interactions/retailEncoder.test.ts +0 -107
- package/src/interactions/retailEncoder.ts +0 -37
- package/src/interactions/webshopEncoder.test.ts +0 -56
- package/src/interactions/webshopEncoder.ts +0 -30
- package/src/types/rpc/modal/openSession.ts +0 -25
- package/src/types/rpc/productInformation.ts +0 -59
- package/src/utils/computeProductId.test.ts +0 -80
- package/src/utils/sso.test.ts +0 -361
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
import { J as Currency, V as SsoMetadata, Y as FrakWalletSdkConfig, _ as TokenAmountType, a as FrakContextV1, i as FrakContext, l as FrakClient, o as FrakContextV2, z as PrepareSsoParamsType } from "./openSso-B0g7-807.cjs";
|
|
2
|
+
import { RpcMessage, RpcResponse } from "@frak-labs/frame-connector";
|
|
3
|
+
import { Address, Hex } from "viem";
|
|
4
|
+
|
|
5
|
+
//#region src/types/compression.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* The received encoded data from a client
|
|
8
|
+
* -> The encoded should contain a HashProtectedData once decoded
|
|
9
|
+
* @ignore
|
|
10
|
+
*/
|
|
11
|
+
type CompressedData = Uint8Array;
|
|
12
|
+
/**
|
|
13
|
+
* The encoded data to send to a client / received by a client
|
|
14
|
+
* @ignore
|
|
15
|
+
*/
|
|
16
|
+
type HashProtectedData<DataType> = Readonly<DataType & {
|
|
17
|
+
validationHash: string;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Represent a key provider used for the hashed and secure compression
|
|
21
|
+
* @ignore
|
|
22
|
+
*/
|
|
23
|
+
type KeyProvider<DataType> = (value: DataType) => string[];
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/types/tracking.d.ts
|
|
26
|
+
type UtmParams = {
|
|
27
|
+
source?: string;
|
|
28
|
+
medium?: string;
|
|
29
|
+
campaign?: string;
|
|
30
|
+
term?: string;
|
|
31
|
+
content?: string;
|
|
32
|
+
};
|
|
33
|
+
type TrackArrivalParams = {
|
|
34
|
+
/** @deprecated V1 legacy — use referrerClientId for v2 contexts */referrerWallet?: Address;
|
|
35
|
+
referrerClientId?: string;
|
|
36
|
+
referrerMerchantId?: string; /** Epoch seconds timestamp from the referral link creation */
|
|
37
|
+
referralTimestamp?: number;
|
|
38
|
+
landingUrl?: string;
|
|
39
|
+
utmParams?: UtmParams;
|
|
40
|
+
};
|
|
41
|
+
type TrackArrivalResult = {
|
|
42
|
+
success: boolean;
|
|
43
|
+
identityGroupId?: string;
|
|
44
|
+
touchpointId?: string;
|
|
45
|
+
error?: string;
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/clients/createIFrameFrakClient.d.ts
|
|
49
|
+
/**
|
|
50
|
+
* Create a new iframe Frak client
|
|
51
|
+
* @param args
|
|
52
|
+
* @param args.config - The configuration to use for the Frak Wallet SDK.
|
|
53
|
+
* When `config.domain` is set, it is forwarded to the iframe handshake so the listener resolves the correct merchant in tunneled/proxied environments (e.g. Shopify dev with Cloudflare tunnel).
|
|
54
|
+
* @param args.iframe - The iframe to use for the communication
|
|
55
|
+
* @returns The created Frak Client
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const frakConfig: FrakWalletSdkConfig = {
|
|
59
|
+
* metadata: {
|
|
60
|
+
* name: "My app title",
|
|
61
|
+
* },
|
|
62
|
+
* }
|
|
63
|
+
* const iframe = await createIframe({ config: frakConfig });
|
|
64
|
+
* const client = createIFrameFrakClient({ config: frakConfig, iframe });
|
|
65
|
+
*/
|
|
66
|
+
declare function createIFrameFrakClient({
|
|
67
|
+
config,
|
|
68
|
+
iframe
|
|
69
|
+
}: {
|
|
70
|
+
config: FrakWalletSdkConfig;
|
|
71
|
+
iframe: HTMLIFrameElement;
|
|
72
|
+
}): FrakClient;
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/clients/DebugInfo.d.ts
|
|
75
|
+
/** @ignore */
|
|
76
|
+
declare class DebugInfoGatherer {
|
|
77
|
+
private config?;
|
|
78
|
+
private iframe?;
|
|
79
|
+
private isSetupDone;
|
|
80
|
+
private lastResponse;
|
|
81
|
+
private lastRequest;
|
|
82
|
+
constructor(config?: FrakWalletSdkConfig, iframe?: HTMLIFrameElement);
|
|
83
|
+
setLastResponse(message: RpcMessage, response: RpcResponse): void;
|
|
84
|
+
setLastRequest(event: RpcMessage): void;
|
|
85
|
+
updateSetupStatus(status: boolean): void;
|
|
86
|
+
private base64Encode;
|
|
87
|
+
/**
|
|
88
|
+
* Extract information from the iframe status
|
|
89
|
+
*/
|
|
90
|
+
private getIframeStatus;
|
|
91
|
+
private getNavigatorInfo;
|
|
92
|
+
private gatherDebugInfo;
|
|
93
|
+
static empty(): DebugInfoGatherer;
|
|
94
|
+
/**
|
|
95
|
+
* Format Frak debug information
|
|
96
|
+
*/
|
|
97
|
+
formatDebugInfo(error: Error | unknown | string): string;
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/clients/setupClient.d.ts
|
|
101
|
+
/**
|
|
102
|
+
* Directly setup the Frak client with an iframe
|
|
103
|
+
* Return when the FrakClient is ready (setup and communication estbalished with the wallet)
|
|
104
|
+
*
|
|
105
|
+
* @param config - The configuration to use for the Frak Wallet SDK
|
|
106
|
+
* @returns a Promise with the Frak Client
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* const frakConfig: FrakWalletSdkConfig = {
|
|
110
|
+
* metadata: {
|
|
111
|
+
* name: "My app title",
|
|
112
|
+
* },
|
|
113
|
+
* }
|
|
114
|
+
* const client = await setupClient({ config: frakConfig });
|
|
115
|
+
*/
|
|
116
|
+
declare function setupClient({
|
|
117
|
+
config
|
|
118
|
+
}: {
|
|
119
|
+
config: FrakWalletSdkConfig;
|
|
120
|
+
}): Promise<FrakClient | undefined>;
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/constants/locales.d.ts
|
|
123
|
+
/**
|
|
124
|
+
* The keys for each locales
|
|
125
|
+
* @inline
|
|
126
|
+
*/
|
|
127
|
+
type LocalesKey = keyof typeof locales;
|
|
128
|
+
/**
|
|
129
|
+
* Map the currency to the locale
|
|
130
|
+
*/
|
|
131
|
+
declare const locales: {
|
|
132
|
+
readonly eur: "fr-FR";
|
|
133
|
+
readonly usd: "en-US";
|
|
134
|
+
readonly gbp: "en-GB";
|
|
135
|
+
};
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/utils/backendUrl.d.ts
|
|
138
|
+
/**
|
|
139
|
+
* Get the backend URL for API calls
|
|
140
|
+
* Tries to derive from SDK config, falls back to production
|
|
141
|
+
*
|
|
142
|
+
* @param walletUrl - Optional wallet URL to derive from (overrides global config)
|
|
143
|
+
*/
|
|
144
|
+
declare function getBackendUrl(walletUrl?: string): string;
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/utils/clientId.d.ts
|
|
147
|
+
/**
|
|
148
|
+
* Client ID utilities for anonymous tracking
|
|
149
|
+
* Generates and persists a UUID fingerprint for referral attribution
|
|
150
|
+
*/
|
|
151
|
+
/**
|
|
152
|
+
* Get the client ID from localStorage, creating one if it doesn't exist
|
|
153
|
+
* @returns The client ID (UUID format)
|
|
154
|
+
*/
|
|
155
|
+
declare function getClientId(): string;
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/utils/compression/b64.d.ts
|
|
158
|
+
/**
|
|
159
|
+
* Encode a buffer to a base64url encoded string
|
|
160
|
+
* @param buffer The buffer to encode
|
|
161
|
+
* @returns The encoded string
|
|
162
|
+
*/
|
|
163
|
+
declare function base64urlEncode(buffer: Uint8Array): string;
|
|
164
|
+
/**
|
|
165
|
+
* Decode a base64url encoded string
|
|
166
|
+
* @param value The value to decode
|
|
167
|
+
* @returns The decoded value
|
|
168
|
+
*/
|
|
169
|
+
declare function base64urlDecode(value: string): Uint8Array;
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/utils/compression/compress.d.ts
|
|
172
|
+
/**
|
|
173
|
+
* Compress json data
|
|
174
|
+
* @param data
|
|
175
|
+
* @ignore
|
|
176
|
+
*/
|
|
177
|
+
declare function compressJsonToB64(data: unknown): string;
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/utils/compression/decompress.d.ts
|
|
180
|
+
/**
|
|
181
|
+
* Decompress json data
|
|
182
|
+
* @param data
|
|
183
|
+
* @ignore
|
|
184
|
+
*/
|
|
185
|
+
declare function decompressJsonFromB64<T>(data: string): T | null;
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/utils/constants.d.ts
|
|
188
|
+
/**
|
|
189
|
+
* Deep link scheme for Frak Wallet mobile app
|
|
190
|
+
*/
|
|
191
|
+
declare const DEEP_LINK_SCHEME = "frakwallet://";
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/utils/deepLinkWithFallback.d.ts
|
|
194
|
+
/**
|
|
195
|
+
* Options for deep link with fallback
|
|
196
|
+
*/
|
|
197
|
+
type DeepLinkFallbackOptions = {
|
|
198
|
+
/** Timeout in ms before triggering fallback (default: 2500ms) */timeout?: number; /** Callback invoked when fallback is triggered (app not installed) */
|
|
199
|
+
onFallback?: () => void;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Check if running on a Chromium-based Android browser.
|
|
203
|
+
*
|
|
204
|
+
* On Chrome Android, custom scheme deep links (e.g. frakwallet://) trigger
|
|
205
|
+
* a confirmation bar ("Continue to Frak Wallet?"). Using intent:// URLs
|
|
206
|
+
* instead bypasses this for Chromium browsers while keeping custom scheme
|
|
207
|
+
* fallback for non-Chromium browsers (e.g. Firefox) where it works fine.
|
|
208
|
+
*/
|
|
209
|
+
declare function isChromiumAndroid(): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Convert a frakwallet:// deep link to an Android intent:// URL.
|
|
212
|
+
*
|
|
213
|
+
* Intent URLs let Chromium browsers open the app directly without
|
|
214
|
+
* showing the "Continue to app?" confirmation bar.
|
|
215
|
+
*
|
|
216
|
+
* Note: We intentionally omit the `package` parameter. Including it
|
|
217
|
+
* causes Chrome to redirect to the Play Store when the app is not
|
|
218
|
+
* installed, which breaks the visibility-based fallback detection.
|
|
219
|
+
* Without `package`, Chrome simply does nothing when the app is
|
|
220
|
+
* missing, allowing the fallback mechanism to fire correctly.
|
|
221
|
+
*
|
|
222
|
+
* Format: intent://path#Intent;scheme=frakwallet;end
|
|
223
|
+
*/
|
|
224
|
+
declare function toAndroidIntentUrl(deepLink: string): string;
|
|
225
|
+
/**
|
|
226
|
+
* Trigger a deep link with visibility-based fallback detection.
|
|
227
|
+
*
|
|
228
|
+
* Uses the Page Visibility API to detect if the app opened (page goes hidden).
|
|
229
|
+
* If the page remains visible after the timeout, assumes app is not installed
|
|
230
|
+
* and invokes the onFallback callback.
|
|
231
|
+
*
|
|
232
|
+
* On Chromium Android, converts custom scheme to intent:// URL to avoid
|
|
233
|
+
* the "Continue to app?" confirmation bar.
|
|
234
|
+
*
|
|
235
|
+
* @param deepLink - The deep link URL to trigger (e.g., "frakwallet://wallet")
|
|
236
|
+
* @param options - Optional configuration (timeout, onFallback callback)
|
|
237
|
+
*/
|
|
238
|
+
declare function triggerDeepLinkWithFallback(deepLink: string, options?: DeepLinkFallbackOptions): void;
|
|
239
|
+
/**
|
|
240
|
+
* Check if a URL is a Frak deep link
|
|
241
|
+
*/
|
|
242
|
+
declare function isFrakDeepLink(url: string): boolean;
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/utils/FrakContext.d.ts
|
|
245
|
+
/**
|
|
246
|
+
* Compress a Frak context into a URL-safe string.
|
|
247
|
+
*
|
|
248
|
+
* - V2 contexts are serialized as compressed JSON (base64url).
|
|
249
|
+
* - V1 contexts encode the wallet address as raw bytes (base64url).
|
|
250
|
+
*
|
|
251
|
+
* @param context - The context to compress (V1 or V2)
|
|
252
|
+
* @returns A compressed base64url string, or undefined on failure
|
|
253
|
+
*/
|
|
254
|
+
declare function compress(context?: FrakContextV1 | FrakContextV2): string | undefined;
|
|
255
|
+
/**
|
|
256
|
+
* Decompress a base64url string back into a Frak context.
|
|
257
|
+
*
|
|
258
|
+
* Attempts V2 JSON decompression first, then falls back to V1 raw bytes.
|
|
259
|
+
*
|
|
260
|
+
* @param context - The compressed context string
|
|
261
|
+
* @returns The decompressed FrakContext, or undefined on failure
|
|
262
|
+
*/
|
|
263
|
+
declare function decompress(context?: string): FrakContext | undefined;
|
|
264
|
+
/**
|
|
265
|
+
* Parse a URL to extract the Frak referral context from the `fCtx` query parameter.
|
|
266
|
+
*
|
|
267
|
+
* @param args
|
|
268
|
+
* @param args.url - The URL to parse
|
|
269
|
+
* @returns The parsed FrakContext, or null if absent
|
|
270
|
+
*/
|
|
271
|
+
declare function parse({
|
|
272
|
+
url
|
|
273
|
+
}: {
|
|
274
|
+
url: string;
|
|
275
|
+
}): FrakContext | null | undefined;
|
|
276
|
+
/**
|
|
277
|
+
* Add or replace the `fCtx` query parameter in a URL with the given context.
|
|
278
|
+
*
|
|
279
|
+
* @param args
|
|
280
|
+
* @param args.url - The URL to update
|
|
281
|
+
* @param args.context - The context to embed (V1 or V2)
|
|
282
|
+
* @returns The updated URL string, or null on failure
|
|
283
|
+
*/
|
|
284
|
+
declare function update({
|
|
285
|
+
url,
|
|
286
|
+
context
|
|
287
|
+
}: {
|
|
288
|
+
url?: string;
|
|
289
|
+
context: FrakContextV1 | FrakContextV2;
|
|
290
|
+
}): string | null;
|
|
291
|
+
/**
|
|
292
|
+
* Remove the `fCtx` query parameter from a URL.
|
|
293
|
+
*
|
|
294
|
+
* @param url - The URL to strip the context from
|
|
295
|
+
* @returns The cleaned URL string
|
|
296
|
+
*/
|
|
297
|
+
declare function remove(url: string): string;
|
|
298
|
+
/**
|
|
299
|
+
* Replace the current browser URL with an updated Frak context.
|
|
300
|
+
*
|
|
301
|
+
* - If `context` is non-null, embeds it via {@link update}.
|
|
302
|
+
* - If `context` is null, strips the context via {@link remove}.
|
|
303
|
+
*
|
|
304
|
+
* @param args
|
|
305
|
+
* @param args.url - Base URL (defaults to `window.location.href`)
|
|
306
|
+
* @param args.context - Context to set, or null to remove
|
|
307
|
+
*/
|
|
308
|
+
declare function replaceUrl({
|
|
309
|
+
url: baseUrl,
|
|
310
|
+
context
|
|
311
|
+
}: {
|
|
312
|
+
url?: string;
|
|
313
|
+
context: FrakContextV1 | FrakContextV2 | null;
|
|
314
|
+
}): void;
|
|
315
|
+
/**
|
|
316
|
+
* Manager for Frak referral context in URLs.
|
|
317
|
+
*
|
|
318
|
+
* Handles compression, decompression, URL parsing, and browser history updates
|
|
319
|
+
* for both V1 (wallet address) and V2 (anonymous clientId) referral contexts.
|
|
320
|
+
*/
|
|
321
|
+
declare const FrakContextManager: {
|
|
322
|
+
compress: typeof compress;
|
|
323
|
+
decompress: typeof decompress;
|
|
324
|
+
parse: typeof parse;
|
|
325
|
+
update: typeof update;
|
|
326
|
+
remove: typeof remove;
|
|
327
|
+
replaceUrl: typeof replaceUrl;
|
|
328
|
+
};
|
|
329
|
+
//#endregion
|
|
330
|
+
//#region src/utils/formatAmount.d.ts
|
|
331
|
+
/**
|
|
332
|
+
* Format a numeric amount as a localized currency string
|
|
333
|
+
* @param amount - The raw numeric amount to format
|
|
334
|
+
* @param currency - Optional currency config; defaults to EUR/fr-FR when omitted
|
|
335
|
+
* @returns Localized currency string (e.g. "1 500 €", "$1,500")
|
|
336
|
+
*/
|
|
337
|
+
declare function formatAmount(amount: number, currency?: Currency): string;
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/utils/getCurrencyAmountKey.d.ts
|
|
340
|
+
/**
|
|
341
|
+
* Get the currency amount key for a given currency
|
|
342
|
+
* @param currency - The currency to use
|
|
343
|
+
* @returns The currency amount key
|
|
344
|
+
*/
|
|
345
|
+
declare function getCurrencyAmountKey(currency?: Currency): keyof TokenAmountType;
|
|
346
|
+
//#endregion
|
|
347
|
+
//#region src/utils/getSupportedCurrency.d.ts
|
|
348
|
+
/**
|
|
349
|
+
* Get the supported currency for a given currency
|
|
350
|
+
* @param currency - The currency to use
|
|
351
|
+
* @returns The supported currency
|
|
352
|
+
*/
|
|
353
|
+
declare function getSupportedCurrency(currency?: Currency): Currency;
|
|
354
|
+
//#endregion
|
|
355
|
+
//#region src/utils/getSupportedLocale.d.ts
|
|
356
|
+
/**
|
|
357
|
+
* Get the supported locale for a given currency
|
|
358
|
+
* @param currency - The currency to use
|
|
359
|
+
* @returns The supported locale
|
|
360
|
+
*/
|
|
361
|
+
declare function getSupportedLocale(currency?: Currency): (typeof locales)[LocalesKey];
|
|
362
|
+
//#endregion
|
|
363
|
+
//#region src/utils/iframeHelper.d.ts
|
|
364
|
+
/**
|
|
365
|
+
* Base props for the iframe
|
|
366
|
+
* @ignore
|
|
367
|
+
*/
|
|
368
|
+
declare const baseIframeProps: {
|
|
369
|
+
id: string;
|
|
370
|
+
name: string;
|
|
371
|
+
title: string;
|
|
372
|
+
allow: string;
|
|
373
|
+
style: {
|
|
374
|
+
width: string;
|
|
375
|
+
height: string;
|
|
376
|
+
border: string;
|
|
377
|
+
position: string;
|
|
378
|
+
zIndex: number;
|
|
379
|
+
top: string;
|
|
380
|
+
left: string;
|
|
381
|
+
colorScheme: string;
|
|
382
|
+
};
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* Create the Frak iframe
|
|
386
|
+
* @param args
|
|
387
|
+
* @param args.walletBaseUrl - Use `config.walletUrl` instead. Will be removed in future versions.
|
|
388
|
+
* @param args.config - The configuration object containing iframe options, including the replacement for `walletBaseUrl`.
|
|
389
|
+
*/
|
|
390
|
+
declare function createIframe({
|
|
391
|
+
walletBaseUrl,
|
|
392
|
+
config
|
|
393
|
+
}: {
|
|
394
|
+
walletBaseUrl?: string;
|
|
395
|
+
config?: FrakWalletSdkConfig;
|
|
396
|
+
}): Promise<HTMLIFrameElement | undefined>;
|
|
397
|
+
/**
|
|
398
|
+
* Find an iframe within window.opener by pathname
|
|
399
|
+
*
|
|
400
|
+
* When a popup is opened via window.open from an iframe, window.opener points to
|
|
401
|
+
* the parent window, not the iframe itself. This utility searches through all frames
|
|
402
|
+
* in window.opener to find an iframe matching the specified pathname.
|
|
403
|
+
*
|
|
404
|
+
* @param pathname - The pathname to search for (default: "/listener")
|
|
405
|
+
* @returns The matching iframe window, or null if not found
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* ```typescript
|
|
409
|
+
* // Find the default /listener iframe
|
|
410
|
+
* const listenerIframe = findIframeInOpener();
|
|
411
|
+
*
|
|
412
|
+
* // Find a custom iframe
|
|
413
|
+
* const customIframe = findIframeInOpener("/my-custom-iframe");
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
declare function findIframeInOpener(pathname?: string): Window | null;
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region src/utils/merchantId.d.ts
|
|
419
|
+
/**
|
|
420
|
+
* Merchant ID utilities for auto-fetching from backend
|
|
421
|
+
*/
|
|
422
|
+
/**
|
|
423
|
+
* Fetch merchantId from backend by domain
|
|
424
|
+
*
|
|
425
|
+
* @param domain - The domain to lookup (defaults to current hostname)
|
|
426
|
+
* @param walletUrl - Optional wallet URL to derive backend URL
|
|
427
|
+
* @returns The merchantId if found, undefined otherwise
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```ts
|
|
431
|
+
* const merchantId = await fetchMerchantId("shop.example.com");
|
|
432
|
+
* if (merchantId) {
|
|
433
|
+
* // Use merchantId for tracking
|
|
434
|
+
* }
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
declare function fetchMerchantId(domain?: string, walletUrl?: string): Promise<string | undefined>;
|
|
438
|
+
/**
|
|
439
|
+
* Clear the cached merchantId
|
|
440
|
+
* Useful for testing or when switching domains
|
|
441
|
+
*/
|
|
442
|
+
declare function clearMerchantIdCache(): void;
|
|
443
|
+
/**
|
|
444
|
+
* Get merchantId from config or auto-fetch from backend
|
|
445
|
+
*
|
|
446
|
+
* @param config - The SDK config that may contain merchantId
|
|
447
|
+
* @param walletUrl - Optional wallet URL to derive backend URL
|
|
448
|
+
* @returns The merchantId if available (from config or fetch), undefined otherwise
|
|
449
|
+
*/
|
|
450
|
+
declare function resolveMerchantId(config: {
|
|
451
|
+
metadata?: {
|
|
452
|
+
merchantId?: string;
|
|
453
|
+
};
|
|
454
|
+
}, walletUrl?: string): Promise<string | undefined>;
|
|
455
|
+
//#endregion
|
|
456
|
+
//#region src/utils/sso.d.ts
|
|
457
|
+
type AppSpecificSsoMetadata = SsoMetadata & {
|
|
458
|
+
name: string;
|
|
459
|
+
css?: string;
|
|
460
|
+
};
|
|
461
|
+
/**
|
|
462
|
+
* The full SSO params that will be used for compression
|
|
463
|
+
*/
|
|
464
|
+
type FullSsoParams = Omit<PrepareSsoParamsType, "metadata"> & {
|
|
465
|
+
metadata: AppSpecificSsoMetadata;
|
|
466
|
+
merchantId: string;
|
|
467
|
+
clientId: string;
|
|
468
|
+
};
|
|
469
|
+
/**
|
|
470
|
+
* Generate SSO URL with compressed parameters
|
|
471
|
+
* This mirrors the wallet's getOpenSsoLink() function
|
|
472
|
+
*
|
|
473
|
+
* @param walletUrl - Base wallet URL (e.g., "https://wallet.frak.id")
|
|
474
|
+
* @param params - SSO parameters
|
|
475
|
+
* @param merchantId - Merchant identifier
|
|
476
|
+
* @param name - Application name
|
|
477
|
+
* @param clientId - Client identifier for identity tracking
|
|
478
|
+
* @param css - Optional custom CSS
|
|
479
|
+
* @returns Complete SSO URL ready to open in popup or redirect
|
|
480
|
+
*
|
|
481
|
+
* @example
|
|
482
|
+
* ```ts
|
|
483
|
+
* const ssoUrl = generateSsoUrl(
|
|
484
|
+
* "https://wallet.frak.id",
|
|
485
|
+
* { metadata: { logoUrl: "..." }, directExit: true },
|
|
486
|
+
* "0x123...",
|
|
487
|
+
* "My App"
|
|
488
|
+
* );
|
|
489
|
+
* // Returns: https://wallet.frak.id/sso?p=<compressed_base64>
|
|
490
|
+
* ```
|
|
491
|
+
*/
|
|
492
|
+
declare function generateSsoUrl(walletUrl: string, params: PrepareSsoParamsType, merchantId: string, name: string, clientId: string, css?: string): string;
|
|
493
|
+
/**
|
|
494
|
+
* Type of compressed the sso data
|
|
495
|
+
*/
|
|
496
|
+
type CompressedSsoData = {
|
|
497
|
+
id?: Hex;
|
|
498
|
+
cId: string;
|
|
499
|
+
r?: string;
|
|
500
|
+
d?: boolean;
|
|
501
|
+
l?: "en" | "fr";
|
|
502
|
+
m: string;
|
|
503
|
+
md: {
|
|
504
|
+
n: string;
|
|
505
|
+
css?: string;
|
|
506
|
+
l?: string;
|
|
507
|
+
h?: string;
|
|
508
|
+
};
|
|
509
|
+
};
|
|
510
|
+
//#endregion
|
|
511
|
+
//#region src/utils/trackEvent.d.ts
|
|
512
|
+
/**
|
|
513
|
+
* Analytics event names emitted by the SDK
|
|
514
|
+
*/
|
|
515
|
+
type FrakEvent = "share_button_clicked" | "wallet_button_clicked" | "open_in_app_clicked" | "open_in_app_login_clicked" | "app_not_installed" | "share_modal_error" | "user_referred_started" | "user_referred_completed" | "user_referred_error";
|
|
516
|
+
type EventProps = Record<string, unknown>;
|
|
517
|
+
/**
|
|
518
|
+
* Track an analytics event via OpenPanel.
|
|
519
|
+
* Fire-and-forget: silently catches errors.
|
|
520
|
+
* @param client - The Frak client instance (no-op if undefined)
|
|
521
|
+
* @param event - The event name to track
|
|
522
|
+
* @param props - Optional event properties
|
|
523
|
+
*/
|
|
524
|
+
declare function trackEvent(client: FrakClient | undefined, event: FrakEvent, props?: EventProps): void;
|
|
525
|
+
//#endregion
|
|
526
|
+
//#region src/utils/computeLegacyProductId.d.ts
|
|
527
|
+
/**
|
|
528
|
+
* Compute the legacy product id from a domain
|
|
529
|
+
* @ignore
|
|
530
|
+
*/
|
|
531
|
+
declare function computeLegacyProductId({
|
|
532
|
+
domain
|
|
533
|
+
}?: {
|
|
534
|
+
domain?: string;
|
|
535
|
+
}): `0x${string}`;
|
|
536
|
+
//#endregion
|
|
537
|
+
export { getBackendUrl as A, HashProtectedData as B, triggerDeepLinkWithFallback as C, base64urlDecode as D, compressJsonToB64 as E, createIFrameFrakClient as F, TrackArrivalParams as I, TrackArrivalResult as L, locales as M, setupClient as N, base64urlEncode as O, DebugInfoGatherer as P, UtmParams as R, toAndroidIntentUrl as S, decompressJsonFromB64 as T, KeyProvider as V, formatAmount as _, CompressedSsoData as a, isChromiumAndroid as b, clearMerchantIdCache as c, baseIframeProps as d, createIframe as f, getCurrencyAmountKey as g, getSupportedCurrency as h, AppSpecificSsoMetadata as i, LocalesKey as j, getClientId as k, fetchMerchantId as l, getSupportedLocale as m, FrakEvent as n, FullSsoParams as o, findIframeInOpener as p, trackEvent as r, generateSsoUrl as s, computeLegacyProductId as t, resolveMerchantId as u, FrakContextManager as v, DEEP_LINK_SCHEME as w, isFrakDeepLink as x, DeepLinkFallbackOptions as y, CompressedData as z };
|