@frak-labs/core-sdk 0.1.1 → 0.2.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.
Files changed (125) hide show
  1. package/README.md +58 -0
  2. package/cdn/bundle.js +14 -0
  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 -6
  9. package/dist/bundle.d.ts +4 -6
  10. package/dist/bundle.js +1 -1
  11. package/dist/{index-CRsQWnTs.d.cts → computeLegacyProductId-BkyJ4rEY.d.ts} +197 -10
  12. package/dist/{index-Ck1hudEi.d.ts → computeLegacyProductId-Raks6FXg.d.cts} +197 -10
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.d.cts +3 -4
  15. package/dist/index.d.ts +3 -4
  16. package/dist/index.js +1 -1
  17. package/dist/{openSso-D--Airj6.d.cts → openSso-BCJGchIb.d.cts} +135 -131
  18. package/dist/{openSso-DsKJ4y0j.d.ts → openSso-DG-_9CED.d.ts} +135 -131
  19. package/dist/setupClient-CQrMDGyZ.js +13 -0
  20. package/dist/setupClient-Ccv3XxwL.cjs +13 -0
  21. package/dist/{index-d8xS4ryI.d.ts → siweAuthenticate-BH7Dn7nZ.d.cts} +90 -65
  22. package/dist/siweAuthenticate-BJHbtty4.js +1 -0
  23. package/dist/{index-C6FxkWPC.d.cts → siweAuthenticate-Btem4QHs.d.ts} +90 -65
  24. package/dist/siweAuthenticate-Cwj3HP0m.cjs +1 -0
  25. package/dist/trackEvent-M2RLTQ2p.js +1 -0
  26. package/dist/trackEvent-T_R9ER2S.cjs +1 -0
  27. package/package.json +11 -22
  28. package/src/actions/displayEmbeddedWallet.ts +1 -0
  29. package/src/actions/displayModal.test.ts +12 -11
  30. package/src/actions/displayModal.ts +7 -18
  31. package/src/actions/ensureIdentity.ts +68 -0
  32. package/src/actions/{getProductInformation.test.ts → getMerchantInformation.test.ts} +33 -50
  33. package/src/actions/getMerchantInformation.ts +16 -0
  34. package/src/actions/index.ts +3 -2
  35. package/src/actions/openSso.ts +4 -2
  36. package/src/actions/referral/processReferral.test.ts +42 -151
  37. package/src/actions/referral/processReferral.ts +18 -42
  38. package/src/actions/referral/referralInteraction.test.ts +1 -7
  39. package/src/actions/referral/referralInteraction.ts +1 -6
  40. package/src/actions/sendInteraction.ts +46 -22
  41. package/src/actions/trackPurchaseStatus.test.ts +354 -141
  42. package/src/actions/trackPurchaseStatus.ts +48 -11
  43. package/src/actions/watchWalletStatus.ts +2 -3
  44. package/src/actions/wrapper/modalBuilder.test.ts +0 -14
  45. package/src/actions/wrapper/modalBuilder.ts +3 -12
  46. package/src/bundle.ts +0 -1
  47. package/src/clients/createIFrameFrakClient.ts +10 -5
  48. package/src/clients/transports/iframeLifecycleManager.test.ts +163 -4
  49. package/src/clients/transports/iframeLifecycleManager.ts +172 -33
  50. package/src/constants/interactionTypes.ts +12 -41
  51. package/src/index.ts +24 -16
  52. package/src/types/config.ts +6 -0
  53. package/src/types/index.ts +13 -10
  54. package/src/types/lifecycle/client.ts +24 -1
  55. package/src/types/lifecycle/iframe.ts +6 -0
  56. package/src/types/rpc/displayModal.ts +2 -4
  57. package/src/types/rpc/embedded/index.ts +2 -2
  58. package/src/types/rpc/interaction.ts +26 -39
  59. package/src/types/rpc/merchantInformation.ts +77 -0
  60. package/src/types/rpc/modal/index.ts +0 -4
  61. package/src/types/rpc/modal/login.ts +5 -1
  62. package/src/types/rpc/walletStatus.ts +1 -7
  63. package/src/types/rpc.ts +22 -30
  64. package/src/types/tracking.ts +60 -0
  65. package/src/utils/backendUrl.test.ts +83 -0
  66. package/src/utils/backendUrl.ts +62 -0
  67. package/src/utils/clientId.test.ts +41 -0
  68. package/src/utils/clientId.ts +43 -0
  69. package/src/utils/compression/compress.test.ts +1 -1
  70. package/src/utils/compression/compress.ts +2 -2
  71. package/src/utils/compression/decompress.test.ts +8 -4
  72. package/src/utils/compression/decompress.ts +2 -2
  73. package/src/utils/{computeProductId.ts → computeLegacyProductId.ts} +2 -2
  74. package/src/utils/constants.ts +5 -0
  75. package/src/utils/deepLinkWithFallback.test.ts +243 -0
  76. package/src/utils/deepLinkWithFallback.ts +103 -0
  77. package/src/utils/formatAmount.ts +6 -0
  78. package/src/utils/iframeHelper.test.ts +18 -5
  79. package/src/utils/iframeHelper.ts +10 -3
  80. package/src/utils/index.ts +16 -1
  81. package/src/utils/merchantId.test.ts +653 -0
  82. package/src/utils/merchantId.ts +143 -0
  83. package/src/utils/sso.ts +18 -11
  84. package/src/utils/trackEvent.test.ts +23 -5
  85. package/src/utils/trackEvent.ts +13 -0
  86. package/cdn/bundle.iife.js +0 -14
  87. package/dist/actions-B5j-i1p0.cjs +0 -1
  88. package/dist/actions-q090Z0oR.js +0 -1
  89. package/dist/index-7OZ39x1U.d.ts +0 -195
  90. package/dist/index-zDq-VlKx.d.cts +0 -195
  91. package/dist/interaction-DMJ3ZfaF.d.cts +0 -45
  92. package/dist/interaction-KX1h9a7V.d.ts +0 -45
  93. package/dist/interactions-DnfM3oe0.js +0 -1
  94. package/dist/interactions-EIXhNLf6.cjs +0 -1
  95. package/dist/interactions.cjs +0 -1
  96. package/dist/interactions.d.cts +0 -2
  97. package/dist/interactions.d.ts +0 -2
  98. package/dist/interactions.js +0 -1
  99. package/dist/productTypes-BUkXJKZ7.cjs +0 -1
  100. package/dist/productTypes-CGb1MmBF.js +0 -1
  101. package/dist/src-1LQ4eLq5.js +0 -13
  102. package/dist/src-hW71KjPN.cjs +0 -13
  103. package/dist/trackEvent-CHnYa85W.js +0 -1
  104. package/dist/trackEvent-GuQm_1Nm.cjs +0 -1
  105. package/src/actions/getProductInformation.ts +0 -14
  106. package/src/actions/openSso.test.ts +0 -407
  107. package/src/actions/sendInteraction.test.ts +0 -219
  108. package/src/constants/interactionTypes.test.ts +0 -128
  109. package/src/constants/productTypes.test.ts +0 -130
  110. package/src/constants/productTypes.ts +0 -33
  111. package/src/interactions/index.ts +0 -5
  112. package/src/interactions/pressEncoder.test.ts +0 -215
  113. package/src/interactions/pressEncoder.ts +0 -53
  114. package/src/interactions/purchaseEncoder.test.ts +0 -291
  115. package/src/interactions/purchaseEncoder.ts +0 -99
  116. package/src/interactions/referralEncoder.test.ts +0 -170
  117. package/src/interactions/referralEncoder.ts +0 -47
  118. package/src/interactions/retailEncoder.test.ts +0 -107
  119. package/src/interactions/retailEncoder.ts +0 -37
  120. package/src/interactions/webshopEncoder.test.ts +0 -56
  121. package/src/interactions/webshopEncoder.ts +0 -30
  122. package/src/types/rpc/modal/openSession.ts +0 -25
  123. package/src/types/rpc/productInformation.ts +0 -59
  124. package/src/utils/computeProductId.test.ts +0 -80
  125. package/src/utils/sso.test.ts +0 -361
