@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.
Files changed (74) hide show
  1. package/README.md +1 -2
  2. package/cdn/bundle.js +55 -3
  3. package/dist/actions.cjs +1 -1
  4. package/dist/actions.d.cts +3 -3
  5. package/dist/actions.d.ts +3 -3
  6. package/dist/actions.js +1 -1
  7. package/dist/bundle.cjs +1 -1
  8. package/dist/bundle.d.cts +4 -4
  9. package/dist/bundle.d.ts +4 -4
  10. package/dist/bundle.js +1 -1
  11. package/dist/{computeLegacyProductId-CCAZvLa5.d.cts → computeLegacyProductId-fKvxbC4k.d.ts} +91 -37
  12. package/dist/{computeLegacyProductId-b5cUWdAm.d.ts → computeLegacyProductId-rYIvY4c3.d.cts} +91 -37
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.d.cts +3 -3
  15. package/dist/index.d.ts +3 -3
  16. package/dist/index.js +1 -1
  17. package/dist/{openSso-B0g7-807.d.cts → openSso-CMZM06uR.d.ts} +258 -46
  18. package/dist/{openSso-CMzwvaCa.d.ts → openSso-CebB8mFv.d.cts} +258 -46
  19. package/dist/setupClient-B_XMB52l.cjs +13 -0
  20. package/dist/setupClient-jYx-fbxB.js +13 -0
  21. package/dist/siweAuthenticate-CWcVvP-G.cjs +1 -0
  22. package/dist/siweAuthenticate-DQfdb5UQ.js +1 -0
  23. package/dist/{siweAuthenticate-CnCZ7mok.d.ts → siweAuthenticate-Dc_Yg9Bg.d.cts} +102 -8
  24. package/dist/{siweAuthenticate-CVigMOxz.d.cts → siweAuthenticate-Ddhl-o4N.d.ts} +102 -8
  25. package/dist/trackEvent-Ce1XlsIE.js +1 -0
  26. package/dist/trackEvent-CvbJTTqA.cjs +1 -0
  27. package/package.json +8 -8
  28. package/src/actions/displayEmbeddedWallet.ts +6 -2
  29. package/src/actions/displayModal.ts +6 -2
  30. package/src/actions/displaySharingPage.ts +49 -0
  31. package/src/actions/ensureIdentity.ts +2 -2
  32. package/src/actions/getMerchantInformation.test.ts +13 -1
  33. package/src/actions/getMerchantInformation.ts +20 -5
  34. package/src/actions/getUserReferralStatus.ts +42 -0
  35. package/src/actions/index.ts +7 -1
  36. package/src/actions/referral/setupReferral.test.ts +79 -0
  37. package/src/actions/referral/setupReferral.ts +32 -0
  38. package/src/actions/trackPurchaseStatus.test.ts +32 -20
  39. package/src/actions/trackPurchaseStatus.ts +3 -5
  40. package/src/actions/wrapper/modalBuilder.test.ts +4 -2
  41. package/src/actions/wrapper/modalBuilder.ts +6 -8
  42. package/src/clients/createIFrameFrakClient.ts +148 -25
  43. package/src/clients/transports/iframeLifecycleManager.test.ts +0 -80
  44. package/src/clients/transports/iframeLifecycleManager.ts +0 -44
  45. package/src/index.ts +17 -4
  46. package/src/types/config.ts +10 -3
  47. package/src/types/index.ts +13 -1
  48. package/src/types/lifecycle/client.ts +22 -27
  49. package/src/types/lifecycle/iframe.ts +0 -8
  50. package/src/types/resolvedConfig.ts +122 -0
  51. package/src/types/rpc/displaySharingPage.ts +77 -0
  52. package/src/types/rpc/interaction.ts +4 -0
  53. package/src/types/rpc/userReferralStatus.ts +20 -0
  54. package/src/types/rpc.ts +42 -5
  55. package/src/utils/backendUrl.test.ts +2 -2
  56. package/src/utils/backendUrl.ts +1 -1
  57. package/src/utils/cache/index.ts +7 -0
  58. package/src/utils/cache/lruMap.test.ts +55 -0
  59. package/src/utils/cache/lruMap.ts +38 -0
  60. package/src/utils/cache/withCache.test.ts +162 -0
  61. package/src/utils/cache/withCache.ts +105 -0
  62. package/src/utils/inAppBrowser.ts +60 -0
  63. package/src/utils/index.ts +6 -4
  64. package/src/utils/sdkConfigStore.test.ts +405 -0
  65. package/src/utils/sdkConfigStore.ts +263 -0
  66. package/src/utils/sso.ts +3 -7
  67. package/dist/setupClient-CqTHGvVa.cjs +0 -13
  68. package/dist/setupClient-DTyvAPgh.js +0 -13
  69. package/dist/siweAuthenticate-BWmI2_TN.cjs +0 -1
  70. package/dist/siweAuthenticate-zczqxm0a.js +0 -1
  71. package/dist/trackEvent-CeLFVzZn.js +0 -1
  72. package/dist/trackEvent-Ew5r5zfI.cjs +0 -1
  73. package/src/utils/merchantId.test.ts +0 -653
  74. package/src/utils/merchantId.ts +0 -143
@@ -1,13 +1,14 @@
1
- import { A as SendTransactionModalStepType, B as PrepareSsoReturnType, E as ModalRpcMetadata, F as SiweAuthenticationParams, H as FinalActionType, I as LoginModalStepType, O as ModalRpcStepsResultType, P as SiweAuthenticateReturnType, T as DisplayModalParamsType, U as FinalModalStepType, b as DisplayEmbeddedWalletResultType, h as GetMerchantInformationReturnType, i as FrakContext, j as SendTransactionReturnType, k as ModalStepTypes, l as FrakClient, p as WalletStatusReturnType, v as SendInteractionParamsType, y as DisplayEmbeddedWalletParamsType, z as PrepareSsoParamsType } from "./openSso-CMzwvaCa.js";
1
+ import { A as ModalRpcMetadata, B as LoginModalStepType, D as DisplaySharingPageResultType, E as DisplaySharingPageParamsType, F as SendTransactionReturnType, K as FinalActionType, M as ModalRpcStepsResultType, N as ModalStepTypes, P as SendTransactionModalStepType, R as SiweAuthenticateReturnType, U as PrepareSsoParamsType, W as PrepareSsoReturnType, b as DisplayEmbeddedWalletParamsType, g as GetMerchantInformationReturnType, i as FrakContext, k as DisplayModalParamsType, l as FrakClient, m as UserReferralStatusType, p as WalletStatusReturnType, q as FinalModalStepType, x as DisplayEmbeddedWalletResultType, y as SendInteractionParamsType, z as SiweAuthenticationParams } from "./openSso-CebB8mFv.cjs";
2
2
 
3
3
  //#region src/actions/displayEmbeddedWallet.d.ts