@@ -1,13 +1,11 @@
1
- import { A as SiweAuthenticateReturnType, B as FinalActionType, D as SendTransactionReturnType, E as SendTransactionModalStepType, L as PrepareSsoParamsType, M as OpenInteractionSessionModalStepType, P as LoginModalStepType, R as PrepareSsoReturnType, S as ModalRpcMetadata, T as ModalStepTypes, V as FinalModalStepType, a as FrakClient, g as DisplayEmbeddedWalletResultType, h as DisplayEmbeddedWalletParamsType, i as FrakContext, j as SiweAuthenticationParams, l as WalletStatusReturnType, u as GetProductInformationReturnType, w as ModalRpcStepsResultType, x as DisplayModalParamsType } from "./openSso-DsKJ4y0j.js";
2
- import { n as SendInteractionParamsType, r as SendInteractionReturnType } from "./interaction-KX1h9a7V.js";
3
- import { Hex } from "viem";
1
+ import { A as SiweAuthenticateReturnType, D as SendTransactionReturnType, E as SendTransactionModalStepType, F as PrepareSsoParamsType, I as PrepareSsoReturnType, M as LoginModalStepType, R as FinalActionType, S as ModalRpcMetadata, T as ModalStepTypes, a as FrakClient, d as GetMerchantInformationReturnType, g as DisplayEmbeddedWalletResultType, h as DisplayEmbeddedWalletParamsType, i as FrakContext, j as SiweAuthenticationParams, l as WalletStatusReturnType, m as SendInteractionParamsType, w as ModalRpcStepsResultType, x as DisplayModalParamsType, z as FinalModalStepType } from "./openSso-BCJGchIb.cjs";
4
2
 