4
4
  /**
5
5
  * Function used to display the Frak embedded wallet popup
6
6
  * @param client - The current Frak Client
7
7
  * @param params - The parameter used to customise the embedded wallet
8
+ * @param placement - Optional placement ID to associate with this display request
8
9
  * @returns The embedded wallet display result
9
10
  */
10
- declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbeddedWalletParamsType): Promise<DisplayEmbeddedWalletResultType>;
11
+ declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbeddedWalletParamsType, placement?: string): Promise<DisplayEmbeddedWalletResultType>;
11
12
  //#endregion
12
13
  //#region src/actions/displayModal.d.ts
13
14
  /**
@@ -16,6 +17,7 @@ declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbedd
16
17
  * @param args
17
18
  * @param args.steps - The different steps of the modal
18
19
  * @param args.metadata - The metadata for the modal (customization, etc)
20
+ * @param placement - Optional placement ID to associate with this modal display
19
21
  * @returns The result of each modal steps
20
22
  *
21
23
  * @description This function will display a modal to the user with the provided steps and metadata.
@@ -115,7 +117,41 @@ declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbedd
115
117
  declare function displayModal<T extends ModalStepTypes[] = ModalStepTypes[]>(client: FrakClient, {
116
118
  steps,
117
119
  metadata
118
- }: DisplayModalParamsType<T>): Promise<ModalRpcStepsResultType<T>>;
120
+ }: DisplayModalParamsType<T>, placement?: string): Promise<ModalRpcStepsResultType<T>>;
121
+ //#endregion
122
+ //#region src/actions/displaySharingPage.d.ts
123
+ /**
124
+ * Function used to display a sharing page
125
+ * @param client - The current Frak Client
126
+ * @param params - The parameters to customize the sharing page (products, link override, metadata)
127
+ * @param placement - Optional placement ID to associate with this display request
128
+ * @returns The result indicating the user's action (shared, copied, or dismissed)
129
+ *
130
+ * @description This function will display a full-page sharing UI to the user,
131
+ * showing product info, estimated rewards, sharing steps, FAQ, and share/copy buttons.
132
+ * The sharing link is generated from the user's wallet context + merchant info.
133
+ *
134
+ * @remarks
135
+ * - The promise resolves on the first user action (share or copy) but the page stays visible
136
+ * - The user can continue to share/copy multiple times after the initial resolution
137
+ * - Dismissing the page after a share/copy action is a no-op (promise already resolved)
138
+ * - If the user dismisses without any action, the promise resolves with `{ action: "dismissed" }`
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * const result = await displaySharingPage(frakClient, {
143
+ * products: [
144
+ * {
145
+ * title: "Babies camel cuir velours bout carré",
146
+ * imageUrl: "https://example.com/product.jpg",
147
+ * },
148
+ * ],
149
+ * });
150
+ *
151
+ * console.log("User action:", result.action); // "shared" | "copied" | "dismissed"
152
+ * ```
153
+ */
154
+ declare function displaySharingPage(client: FrakClient, params: DisplaySharingPageParamsType, placement?: string): Promise<DisplaySharingPageResultType>;
119
155
  //#endregion
120
156
  //#region src/actions/ensureIdentity.d.ts
121
157
  /**
@@ -144,13 +180,50 @@ declare function ensureIdentity(interactionToken: string): Promise<void>;
144
180
  //#endregion
145
181
  //#region src/actions/getMerchantInformation.d.ts
146
182
  /**
147
- * Fetch the current merchant information (name, rewards, tiers) from the wallet iframe
183
+ * Fetch the current merchant information (name, rewards, tiers) from the wallet iframe.
184
+ *
185
+ * Results are cached in memory for 30 seconds by default. Concurrent calls
186
+ * while a request is in-flight are deduplicated automatically.
187
+ *
148
188
  * @param client - The current Frak Client
189
+ * @param options - Optional cache configuration
190
+ * @param options.cacheTime - Time in ms to cache the result. Default: 30_000 (30s). Set to 0 to disable.
149
191
  * @returns The merchant information including available reward tiers
150
192
  *
151
193
  * @see {@link @frak-labs/core-sdk!index.GetMerchantInformationReturnType | `GetMerchantInformationReturnType`} for the return type shape
152
194
  */
153
- declare function getMerchantInformation(client: FrakClient): Promise<GetMerchantInformationReturnType>;
195
+ declare function getMerchantInformation(client: FrakClient, options?: {
196
+ cacheTime?: number;
197
+ }): Promise<GetMerchantInformationReturnType>;
198
+ //#endregion
199
+ //#region src/actions/getUserReferralStatus.d.ts
200
+ /**
201
+ * Fetch the current user's referral status on the current merchant.
202
+ *
203
+ * The listener resolves the user's identity (via clientId or wallet session)
204
+ * and checks whether a referral link exists where the user is the referee.
205
+ *
206
+ * Results are cached in memory for 30 seconds by default. Concurrent calls
207
+ * while a request is in-flight are deduplicated automatically.
208
+ *
209
+ * Returns `null` when the user's identity cannot be resolved.
210
+ *
211
+ * @param client - The current Frak Client
212
+ * @param options - Optional cache configuration
213
+ * @param options.cacheTime - Time in ms to cache the result. Default: 30_000 (30s). Set to 0 to disable.
214
+ * @returns The user's referral status, or `null` if identity cannot be resolved
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * const status = await getUserReferralStatus(client);
219
+ * if (status?.isReferred) {
220
+ * console.log("User was referred to this merchant");
221
+ * }
222
+ * ```
223
+ */
224
+ declare function getUserReferralStatus(client: FrakClient, options?: {
225
+ cacheTime?: number;
226
+ }): Promise<UserReferralStatusType | null>;
154
227
  //#endregion
155
228
  //#region src/actions/prepareSso.d.ts
156
229
  /**
@@ -256,6 +329,26 @@ declare function referralInteraction(client: FrakClient, {
256
329
  options?: ProcessReferralOptions;
257
330
  }): Promise<("idle" | "processing" | "success" | "no-referrer" | "self-referral") | undefined>;
258
331
  //#endregion
332
+ //#region src/actions/referral/setupReferral.d.ts
333
+ /**
334
+ * Custom event name dispatched on successful referral processing.
335
+ *
336
+ * Fired once per page load when a valid referral context is found in the URL
337
+ * and successfully tracked. Consumers (e.g. `<frak-banner>`) listen for this
338
+ * to display a referral success message.
339
+ */
340
+ declare const REFERRAL_SUCCESS_EVENT = "frak:referral-success";
341
+ /**
342
+ * Process referral context and emit a DOM event on success.
343
+ *
344
+ * - Calls {@link referralInteraction} to detect and track any referral in the URL
345
+ * - On `"success"`, dispatches a bare {@link REFERRAL_SUCCESS_EVENT} on `window`
346
+ * - Silently swallows errors (fire-and-forget during SDK init)
347
+ *
348
+ * @param client - The initialized Frak client
349
+ */
350
+ declare function setupReferral(client: FrakClient): Promise<void>;
351
+ //#endregion
259
352
  //#region src/actions/sendInteraction.d.ts
260
353
  /**
261
354
  * Send an interaction to the backend via the listener RPC.
@@ -322,7 +415,7 @@ declare function sendInteraction(client: FrakClient, params: SendInteractionPara
322
415
  * }
323
416
  *
324
417
  * @remarks
325
- * - Merchant id is resolved in this order: explicit `args.merchantId`, `frak-merchant-id` from session storage, then `fetchMerchantId()`.
418
+ * - Merchant id is resolved in this order: explicit `args.merchantId`, then `sdkConfigStore.resolveMerchantId()` (config store sessionStorage → backend fetch).
326
419
  * - This function supports anonymous users and will use the `x-frak-client-id` header when available.
327
420
  * - At least one identity source must exist (`frak-wallet-interaction-token` or `x-frak-client-id`), otherwise the tracking request is skipped.
328
421
  * - This function will print a warning if used in a non-browser environment or if no identity / merchant id can be resolved.
@@ -380,8 +473,9 @@ type ModalStepBuilder<Steps extends ModalStepTypes[] = ModalStepTypes[]> = {
380
473
  /**
381
474
  * Display the modal
382
475
  * @param metadataOverride - Function returning optional metadata to override the current modal metadata
476
+ * @param placement - Optional placement ID to associate with this modal display
383
477
  */
384
- display: (metadataOverride?: (current?: ModalRpcMetadata) => ModalRpcMetadata | undefined) => Promise<ModalRpcStepsResultType<Steps>>;
478
+ display: (metadataOverride?: (current?: ModalRpcMetadata) => ModalRpcMetadata | undefined, placement?: string) => Promise<ModalRpcStepsResultType<Steps>>;
385
479
  };
386
480
  /**
387
481
  * Represent the output type of the modal builder
@@ -529,4 +623,4 @@ declare function siweAuthenticate(client: FrakClient, {
529
623
  metadata
530
624
  }: SiweAuthenticateModalParams): Promise<SiweAuthenticateReturnType>;
531
625
  //#endregion
532
- export { displayModal as _, ModalBuilder as a, watchWalletStatus as c, referralInteraction as d, ProcessReferralOptions as f, ensureIdentity as g, getMerchantInformation as h, sendTransaction as i, trackPurchaseStatus as l, prepareSso as m, siweAuthenticate as n, ModalStepBuilder as o, processReferral as p, SendTransactionParams as r, modalBuilder as s, SiweAuthenticateModalParams as t, sendInteraction as u, displayEmbeddedWallet as v };
626
+ export { displayEmbeddedWallet as S, getUserReferralStatus as _, ModalBuilder as a, displaySharingPage as b, watchWalletStatus as c, REFERRAL_SUCCESS_EVENT as d, setupReferral as f, prepareSso as g, processReferral as h, sendTransaction as i, trackPurchaseStatus as l, ProcessReferralOptions as m, siweAuthenticate as n, ModalStepBuilder as o, referralInteraction as p, SendTransactionParams as r, modalBuilder as s, SiweAuthenticateModalParams as t, sendInteraction as u, getMerchantInformation as v, displayModal as x, ensureIdentity as y };
@@ -1,13 +1,14 @@
1
- import { A as SendTransactionModalStepType, B as PrepareSsoReturnType, E as ModalRpcMetadata, F as SiweAuthenticationParams, H as FinalActionType, I as LoginModalStepType, O as ModalRpcStepsResultType, P as SiweAuthenticateReturnType, T as DisplayModalParamsType, U as FinalModalStepType, b as DisplayEmbeddedWalletResultType, h as GetMerchantInformationReturnType, i as FrakContext, j as SendTransactionReturnType, k as ModalStepTypes, l as FrakClient, p as WalletStatusReturnType, v as SendInteractionParamsType, y as DisplayEmbeddedWalletParamsType, z as PrepareSsoParamsType } from "./openSso-B0g7-807.cjs";
1
+ import { A as ModalRpcMetadata, B as LoginModalStepType, D as DisplaySharingPageResultType, E as DisplaySharingPageParamsType, F as SendTransactionReturnType, K as FinalActionType, M as ModalRpcStepsResultType, N as ModalStepTypes, P as SendTransactionModalStepType, R as SiweAuthenticateReturnType, U as PrepareSsoParamsType, W as PrepareSsoReturnType, b as DisplayEmbeddedWalletParamsType, g as GetMerchantInformationReturnType, i as FrakContext, k as DisplayModalParamsType, l as FrakClient, m as UserReferralStatusType, p as WalletStatusReturnType, q as FinalModalStepType, x as DisplayEmbeddedWalletResultType, y as SendInteractionParamsType, z as SiweAuthenticationParams } from "./openSso-CMZM06uR.js";
2
2
 
3
3
  //#region src/actions/displayEmbeddedWallet.d.ts
4
4
  /**
5
5
  * Function used to display the Frak embedded wallet popup
6
6
  * @param client - The current Frak Client
7
7
  * @param params - The parameter used to customise the embedded wallet
8
+ * @param placement - Optional placement ID to associate with this display request
8
9
  * @returns The embedded wallet display result
9
10
  */
10
- declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbeddedWalletParamsType): Promise<DisplayEmbeddedWalletResultType>;
11
+ declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbeddedWalletParamsType, placement?: string): Promise<DisplayEmbeddedWalletResultType>;
11
12
  //#endregion
12
13
  //#region src/actions/displayModal.d.ts
13
14
  /**
@@ -16,6 +17,7 @@ declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbedd
16
17
  * @param args
17
18
  * @param args.steps - The different steps of the modal
18
19
  * @param args.metadata - The metadata for the modal (customization, etc)
20
+ * @param placement - Optional placement ID to associate with this modal display
19
21
  * @returns The result of each modal steps
20
22
  *
21
23
  * @description This function will display a modal to the user with the provided steps and metadata.
@@ -115,7 +117,41 @@ declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbedd
115
117
  declare function displayModal<T extends ModalStepTypes[] = ModalStepTypes[]>(client: FrakClient, {
116
118
  steps,
117
119
  metadata
118
- }: DisplayModalParamsType<T>): Promise<ModalRpcStepsResultType<T>>;
120
+ }: DisplayModalParamsType<T>, placement?: string): Promise<ModalRpcStepsResultType<T>>;
121
+ //#endregion
122
+ //#region src/actions/displaySharingPage.d.ts
123
+ /**
124
+ * Function used to display a sharing page
125
+ * @param client - The current Frak Client
126
+ * @param params - The parameters to customize the sharing page (products, link override, metadata)
127
+ * @param placement - Optional placement ID to associate with this display request
128
+ * @returns The result indicating the user's action (shared, copied, or dismissed)
129
+ *
130
+ * @description This function will display a full-page sharing UI to the user,
131
+ * showing product info, estimated rewards, sharing steps, FAQ, and share/copy buttons.
132
+ * The sharing link is generated from the user's wallet context + merchant info.
133
+ *
134
+ * @remarks
135
+ * - The promise resolves on the first user action (share or copy) but the page stays visible
136
+ * - The user can continue to share/copy multiple times after the initial resolution
137
+ * - Dismissing the page after a share/copy action is a no-op (promise already resolved)
138
+ * - If the user dismisses without any action, the promise resolves with `{ action: "dismissed" }`
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * const result = await displaySharingPage(frakClient, {
143
+ * products: [
144
+ * {
145
+ * title: "Babies camel cuir velours bout carré",
146
+ * imageUrl: "https://example.com/product.jpg",
147
+ * },
148
+ * ],
149
+ * });
150
+ *
151
+ * console.log("User action:", result.action); // "shared" | "copied" | "dismissed"
152
+ * ```
153
+ */
154
+ declare function displaySharingPage(client: FrakClient, params: DisplaySharingPageParamsType, placement?: string): Promise<DisplaySharingPageResultType>;
119
155
  //#endregion