5
3
  //#region src/actions/displayEmbeddedWallet.d.ts
6
-
7
4
  /**
8
5
  * Function used to display the Frak embedded wallet popup
9
6
  * @param client - The current Frak Client
10
7
  * @param params - The parameter used to customise the embedded wallet
8
+ * @returns The embedded wallet display result
11
9
  */
12
10
  declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbeddedWalletParamsType): Promise<DisplayEmbeddedWalletResultType>;
13
11
  //#endregion
@@ -24,26 +22,22 @@ declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbedd
24
22
  *
25
23
  * @remarks
26
24
  * - The UI of the displayed modal can be configured with the `customCss` property in the `customizations.css` field of the top-level config.
27
- * - The `login` and `openSession` steps will be automatically skipped if the user is already logged in or has an active session. It's safe to include these steps in all cases to ensure proper user state.
25
+ * - The `login` step will be automatically skipped if the user is already logged in. It's safe to include this step in all cases to ensure proper user state.
28
26
  * - Steps are automatically reordered in the following sequence:
29
27
  * 1. `login` (if needed)
30
- * 2. `openSession` (if needed)
31
- * 3. All other steps in the order specified
32
- * 4. `success` (if included, always last)
28
+ * 2. All other steps in the order specified
29
+ * 3. `success` (if included, always last)
33
30
  *
34
31
  * @example
35
32
  * Simple sharing modal with steps:
36
33
  * 1. Login (Skipped if already logged in)
37
- * 2. Open a session (Skipped if already opened)
38
- * 3. Display a success message with sharing link option
34
+ * 2. Display a success message with sharing link option
39
35
  *
40
36
  * ```ts
41
37
  * const results = await displayModal(frakConfig, {
42
38
  * steps: {
43
39
  * // Simple login with no SSO, nor customization
44
40
  * login: { allowSso: false },
45
- * // Simple session opening, with no customization
46
- * openSession: {},
47
41
  * // Success message
48
42
  * final: {
49
43
  * action: { key: "reward" },
@@ -54,19 +48,14 @@ declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbedd
54
48
  * });
55
49
  *
56
50
  * console.log("Login step - wallet", results.login.wallet);
57
- * console.log("Open session step - start + end", {
58
- * start: results.openSession.startTimestamp,
59
- * end: results.openSession.endTimestamp,
60
- * });
61
51
  * ```