120
156
  //#region src/actions/ensureIdentity.d.ts
121
157
  /**
@@ -144,13 +180,50 @@ declare function ensureIdentity(interactionToken: string): Promise<void>;
144
180
  //#endregion
145
181
  //#region src/actions/getMerchantInformation.d.ts
146
182
  /**
147
- * Fetch the current merchant information (name, rewards, tiers) from the wallet iframe
183
+ * Fetch the current merchant information (name, rewards, tiers) from the wallet iframe.
184
+ *
185
+ * Results are cached in memory for 30 seconds by default. Concurrent calls
186
+ * while a request is in-flight are deduplicated automatically.
187
+ *
148
188
  * @param client - The current Frak Client
189
+ * @param options - Optional cache configuration
190
+ * @param options.cacheTime - Time in ms to cache the result. Default: 30_000 (30s). Set to 0 to disable.
149
191
  * @returns The merchant information including available reward tiers
150
192
  *
151
193
  * @see {@link @frak-labs/core-sdk!index.GetMerchantInformationReturnType | `GetMerchantInformationReturnType`} for the return type shape
152
194
  */
153
- declare function getMerchantInformation(client: FrakClient): Promise<GetMerchantInformationReturnType>;
195
+ declare function getMerchantInformation(client: FrakClient, options?: {
196
+ cacheTime?: number;
197
+ }): Promise<GetMerchantInformationReturnType>;
198
+ //#endregion
199
+ //#region src/actions/getUserReferralStatus.d.ts
200
+ /**
201
+ * Fetch the current user's referral status on the current merchant.
202
+ *
203
+ * The listener resolves the user's identity (via clientId or wallet session)
204
+ * and checks whether a referral link exists where the user is the referee.
205
+ *
206
+ * Results are cached in memory for 30 seconds by default. Concurrent calls
207
+ * while a request is in-flight are deduplicated automatically.
208
+ *
209
+ * Returns `null` when the user's identity cannot be resolved.
210
+ *
211
+ * @param client - The current Frak Client
212
+ * @param options - Optional cache configuration
213
+ * @param options.cacheTime - Time in ms to cache the result. Default: 30_000 (30s). Set to 0 to disable.
214
+ * @returns The user's referral status, or `null` if identity cannot be resolved
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * const status = await getUserReferralStatus(client);
219
+ * if (status?.isReferred) {
220
+ * console.log("User was referred to this merchant");
221
+ * }
222
+ * ```
223
+ */
224
+ declare function getUserReferralStatus(client: FrakClient, options?: {
225
+ cacheTime?: number;
226
+ }): Promise<UserReferralStatusType | null>;
154
227
  //#endregion
155
228
  //#region src/actions/prepareSso.d.ts
156
229
  /**
@@ -256,6 +329,26 @@ declare function referralInteraction(client: FrakClient, {
256
329
  options?: ProcessReferralOptions;
257
330
  }): Promise<("idle" | "processing" | "success" | "no-referrer" | "self-referral") | undefined>;
258
331
  //#endregion
332
+ //#region src/actions/referral/setupReferral.d.ts
333
+ /**
334
+ * Custom event name dispatched on successful referral processing.
335
+ *
336
+ * Fired once per page load when a valid referral context is found in the URL
337
+ * and successfully tracked. Consumers (e.g. `<frak-banner>`) listen for this
338
+ * to display a referral success message.
339
+ */
340
+ declare const REFERRAL_SUCCESS_EVENT = "frak:referral-success";
341
+ /**
342
+ * Process referral context and emit a DOM event on success.
343
+ *
344
+ * - Calls {@link referralInteraction} to detect and track any referral in the URL
345
+ * - On `"success"`, dispatches a bare {@link REFERRAL_SUCCESS_EVENT} on `window`
346
+ * - Silently swallows errors (fire-and-forget during SDK init)
347
+ *
348
+ * @param client - The initialized Frak client
349
+ */
350
+ declare function setupReferral(client: FrakClient): Promise<void>;
351
+ //#endregion
259
352
  //#region src/actions/sendInteraction.d.ts
260
353
  /**
261
354
  * Send an interaction to the backend via the listener RPC.
@@ -322,7 +415,7 @@ declare function sendInteraction(client: FrakClient, params: SendInteractionPara
322
415
  * }
323
416
  *
324
417
  * @remarks
325
- * - Merchant id is resolved in this order: explicit `args.merchantId`, `frak-merchant-id` from session storage, then `fetchMerchantId()`.
418
+ * - Merchant id is resolved in this order: explicit `args.merchantId`, then `sdkConfigStore.resolveMerchantId()` (config store sessionStorage → backend fetch).
326
419
  * - This function supports anonymous users and will use the `x-frak-client-id` header when available.
327
420
  * - At least one identity source must exist (`frak-wallet-interaction-token` or `x-frak-client-id`), otherwise the tracking request is skipped.
328
421
  * - This function will print a warning if used in a non-browser environment or if no identity / merchant id can be resolved.
@@ -380,8 +473,9 @@ type ModalStepBuilder<Steps extends ModalStepTypes[] = ModalStepTypes[]> = {
380
473
  /**
381
474
  * Display the modal
382
475
  * @param metadataOverride - Function returning optional metadata to override the current modal metadata
476
+ * @param placement - Optional placement ID to associate with this modal display
383
477
  */
384
- display: (metadataOverride?: (current?: ModalRpcMetadata) => ModalRpcMetadata | undefined) => Promise<ModalRpcStepsResultType<Steps>>;
478
+ display: (metadataOverride?: (current?: ModalRpcMetadata) => ModalRpcMetadata | undefined, placement?: string) => Promise<ModalRpcStepsResultType<Steps>>;
385
479
  };