62
52
  *
63
53
  * @example
64
54
  * A full modal example, with a few customization options, with the steps:
65
55
  * 1. Login (Skipped if already logged in)
66
- * 2. Open a session (Skipped if already opened)
67
- * 3. Authenticate via SIWE
68
- * 4. Send a transaction
69
- * 5. Display a success message with sharing link options
56
+ * 2. Authenticate via SIWE
57
+ * 3. Send a transaction
58
+ * 4. Display a success message with sharing link options
70
59
  *
71
60
  * ```ts
72
61
  * const results = await displayModal(frakConfig, {
@@ -79,8 +68,6 @@ declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbedd
79
68
  * homepageLink: "https://my-app.com",
80
69
  * },
81
70
  * },
82
- * // Simple session opening, with no customisation
83
- * openSession: {},
84
71
  * // Siwe authentication
85
72
  * siweAuthenticate: {
86
73
  * siwe: {
@@ -130,13 +117,40 @@ declare function displayModal<T extends ModalStepTypes[] = ModalStepTypes[]>(cli
130
117
  metadata
131
118
  }: DisplayModalParamsType<T>): Promise<ModalRpcStepsResultType<T>>;
132
119
  //#endregion
133
- //#region src/actions/getProductInformation.d.ts
120
+ //#region src/actions/ensureIdentity.d.ts
121
+ /**
122
+ * Ensure the current wallet ↔ clientId link exists on the backend.
123
+ *
124
+ * Called automatically by {@link watchWalletStatus} when a connected wallet
125
+ * status is received. Acts as a failsafe: if the primary merge (SSO, pairing,
126
+ * login/register) missed or silently failed, this ensures the link is
127
+ * eventually established.
128
+ *
129
+ * The call is:
130
+ * - **Idempotent** — if already linked, backend returns immediately
131
+ * - **Deduplicated** — only fires once per browser session per merchant
132
+ * - **Fire-and-forget** — errors are logged but never thrown
133
+ *
134
+ * @param interactionToken - The SDK JWT from wallet status (x-wallet-sdk-auth)
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * // Usually called automatically via watchWalletStatus side effect.
139
+ * // Can also be called manually if needed:
140
+ * await ensureIdentity("eyJhbGciOi...");
141
+ * ```
142
+ */
143
+ declare function ensureIdentity(interactionToken: string): Promise<void>;
144
+ //#endregion
145
+ //#region src/actions/getMerchantInformation.d.ts
134
146
  /**
135
- * Function used to get the current product information
147
+ * Fetch the current merchant information (name, rewards, tiers) from the wallet iframe
136
148
  * @param client - The current Frak Client
137
- * @returns The product information in a promise
149
+ * @returns The merchant information including available reward tiers
150
+ *
151
+ * @see {@link @frak-labs/core-sdk!index.GetMerchantInformationReturnType | `GetMerchantInformationReturnType`} for the return type shape
138
152
  */
139
- declare function getProductInformation(client: FrakClient): Promise<GetProductInformationReturnType>;
153
+ declare function getMerchantInformation(client: FrakClient): Promise<GetMerchantInformationReturnType>;
140
154
  //#endregion
141
155
  //#region src/actions/prepareSso.d.ts
142
156
  /**
@@ -177,7 +191,7 @@ declare function prepareSso(client: FrakClient, args: PrepareSsoParamsType): Pro
177
191
  * The different states of the referral process
178
192
  * @inline
179
193
  */
180
- type ReferralState = "idle" | "processing" | "success" | "no-wallet" | "no-session" | "error" | "no-referrer" | "self-referral";
194
+ type ReferralState = "idle" | "processing" | "success" | "no-wallet" | "error" | "no-referrer" | "self-referral";
181
195
  /**
182
196
  * Options for the referral auto-interaction process
183
197
  */
@@ -194,11 +208,9 @@ type ProcessReferralOptions = {
194
208
  * 2. Then check if the user is logged in or not
195
209
  * 2.1 If not logged in, try a soft login, if it fail, display a modal for the user to login
196
210
  * 3. Check if that's not a self-referral (if yes, early exit)
197
- * 4. Check if the user has an interaction session or not
198
- * 4.1 If not, display a modal for the user to open a session
199
- * 5. Push the referred interaction
200
- * 6. Update the current url with the right data
201
- * 7. Return the resulting referral state
211
+ * 4. Track the referral event
212
+ * 5. Update the current url with the right data
213
+ * 6. Return the resulting referral state
202
214
  *
203
215
  * If any error occurs during the process, the function will catch it and return an error state
204
216
  *
@@ -207,35 +219,29 @@ type ProcessReferralOptions = {
207
219
  * @param args.walletStatus - The current user wallet status
208
220
  * @param args.frakContext - The current frak context
209
221
  * @param args.modalConfig - The modal configuration to display if the user is not logged in
210
- * @param args.productId - The product id to interact with (if not specified will be recomputed from the current domain)
211
222
  * @param args.options - Some options for the referral interaction
212
223
  * @returns A promise with the resulting referral state
213
224
  *
214
225
  * @see {@link displayModal} for more details about the displayed modal
215
- * @see {@link sendInteraction} for more details on the interaction submission part
216
- * @see {@link ReferralInteractionEncoder} for more details about the referred interaction
217
226
  * @see {@link @frak-labs/core-sdk!ModalStepTypes} for more details on each modal steps types
218
227
  */
219
228
  declare function processReferral(client: FrakClient, {
220
229
  walletStatus,
221
230
  frakContext,
222
231
  modalConfig,
223
- productId,
224
232
  options
225
233
  }: {
226
234
  walletStatus?: WalletStatusReturnType;
227
235
  frakContext?: Partial<FrakContext> | null;
228
236
  modalConfig?: DisplayEmbeddedWalletParamsType;
229
- productId?: Hex;
230
237
  options?: ProcessReferralOptions;
231
238
  }): Promise<ReferralState>;
232
239
  //#endregion
233
240
  //#region src/actions/referral/referralInteraction.d.ts
234
241
  /**
235
- * Function used to display a modal
242
+ * Function used to handle referral interactions
236
243
  * @param client - The current Frak Client
237
244
  * @param args
238
- * @param args.productId - The product id to interact with (if not specified will be recomputed from the current domain)
239
245
  * @param args.modalConfig - The modal configuration to display if the user is not logged in
240
246
  * @param args.options - Some options for the referral interaction
241
247
  *
@@ -247,35 +253,53 @@ declare function processReferral(client: FrakClient, {
247
253
  * @see {@link @frak-labs/core-sdk!ModalStepTypes} for more details on each modal steps types
248
254
  */
249
255
  declare function referralInteraction(client: FrakClient, {
250
- productId,
251
256
  modalConfig,
252
257
  options
253
258
  }?: {
254
- productId?: Hex;
255
259
  modalConfig?: DisplayEmbeddedWalletParamsType;
256
260
  options?: ProcessReferralOptions;
257
- }): Promise<("no-referrer" | "self-referral" | "success" | "idle" | "processing" | "no-wallet" | "no-session" | "error") | undefined>;
261
+ }): Promise<("no-referrer" | "self-referral" | "success" | "idle" | "processing" | "no-wallet" | "error") | undefined>;
258
262
  //#endregion
259
263
  //#region src/actions/sendInteraction.d.ts