386
480
  /**
387
481
  * Represent the output type of the modal builder
@@ -529,4 +623,4 @@ declare function siweAuthenticate(client: FrakClient, {
529
623
  metadata
530
624
  }: SiweAuthenticateModalParams): Promise<SiweAuthenticateReturnType>;
531
625
  //#endregion
532
- export { displayModal as _, ModalBuilder as a, watchWalletStatus as c, referralInteraction as d, ProcessReferralOptions as f, ensureIdentity as g, getMerchantInformation as h, sendTransaction as i, trackPurchaseStatus as l, prepareSso as m, siweAuthenticate as n, ModalStepBuilder as o, processReferral as p, SendTransactionParams as r, modalBuilder as s, SiweAuthenticateModalParams as t, sendInteraction as u, displayEmbeddedWallet as v };
626
+ export { displayEmbeddedWallet as S, getUserReferralStatus as _, ModalBuilder as a, displaySharingPage as b, watchWalletStatus as c, REFERRAL_SUCCESS_EVENT as d, setupReferral as f, prepareSso as g, processReferral as h, sendTransaction as i, trackPurchaseStatus as l, ProcessReferralOptions as m, siweAuthenticate as n, ModalStepBuilder as o, referralInteraction as p, SendTransactionParams as r, modalBuilder as s, SiweAuthenticateModalParams as t, sendInteraction as u, getMerchantInformation as v, displayModal as x, ensureIdentity as y };
@@ -0,0 +1 @@
1
+ import{bytesToHex as e,hexToBytes as t,isAddress as n,keccak256 as r,toHex as i}from"viem";import{jsonDecode as a,jsonEncode as o}from"@frak-labs/frame-connector";const s=`frak-client-id`;function c(){return typeof crypto<`u`&&crypto.randomUUID?crypto.randomUUID():`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)})}function l(){if(typeof window>`u`||!window.localStorage)return console.warn(`[Frak SDK] No Window / localStorage available to save the clientId`),c();let e=localStorage.getItem(s);return e||(e=c(),localStorage.setItem(s,e)),e}function u({domain:e}={}){return r(i((e??window.location.host).replace(`www.`,``)))}function d(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function f(e){let t=e.length%4;return Uint8Array.from(atob(e.replace(/-/g,`+`).replace(/_/g,`/`).padEnd(e.length+(t===0?0:4-t),`=`)),e=>e.charCodeAt(0))}function p(e){return d(o(e))}function m(e,t,n,r,i,a){let o=p(ee({redirectUrl:t.redirectUrl,directExit:t.directExit,lang:t.lang,merchantId:n,metadata:{name:r,css:a,logoUrl:t.metadata?.logoUrl,homepageLink:t.metadata?.homepageLink},clientId:i})),s=new URL(e);return s.pathname=`/sso`,s.searchParams.set(`p`,o),s.toString()}function ee(e){return{r:e.redirectUrl,cId:e.clientId,d:e.directExit,l:e.lang,m:e.merchantId,md:{n:e.metadata?.name,css:e.metadata?.css,l:e.metadata?.logoUrl,h:e.metadata?.homepageLink}}}const h=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,g=`frak-sso`;async function _(e,t){let{metadata:n,customizations:r,walletUrl:i}=e.config;if(t.openInSameWindow??!!t.redirectUrl)return await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]});let a=t.ssoPopupUrl??m(i??`https://wallet.frak.id`,t,u(),n.name,l(),r?.css),o=window.open(a,g,h);if(!o)throw Error(`Popup was blocked. Please allow popups for this site.`);return o.focus(),await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]})??{}}const v=`https://backend.frak.id`;function y(e){return e.includes(`localhost:3000`)||e.includes(`localhost:3010`)}function b(e){return y(e)?`https://localhost:3030`:e.includes(`wallet-dev.frak.id`)||e.includes(`wallet.gcp-dev.frak.id`)?`https://backend.gcp-dev.frak.id`:v}function x(e){if(e)return b(e);if(typeof window<`u`){let e=window.FrakSetup?.client?.config?.walletUrl;if(e)return b(e)}return v}var S=class extends Map{maxSize;constructor(e){super(),this.maxSize=e}get(e){let t=super.get(e);return super.has(e)&&(super.delete(e),super.set(e,t)),t}set(e,t){if(super.has(e)&&super.delete(e),super.set(e,t),this.maxSize&&this.size>this.maxSize){let e=super.keys().next().value;e!==void 0&&super.delete(e)}return this}};const C=new S(1024),w=new S(1024),T=3e4;async function E(e,{cacheKey:t,cacheTime:n=T}){if(n>0){let e=w.get(t);if(e&&Date.now()-e.created<n)return e.data}let r=C.get(t);r||(r=e(),C.set(t,r));try{let e=await r;return w.set(t,{data:e,created:Date.now()}),e}finally{C.delete(t)}}function D(e){return{clear:()=>{C.delete(e),w.delete(e)},has:(t=T)=>{let n=w.get(e);return n?Date.now()-n.created<t:!1}}}function O(){C.clear(),w.clear()}function k(e){return a(f(e))}function te(e){return`r`in e&&!(`v`in e)}function A(e){return`v`in e&&e.v===2}const j=`fCtx`;function M(e){if(e)try{return A(e)?!e.c||!e.m||!e.t?void 0:p({v:2,c:e.c,m:e.m,t:e.t}):d(t(e.r))}catch(t){console.error(`Error compressing Frak context`,{e:t,context:e})}}function N(t){if(!(!t||t.length===0))try{let r=k(t);if(r&&typeof r==`object`&&r.v===2)return r.c&&r.m&&r.t?{v:2,c:r.c,m:r.m,t:r.t}:void 0;let i=e(f(t),{size:20});if(n(i))return{r:i}}catch(e){console.error(`Error decompressing Frak context`,{e,context:t})}}function P({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(j);return t?N(t):null}function F({url:e,context:t}){if(!e)return null;let n=M(t);if(!n)return null;let r=new URL(e);return r.searchParams.set(j,n),r.toString()}function I(e){let t=new URL(e);return t.searchParams.delete(j),t.toString()}function ne({url:e,context:t}){if(!window.location?.href||typeof window>`u`){console.error(`No window found, can't update context`);return}let n=e??window.location.href,r;r=t===null?I(n):F({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}const L={compress:M,decompress:N,parse:P,update:F,remove:I,replaceUrl:ne},R=`__frakSdkConfig`,z=`frak-config-cache`,B=`frak-merchant-id`,V={key:z},H=typeof window<`u`;function U(){return{isResolved:!1,merchantId:``}}let W=null;function G(){if(!H)return null;try{let e=localStorage.getItem(V.key);if(!e)return null;let t=JSON.parse(e);return t.config?.isResolved?(W=t,t):null}catch{return null}}function K(){return(W??G())?.config}function q(){let e=W??G();return e?Date.now()-e.timestamp<3e4:!1}function J(e){if(!(!H||!e.isResolved))try{let t={config:e,timestamp:Date.now()};localStorage.setItem(V.key,JSON.stringify(t)),W=t}catch{}}function Y(){if(H){W=null;try{localStorage.removeItem(V.key)}catch{}}}function X(){H&&(window[R]||(window[R]=K()??U()))}X();function Z(){return H?window[R]??U():U()}function Q(e){H&&window.dispatchEvent(new CustomEvent(`frak:config`,{detail:e}))}function re(e){return e??(H?window.location.hostname:``)}async function ie(e,t,n){try{let r=x(t),i=n?`&lang=${encodeURIComponent(n)}`:``,a=await fetch(`${r}/user/merchant/resolve?domain=${encodeURIComponent(e)}${i}`);if(!a.ok){console.warn(`[Frak SDK] Merchant lookup failed for domain ${e}: ${a.status}`);return}let o=await a.json();if(H)try{sessionStorage.setItem(B,o.merchantId)}catch{}return o}catch(e){console.warn(`[Frak SDK] Failed to fetch merchant config:`,e);return}}const $={getConfig:Z,get isResolved(){return Z().isResolved},get isCacheFresh(){return q()},setCacheScope(e,t){V.key=`${z}:${`${e}:${t??``}`}`,W=null},setConfig(e){if(H&&(window[R]=e),J(e),Q(e),H&&e.merchantId)try{sessionStorage.setItem(B,e.merchantId)}catch{}},reset(){let e=K()??U();H&&(window[R]=e),Q(e)},clearCache(){if(Y(),O(),H)try{sessionStorage.removeItem(B)}catch{}},resolve(e,t,n){let r=re(e);return r?E(async()=>{let e=await ie(r,t,n);if(!e)throw Error(`Config resolution returned empty`);return e},{cacheKey:`sdkConfig:${r}:${n??``}`,cacheTime:1/0}).catch(()=>void 0):Promise.resolve(void 0)},getMerchantId(){let e=Z();if(e.isResolved&&e.merchantId)return e.merchantId;if(H)try{return sessionStorage.getItem(B)??void 0}catch{}},async resolveMerchantId(e,t){return $.getMerchantId()||(await $.resolve(e,t))?.merchantId}};function ae(e,t,n={}){if(!e){console.debug(`[Frak] No client provided, skipping event tracking`);return}try{e.openPanel?.track(t,n)}catch(e){console.debug(`[Frak] Failed to track event:`,t,e)}}export{d as _,A as a,D as c,_ as d,h as f,f as g,p as h,te as i,E as l,m,$ as n,k as o,g as p,L as r,O as s,ae as t,x as u,u as v,l as y};
@@ -0,0 +1 @@
1
+ let e=require(`viem`),t=require(`@frak-labs/frame-connector`);const n=`frak-client-id`;function r(){return typeof crypto<`u`&&crypto.randomUUID?crypto.randomUUID():`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)})}function i(){if(typeof window>`u`||!window.localStorage)return console.warn(`[Frak SDK] No Window / localStorage available to save the clientId`),r();let e=localStorage.getItem(n);return e||(e=r(),localStorage.setItem(n,e)),e}function a({domain:t}={}){return(0,e.keccak256)((0,e.toHex)((t??window.location.host).replace(`www.`,``)))}function o(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function s(e){let t=e.length%4;return Uint8Array.from(atob(e.replace(/-/g,`+`).replace(/_/g,`/`).padEnd(e.length+(t===0?0:4-t),`=`)),e=>e.charCodeAt(0))}function c(e){return o((0,t.jsonEncode)(e))}function l(e,t,n,r,i,a){let o=c(u({redirectUrl:t.redirectUrl,directExit:t.directExit,lang:t.lang,merchantId:n,metadata:{name:r,css:a,logoUrl:t.metadata?.logoUrl,homepageLink:t.metadata?.homepageLink},clientId:i})),s=new URL(e);return s.pathname=`/sso`,s.searchParams.set(`p`,o),s.toString()}function u(e){return{r:e.redirectUrl,cId:e.clientId,d:e.directExit,l:e.lang,m:e.merchantId,md:{n:e.metadata?.name,css:e.metadata?.css,l:e.metadata?.logoUrl,h:e.metadata?.homepageLink}}}const d=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,f=`frak-sso`;async function p(e,t){let{metadata:n,customizations:r,walletUrl:o}=e.config;if(t.openInSameWindow??!!t.redirectUrl)return await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]});let s=t.ssoPopupUrl??l(o??`https://wallet.frak.id`,t,a(),n.name,i(),r?.css),c=window.open(s,f,d);if(!c)throw Error(`Popup was blocked. Please allow popups for this site.`);return c.focus(),await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]})??{}}const m=`https://backend.frak.id`;function h(e){return e.includes(`localhost:3000`)||e.includes(`localhost:3010`)}function g(e){return h(e)?`https://localhost:3030`:e.includes(`wallet-dev.frak.id`)||e.includes(`wallet.gcp-dev.frak.id`)?`https://backend.gcp-dev.frak.id`:m}function _(e){if(e)return g(e);if(typeof window<`u`){let e=window.FrakSetup?.client?.config?.walletUrl;if(e)return g(e)}return m}var v=class extends Map{maxSize;constructor(e){super(),this.maxSize=e}get(e){let t=super.get(e);return super.has(e)&&(super.delete(e),super.set(e,t)),t}set(e,t){if(super.has(e)&&super.delete(e),super.set(e,t),this.maxSize&&this.size>this.maxSize){let e=super.keys().next().value;e!==void 0&&super.delete(e)}return this}};const y=new v(1024),b=new v(1024),x=3e4;async function S(e,{cacheKey:t,cacheTime:n=x}){if(n>0){let e=b.get(t);if(e&&Date.now()-e.created<n)return e.data}let r=y.get(t);r||(r=e(),y.set(t,r));try{let e=await r;return b.set(t,{data:e,created:Date.now()}),e}finally{y.delete(t)}}function C(e){return{clear:()=>{y.delete(e),b.delete(e)},has:(t=x)=>{let n=b.get(e);return n?Date.now()-n.created<t:!1}}}function w(){y.clear(),b.clear()}function T(e){return(0,t.jsonDecode)(s(e))}function E(e){return`r`in e&&!(`v`in e)}function D(e){return`v`in e&&e.v===2}const O=`fCtx`;function k(t){if(t)try{return D(t)?!t.c||!t.m||!t.t?void 0:c({v:2,c:t.c,m:t.m,t:t.t}):o((0,e.hexToBytes)(t.r))}catch(e){console.error(`Error compressing Frak context`,{e,context:t})}}function A(t){if(!(!t||t.length===0))try{let n=T(t);if(n&&typeof n==`object`&&n.v===2)return n.c&&n.m&&n.t?{v:2,c:n.c,m:n.m,t:n.t}:void 0;let r=(0,e.bytesToHex)(s(t),{size:20});if((0,e.isAddress)(r))return{r}}catch(e){console.error(`Error decompressing Frak context`,{e,context:t})}}function j({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(O);return t?A(t):null}function M({url:e,context:t}){if(!e)return null;let n=k(t);if(!n)return null;let r=new URL(e);return r.searchParams.set(O,n),r.toString()}function N(e){let t=new URL(e);return t.searchParams.delete(O),t.toString()}function P({url:e,context:t}){if(!window.location?.href||typeof window>`u`){console.error(`No window found, can't update context`);return}let n=e??window.location.href,r;r=t===null?N(n):M({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}const F={compress:k,decompress:A,parse:j,update:M,remove:N,replaceUrl:P},I=`__frakSdkConfig`,L=`frak-config-cache`,R=`frak-merchant-id`,z={key:L},B=typeof window<`u`;function V(){return{isResolved:!1,merchantId:``}}let H=null;function U(){if(!B)return null;try{let e=localStorage.getItem(z.key);if(!e)return null;let t=JSON.parse(e);return t.config?.isResolved?(H=t,t):null}catch{return null}}function W(){return(H??U())?.config}function G(){let e=H??U();return e?Date.now()-e.timestamp<3e4:!1}function K(e){if(!(!B||!e.isResolved))try{let t={config:e,timestamp:Date.now()};localStorage.setItem(z.key,JSON.stringify(t)),H=t}catch{}}function q(){if(B){H=null;try{localStorage.removeItem(z.key)}catch{}}}function J(){B&&(window[I]||(window[I]=W()??V()))}J();function Y(){return B?window[I]??V():V()}function X(e){B&&window.dispatchEvent(new CustomEvent(`frak:config`,{detail:e}))}function Z(e){return e??(B?window.location.hostname:``)}async function Q(e,t,n){try{let r=_(t),i=n?`&lang=${encodeURIComponent(n)}`:``,a=await fetch(`${r}/user/merchant/resolve?domain=${encodeURIComponent(e)}${i}`);if(!a.ok){console.warn(`[Frak SDK] Merchant lookup failed for domain ${e}: ${a.status}`);return}let o=await a.json();if(B)try{sessionStorage.setItem(R,o.merchantId)}catch{}return o}catch(e){console.warn(`[Frak SDK] Failed to fetch merchant config:`,e);return}}const $={getConfig:Y,get isResolved(){return Y().isResolved},get isCacheFresh(){return G()},setCacheScope(e,t){z.key=`${L}:${`${e}:${t??``}`}`,H=null},setConfig(e){if(B&&(window[I]=e),K(e),X(e),B&&e.merchantId)try{sessionStorage.setItem(R,e.merchantId)}catch{}},reset(){let e=W()??V();B&&(window[I]=e),X(e)},clearCache(){if(q(),w(),B)try{sessionStorage.removeItem(R)}catch{}},resolve(e,t,n){let r=Z(e);return r?S(async()=>{let e=await Q(r,t,n);if(!e)throw Error(`Config resolution returned empty`);return e},{cacheKey:`sdkConfig:${r}:${n??``}`,cacheTime:1/0}).catch(()=>void 0):Promise.resolve(void 0)},getMerchantId(){let e=Y();if(e.isResolved&&e.merchantId)return e.merchantId;if(B)try{return sessionStorage.getItem(R)??void 0}catch{}},async resolveMerchantId(e,t){return $.getMerchantId()||(await $.resolve(e,t))?.merchantId}};function ee(e,t,n={}){if(!e){console.debug(`[Frak] No client provided, skipping event tracking`);return}try{e.openPanel?.track(t,n)}catch(e){console.debug(`[Frak] Failed to track event:`,t,e)}}Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return i}});
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "url": "https://twitter.com/QNivelais"
12
12
  }
13
13
  ],
14
- "version": "0.2.1-beta.b38eef2e",
14
+ "version": "0.2.1-beta.d04602ec",
15
15
  "description": "Core SDK of the Frak wallet, low level library to interact directly with the frak ecosystem.",
16
16
  "repository": {
17
17
  "url": "https://github.com/frak-id/wallet",
@@ -91,22 +91,22 @@
91
91
  "viem": "^2.x"
92
92
  },
93
93
  "dependencies": {
94
- "@frak-labs/frame-connector": "0.2.0-beta.b38eef2e",
95
- "@openpanel/web": "^1.0.7"
94
+ "@frak-labs/frame-connector": "0.2.0-beta.d04602ec",
95
+ "@openpanel/web": "^1.2.0"
96
96
  },
97
97
  "devDependencies": {
98
98
  "@arethetypeswrong/cli": "^0.18.2",
99
99
  "@frak-labs/dev-tooling": "0.0.0",
100
100
  "@frak-labs/test-foundation": "0.1.0",
101
101
  "@rolldown/plugin-node-polyfills": "^1.0.3",
102
- "@types/jsdom": "^27.0.0",
102
+ "@types/jsdom": "^28.0.0",
103
103
  "@types/node": "^24.10.13",
104
- "@vitest/coverage-v8": "^4.0.18",
105
- "@vitest/ui": "^4.0.18",
106
- "jsdom": "^28.0.0",
104
+ "@vitest/coverage-v8": "^4.1.0",
105
+ "@vitest/ui": "^4.1.0",
106
+ "jsdom": "^29.0.0",
107
107
  "tsdown": "^0.20.3",
108
108
  "typescript": "^5.9.3",
109
109
  "viem": "^2.39.0",
110
- "vitest": "^4.0.18"
110
+ "vitest": "^4.1.0"
111
111
  }
112
112
  }
@@ -8,14 +8,18 @@ import type {
8
8
  * Function used to display the Frak embedded wallet popup
9
9
  * @param client - The current Frak Client
10
10
  * @param params - The parameter used to customise the embedded wallet
11
+ * @param placement - Optional placement ID to associate with this display request
11
12
  * @returns The embedded wallet display result
12
13
  */