260
264
  /**
261
- * Function used to send an interaction
262
- * @param client - The current Frak Client
263
- * @param args
265
+ * Send an interaction to the backend via the listener RPC.
266
+ * Fire-and-forget: errors are caught and logged, not thrown.
267
+ *
268
+ * @param client - The Frak client instance
269
+ * @param params - The interaction parameters
270
+ *
271
+ * @description Sends a user interaction event through the wallet iframe RPC. Supports three interaction types: arrival tracking, sharing events, and custom interactions.
264
272
  *
265
273
  * @example
266
- * const interaction = PressInteractionEncoder.openArticle({
267
- * articleId: keccak256(toHex("article-slug")),
274
+ * Track a user arrival with referral attribution:
275
+ * ```ts
276
+ * await sendInteraction(client, {
277
+ * type: "arrival",
278
+ * referrerWallet: "0x1234...abcd",
279
+ * landingUrl: window.location.href,
280
+ * utmSource: "twitter",
281
+ * utmMedium: "social",
282
+ * utmCampaign: "launch-2026",
268
283
  * });
269
- * const { delegationId } = await sendInteraction(frakConfig, {
270
- * interaction,
284
+ * ```
285
+ *
286
+ * @example
287
+ * Track a sharing event:
288
+ * ```ts
289
+ * await sendInteraction(client, { type: "sharing" });
290
+ * ```
291
+ *
292
+ * @example
293
+ * Send a custom interaction:
294
+ * ```ts
295
+ * await sendInteraction(client, {
296
+ * type: "custom",
297
+ * customType: "newsletter_signup",
298
+ * data: { email: "user@example.com" },
271
299
  * });
272
- * console.log("Delegated interaction id", delegationId);
300
+ * ```
273
301
  */
274
- declare function sendInteraction(client: FrakClient, {
275
- productId,
276
- interaction,
277
- validation
278
- }: SendInteractionParamsType): Promise<SendInteractionReturnType>;
302
+ declare function sendInteraction(client: FrakClient, params: SendInteractionParamsType): Promise<void>;
279
303
  //#endregion
280
304
  //#region src/actions/trackPurchaseStatus.d.ts
281
305
  /**
@@ -285,6 +309,7 @@ declare function sendInteraction(client: FrakClient, {
285
309
  * @param args.customerId - The customer id that made the purchase (on your side)
286
310
  * @param args.orderId - The order id of the purchase (on your side)
287
311
  * @param args.token - The token of the purchase
312
+ * @param args.merchantId - Optional explicit merchant id to use for the tracking request
288
313
  *
289
314
  * @description This function will send a request to the backend to listen for the purchase status.
290
315
  *
@@ -294,19 +319,23 @@ declare function sendInteraction(client: FrakClient, {
294
319
  * customerId: checkout.order.customer.id,
295
320
  * orderId: checkout.order.id,
296
321
  * token: checkout.token,
322
+ * merchantId: "your-merchant-id",
297
323
  * };
298
324
  *
299
325
  * await trackPurchaseStatus(payload);
300
326
  * }
301
327
  *
302
328
  * @remarks
303
- * - The `trackPurchaseStatus` function requires the `frak-wallet-interaction-token` stored in the session storage to authenticate the request.
304
- * - This function will print a warning if used in a non-browser environment or if the wallet interaction token is not available.
329
+ * - Merchant id is resolved in this order: explicit `args.merchantId`, `frak-merchant-id` from session storage, then `fetchMerchantId()`.
330
+ * - This function supports anonymous users and will use the `x-frak-client-id` header when available.
331
+ * - At least one identity source must exist (`frak-wallet-interaction-token` or `x-frak-client-id`), otherwise the tracking request is skipped.
332
+ * - This function will print a warning if used in a non-browser environment or if no identity / merchant id can be resolved.
305
333
  */
306
334
  declare function trackPurchaseStatus(args: {
307
335
  customerId: string | number;
308
336
  orderId: string | number;
309
337
  token: string;
338
+ merchantId?: string;
310
339
  }): Promise<void>;
311
340
  //#endregion
312
341
  //#region src/actions/watchWalletStatus.d.ts