13
14
  export async function displayEmbeddedWallet(
14
15
  client: FrakClient,
15
- params: DisplayEmbeddedWalletParamsType
16
+ params: DisplayEmbeddedWalletParamsType,
17
+ placement?: string
16
18
  ): Promise<DisplayEmbeddedWalletResultType> {
17
19
  return await client.request({
18
20
  method: "frak_displayEmbeddedWallet",
19
- params: [params, client.config.metadata],
21
+ params: placement
22
+ ? [params, client.config.metadata, placement]
23
+ : [params, client.config.metadata],
20
24
  });
21
25
  }
@@ -11,6 +11,7 @@ import type {
11
11
  * @param args
12
12
  * @param args.steps - The different steps of the modal
13
13
  * @param args.metadata - The metadata for the modal (customization, etc)
14
+ * @param placement - Optional placement ID to associate with this modal display
14
15
  * @returns The result of each modal steps
15
16
  *
16
17
  * @description This function will display a modal to the user with the provided steps and metadata.
@@ -111,10 +112,13 @@ export async function displayModal<
111
112
  T extends ModalStepTypes[] = ModalStepTypes[],
112
113
  >(
113
114
  client: FrakClient,
114
- { steps, metadata }: DisplayModalParamsType<T>
115
+ { steps, metadata }: DisplayModalParamsType<T>,
116
+ placement?: string
115
117
  ): Promise<ModalRpcStepsResultType<T>> {
116
118
  return (await client.request({
117
119
  method: "frak_displayModal",
118
- params: [steps, metadata, client.config.metadata],
120
+ params: placement
121
+ ? [steps, metadata, client.config.metadata, placement]
122
+ : [steps, metadata, client.config.metadata],
119
123
  })) as ModalRpcStepsResultType<T>;
120
124
  }
@@ -0,0 +1,49 @@
1
+ import type {
2
+ DisplaySharingPageParamsType,
3
+ DisplaySharingPageResultType,
4
+ FrakClient,
5
+ } from "../types";
6
+
7
+ /**
8
+ * Function used to display a sharing page
9
+ * @param client - The current Frak Client
10
+ * @param params - The parameters to customize the sharing page (products, link override, metadata)
11
+ * @param placement - Optional placement ID to associate with this display request
12
+ * @returns The result indicating the user's action (shared, copied, or dismissed)
13
+ *
14
+ * @description This function will display a full-page sharing UI to the user,
15
+ * showing product info, estimated rewards, sharing steps, FAQ, and share/copy buttons.
16
+ * The sharing link is generated from the user's wallet context + merchant info.
17
+ *
18
+ * @remarks
19
+ * - The promise resolves on the first user action (share or copy) but the page stays visible
20
+ * - The user can continue to share/copy multiple times after the initial resolution
21
+ * - Dismissing the page after a share/copy action is a no-op (promise already resolved)
22
+ * - If the user dismisses without any action, the promise resolves with `{ action: "dismissed" }`
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const result = await displaySharingPage(frakClient, {
27
+ * products: [
28
+ * {
29
+ * title: "Babies camel cuir velours bout carré",
30
+ * imageUrl: "https://example.com/product.jpg",
31
+ * },
32
+ * ],
33
+ * });
34
+ *
35
+ * console.log("User action:", result.action); // "shared" | "copied" | "dismissed"
36
+ * ```
37
+ */
38
+ export async function displaySharingPage(
39
+ client: FrakClient,
40
+ params: DisplaySharingPageParamsType,
41
+ placement?: string
42
+ ): Promise<DisplaySharingPageResultType> {
43
+ return await client.request({
44
+ method: "frak_displaySharingPage",
45
+ params: placement
46
+ ? [params, client.config.metadata, placement]
47
+ : [params, client.config.metadata],
48
+ });
49
+ }
@@ -1,6 +1,6 @@
1
1
  import { getBackendUrl } from "../utils/backendUrl";
2
2
  import { getClientId } from "../utils/clientId";
3
- import { fetchMerchantId } from "../utils/merchantId";
3
+ import { sdkConfigStore } from "../utils/sdkConfigStore";
4
4
 
5
5
  const ENSURE_STORAGE_PREFIX = "frak-identity-ensured-";
6
6
 
@@ -36,7 +36,7 @@ export async function ensureIdentity(interactionToken: string): Promise<void> {
36
36
  return;
37
37
  }
38
38
 
39
- const merchantId = await fetchMerchantId();
39
+ const merchantId = await sdkConfigStore.resolveMerchantId();
40
40
  if (!merchantId) {
41
41
  return;
42
42
  }
@@ -1,9 +1,21 @@
1
1
  import type { Address, Hex } from "viem";
2
- import { describe, expect, it, vi } from "../../tests/vitest-fixtures";
2
+ import {
3
+ beforeEach,
4
+ describe,
5
+ expect,
6
+ it,
7
+ vi,
8
+ } from "../../tests/vitest-fixtures";
3
9
  import type { FrakClient, GetMerchantInformationReturnType } from "../types";
10
+ import { clearAllCache } from "../utils/cache";
4
11
  import { getMerchantInformation } from "./getMerchantInformation";
5
12
 
6
13
  describe("getMerchantInformation", () => {
14
+ // Clear cache between tests to ensure isolation
15
+ beforeEach(() => {
16
+ clearAllCache();
17
+ });
18
+
7
19
  describe("success cases", () => {
8
20
  it("should call client.request with correct method", async () => {
9
21
  const mockResponse: GetMerchantInformationReturnType = {
@@ -1,16 +1,31 @@
1
1
  import type { FrakClient, GetMerchantInformationReturnType } from "../types";
2
+ import { withCache } from "../utils/cache";
2
3
 
3
4
  /**
4
- * Fetch the current merchant information (name, rewards, tiers) from the wallet iframe
5
+ * Fetch the current merchant information (name, rewards, tiers) from the wallet iframe.
6
+ *
7
+ * Results are cached in memory for 30 seconds by default. Concurrent calls
8
+ * while a request is in-flight are deduplicated automatically.
9
+ *
5
10
  * @param client - The current Frak Client
11
+ * @param options - Optional cache configuration
12
+ * @param options.cacheTime - Time in ms to cache the result. Default: 30_000 (30s). Set to 0 to disable.
6
13
  * @returns The merchant information including available reward tiers
7
14
  *
8
15
  * @see {@link @frak-labs/core-sdk!index.GetMerchantInformationReturnType | `GetMerchantInformationReturnType`} for the return type shape
9
16
  */
10
17
  export async function getMerchantInformation(
11
- client: FrakClient
18
+ client: FrakClient,
19
+ options?: { cacheTime?: number }
12
20
  ): Promise<GetMerchantInformationReturnType> {
13
- return await client.request({
14
- method: "frak_getMerchantInformation",
15
- });
21
+ return withCache(
22
+ () =>
23
+ client.request({
24
+ method: "frak_getMerchantInformation",
25
+ }),
26
+ {
27
+ cacheKey: "frak_getMerchantInformation",
28
+ cacheTime: options?.cacheTime,
29
+ }
30
+ );
16
31
  }
@@ -0,0 +1,42 @@
1
+ import type { FrakClient, UserReferralStatusType } from "../types";
2
+ import { withCache } from "../utils/cache";
3
+
4
+ /**
5
+ * Fetch the current user's referral status on the current merchant.
6
+ *
7
+ * The listener resolves the user's identity (via clientId or wallet session)
8
+ * and checks whether a referral link exists where the user is the referee.
9
+ *
10
+ * Results are cached in memory for 30 seconds by default. Concurrent calls
11
+ * while a request is in-flight are deduplicated automatically.
12
+ *
13
+ * Returns `null` when the user's identity cannot be resolved.
14
+ *
15
+ * @param client - The current Frak Client
16
+ * @param options - Optional cache configuration
17
+ * @param options.cacheTime - Time in ms to cache the result. Default: 30_000 (30s). Set to 0 to disable.
18
+ * @returns The user's referral status, or `null` if identity cannot be resolved
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const status = await getUserReferralStatus(client);
23
+ * if (status?.isReferred) {
24
+ * console.log("User was referred to this merchant");
25
+ * }
26
+ * ```
27
+ */
28
+ export async function getUserReferralStatus(
29
+ client: FrakClient,
30
+ options?: { cacheTime?: number }
31
+ ): Promise<UserReferralStatusType | null> {
32
+ return withCache(
33
+ () =>
34
+ client.request({
35
+ method: "frak_getUserReferralStatus",
36
+ }),
37
+ {
38
+ cacheKey: "frak_getUserReferralStatus",
39
+ cacheTime: options?.cacheTime,
40
+ }
41
+ );
42
+ }