@@ -322,7 +351,6 @@ declare function trackPurchaseStatus(args: {
322
351
  * await watchWalletStatus(frakConfig, (status: WalletStatusReturnType) => {
323
352
  * if (status.key === "connected") {
324
353
  * console.log("Wallet connected:", status.wallet);
325
- * console.log("Current interaction session:", status.interactionSession);
326
354
  * } else {
327
355
  * console.log("Wallet not connected");
328
356
  * }
@@ -362,16 +390,15 @@ type ModalStepBuilder<Steps extends ModalStepTypes[] = ModalStepTypes[]> = {
362
390
  /**
363
391
  * Represent the output type of the modal builder
364
392
  */
365
- type ModalBuilder = ModalStepBuilder<[LoginModalStepType, OpenInteractionSessionModalStepType]>;
393
+ type ModalBuilder = ModalStepBuilder<[LoginModalStepType]>;
366
394
  /**
367
395
  * Helper to craft Frak modal, and share a base initial config
368
396
  * @param client - The current Frak Client
369
397
  * @param args
370
398
  * @param args.metadata - Common modal metadata (customisation, language etc)
371
399
  * @param args.login - Login step parameters
372
- * @param args.openSession - Open session step parameters
373
400
  *
374
- * @description This function will create a modal builder with the provided metadata, login and open session parameters.
401
+ * @description This function will create a modal builder with the provided metadata and login parameters.
375
402
  *
376
403
  * @example
377
404
  * Here is an example of how to use the `modalBuilder` to create and display a sharing modal:
@@ -400,12 +427,10 @@ type ModalBuilder = ModalStepBuilder<[LoginModalStepType, OpenInteractionSession
400
427
  */
401
428
  declare function modalBuilder(client: FrakClient, {
402
429
  metadata,
403
- login,
404
- openSession
430
+ login
405
431
  }: {
406
432
  metadata?: ModalRpcMetadata;
407
433
  login?: LoginModalStepType["params"];
408
- openSession?: OpenInteractionSessionModalStepType["params"];
409
434
  }): ModalBuilder;
410
435
  //#endregion
411
436
  //#region src/actions/wrapper/sendTransaction.d.ts
@@ -508,4 +533,4 @@ declare function siweAuthenticate(client: FrakClient, {
508
533
  metadata
509
534
  }: SiweAuthenticateModalParams): Promise<SiweAuthenticateReturnType>;
510
535
  //#endregion
511
- export { displayEmbeddedWallet as _, ModalBuilder as a, watchWalletStatus as c, referralInteraction as d, ProcessReferralOptions as f, displayModal as g, getProductInformation 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 };
536
+ 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 };
@@ -0,0 +1 @@
1
+ import{a as e,h as t,o as n,r,t as i}from"./trackEvent-M2RLTQ2p.js";import{isAddressEqual as a}from"viem";import{Deferred as o,FrakRpcError as s,RpcErrorCodes as c}from"@frak-labs/frame-connector";import{generateSiweNonce as l}from"viem/siwe";async function u(e,t){return await e.request({method:`frak_displayEmbeddedWallet`,params:[t,e.config.metadata]})}async function d(e,{steps:t,metadata:n}){return await e.request({method:`frak_displayModal`,params:[t,n,e.config.metadata]})}async function f(e){if(typeof window>`u`)return;let i=t();if(!i)return;let a=await r();if(!a)return;let o=`frak-identity-ensured-${a}`;if(!window.sessionStorage.getItem(o))try{let t=n();(await fetch(`${t}/user/identity/ensure`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`,"x-wallet-sdk-auth":e,"x-frak-client-id":i},body:JSON.stringify({merchantId:a})})).ok&&window.sessionStorage.setItem(o,`1`)}catch{}}async function p(e){return await e.request({method:`frak_getMerchantInformation`})}async function m(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function h(e,n){try{await e.request({method:`frak_sendInteraction`,params:[n,{clientId:t()}]})}catch{console.warn(`[Frak SDK] Failed to send interaction:`,n.type)}}async function g(t,{walletStatus:n,frakContext:r,modalConfig:a,options:o}){if(!r?.r)return`no-referrer`;i(t,`user_referred_started`,{properties:{referrer:r?.r,walletStatus:n?.key}}),h(t,{type:`arrival`,referrerWallet:r.r,landingUrl:typeof window<`u`?window.location.href:void 0});let c=!1;async function l(){if(!c)return c=!0,v(t,{modalConfig:{...a,loggedIn:{action:{key:`referred`}}},walletStatus:n})}try{let{status:a,currentWallet:s}=await _({initialWalletStatus:n,getFreshWalletStatus:l,frakContext:r});return e.replaceUrl({url:window.location?.href,context:o?.alwaysAppendUrl?{r:s}:null}),i(t,`user_referred_completed`,{properties:{status:a,referrer:r?.r,wallet:s}}),a}catch(a){return console.log(`Error processing referral`,{error:a}),i(t,`user_referred_error`,{properties:{referrer:r?.r,error:a instanceof s?`[${a.code}] ${a.name} - ${a.message}`:a instanceof Error?a.message:`undefined`}}),e.replaceUrl({url:window.location?.href,context:o?.alwaysAppendUrl?{r:n?.wallet}:null}),y(a)}}async function _({initialWalletStatus:e,getFreshWalletStatus:t,frakContext:n}){let r=e?.wallet;return r||=await t(),r&&a(n.r,r)?{status:`self-referral`,currentWallet:r}:{status:`success`,currentWallet:r}}async function v(e,{modalConfig:t,walletStatus:n}){return n?.key===`connected`?n.wallet??void 0:(await u(e,t??{}))?.wallet??void 0}function y(e){if(e instanceof s)switch(e.code){case c.walletNotConnected:return`no-wallet`;default:return`error`}return`error`}async function b(t,{modalConfig:n,options:r}={}){let i=e.parse({url:window.location.href}),a=await S(t);try{return await g(t,{walletStatus:a,frakContext:i,modalConfig:n,options:r})}catch(e){console.warn(`Error processing referral`,{error:e})}}async function x(e){if(typeof window>`u`){console.warn(`[Frak] No window found, can't track purchase`);return}let i=window.sessionStorage.getItem(`frak-wallet-interaction-token`),a=t();if(!i&&!a){console.warn(`[Frak] No identity found, skipping purchase check`);return}let o=window.sessionStorage.getItem(`frak-merchant-id`),s=e.merchantId??o??await r();if(!s){console.warn(`[Frak] No merchant id found, skipping purchase check`);return}let c={Accept:`application/json`,"Content-Type":`application/json`};i&&(c[`x-wallet-sdk-auth`]=i),a&&(c[`x-frak-client-id`]=a);let l=n();await fetch(`${l}/user/track/purchase`,{method:`POST`,headers:c,body:JSON.stringify({customerId:e.customerId,orderId:e.orderId,token:e.token,merchantId:s})})}function S(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(C(e,t),t));let n=new o,r=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},i=>{C(e,i),t(i),r||=(n.resolve(i),!0)}),n.promise}function C(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?(window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken),f(t.interactionToken)):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function w(e,{metadata:t,login:n}){return T(e,{steps:{login:n??{}},metadata:t})}function T(e,t){function n(n){return T(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return T(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return T(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function a(n){return n&&(t.metadata=n(t.metadata??{})),await d(e,t)}return{params:t,sendTx:n,reward:r,sharing:i,display:a}}async function E(e,{tx:t,metadata:n}){return(await d(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}async function D(e,{siwe:t,metadata:n}){let r=e.config?.domain??window.location.host,i=t?.statement??`I confirm that I want to use my Frak wallet on: ${e.config.metadata.name}`;return(await d(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:i,nonce:t?.nonce??l(),uri:t?.uri??`https://${r}`,version:t?.version??`1`,domain:r}}}})).siweAuthenticate}export{x as a,h as c,f as d,d as f,S as i,m as l,E as n,b as o,u as p,w as r,g as s,D as t,p as u};