@frak-labs/core-sdk 0.1.0 → 0.1.1-beta.2c88e0f4

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 (130) hide show
  1. package/README.md +58 -0
  2. package/cdn/bundle.js +3 -8
  3. package/dist/actions.cjs +1 -1
  4. package/dist/actions.d.cts +3 -1400
  5. package/dist/actions.d.ts +3 -1400
  6. package/dist/actions.js +1 -1
  7. package/dist/bundle.cjs +1 -13
  8. package/dist/bundle.d.cts +4 -1927
  9. package/dist/bundle.d.ts +4 -1927
  10. package/dist/bundle.js +1 -13
  11. package/dist/computeLegacyProductId-B-2-L7VT.d.cts +538 -0
  12. package/dist/computeLegacyProductId-M9k7vnUf.d.ts +538 -0
  13. package/dist/index.cjs +1 -13
  14. package/dist/index.d.cts +3 -1269
  15. package/dist/index.d.ts +3 -1269
  16. package/dist/index.js +1 -13
  17. package/dist/openSso-DTFns_5E.d.cts +1022 -0
  18. package/dist/openSso-DXL8K2tc.d.ts +1022 -0
  19. package/dist/setupClient--zfx2pFM.cjs +13 -0
  20. package/dist/setupClient-CFQDaGKh.js +13 -0
  21. package/dist/siweAuthenticate-BxRXLOpn.d.ts +511 -0
  22. package/dist/siweAuthenticate-D_AfTjZY.d.cts +511 -0
  23. package/dist/siweAuthenticate-Dfu_kubw.js +1 -0
  24. package/dist/siweAuthenticate-o0RXILdG.cjs +1 -0
  25. package/dist/trackEvent-B0S5E6_h.js +1 -0
  26. package/dist/trackEvent-BbX2d3g_.cjs +1 -0
  27. package/package.json +25 -31
  28. package/src/actions/displayEmbeddedWallet.test.ts +194 -0
  29. package/src/actions/displayEmbeddedWallet.ts +21 -0
  30. package/src/actions/displayModal.test.ts +388 -0
  31. package/src/actions/displayModal.ts +120 -0
  32. package/src/actions/getMerchantInformation.test.ts +116 -0
  33. package/src/actions/getMerchantInformation.ts +16 -0
  34. package/src/actions/index.ts +29 -0
  35. package/src/actions/openSso.ts +116 -0
  36. package/src/actions/prepareSso.test.ts +223 -0
  37. package/src/actions/prepareSso.ts +48 -0
  38. package/src/actions/referral/processReferral.test.ts +248 -0
  39. package/src/actions/referral/processReferral.ts +232 -0
  40. package/src/actions/referral/referralInteraction.test.ts +147 -0
  41. package/src/actions/referral/referralInteraction.ts +52 -0
  42. package/src/actions/sendInteraction.ts +56 -0
  43. package/src/actions/trackPurchaseStatus.test.ts +500 -0
  44. package/src/actions/trackPurchaseStatus.ts +90 -0
  45. package/src/actions/watchWalletStatus.test.ts +372 -0
  46. package/src/actions/watchWalletStatus.ts +93 -0
  47. package/src/actions/wrapper/modalBuilder.test.ts +239 -0
  48. package/src/actions/wrapper/modalBuilder.ts +203 -0
  49. package/src/actions/wrapper/sendTransaction.test.ts +164 -0
  50. package/src/actions/wrapper/sendTransaction.ts +62 -0
  51. package/src/actions/wrapper/siweAuthenticate.test.ts +290 -0
  52. package/src/actions/wrapper/siweAuthenticate.ts +94 -0
  53. package/src/bundle.ts +2 -0
  54. package/src/clients/DebugInfo.test.ts +418 -0
  55. package/src/clients/DebugInfo.ts +182 -0
  56. package/src/clients/createIFrameFrakClient.ts +290 -0
  57. package/src/clients/index.ts +3 -0
  58. package/src/clients/setupClient.test.ts +343 -0
  59. package/src/clients/setupClient.ts +73 -0
  60. package/src/clients/transports/iframeLifecycleManager.test.ts +558 -0
  61. package/src/clients/transports/iframeLifecycleManager.ts +229 -0
  62. package/src/constants/interactionTypes.ts +15 -0
  63. package/src/constants/locales.ts +14 -0
  64. package/src/index.ts +109 -0
  65. package/src/types/client.ts +14 -0
  66. package/src/types/compression.ts +22 -0
  67. package/src/types/config.ts +117 -0
  68. package/src/types/context.ts +13 -0
  69. package/src/types/index.ts +74 -0
  70. package/src/types/lifecycle/client.ts +69 -0
  71. package/src/types/lifecycle/iframe.ts +41 -0
  72. package/src/types/lifecycle/index.ts +2 -0
  73. package/src/types/rpc/displayModal.ts +82 -0
  74. package/src/types/rpc/embedded/index.ts +68 -0
  75. package/src/types/rpc/embedded/loggedIn.ts +55 -0
  76. package/src/types/rpc/embedded/loggedOut.ts +28 -0
  77. package/src/types/rpc/interaction.ts +30 -0
  78. package/src/types/rpc/merchantInformation.ts +77 -0
  79. package/src/types/rpc/modal/final.ts +46 -0
  80. package/src/types/rpc/modal/generic.ts +46 -0
  81. package/src/types/rpc/modal/index.ts +16 -0
  82. package/src/types/rpc/modal/login.ts +36 -0
  83. package/src/types/rpc/modal/siweAuthenticate.ts +37 -0
  84. package/src/types/rpc/modal/transaction.ts +33 -0
  85. package/src/types/rpc/sso.ts +80 -0
  86. package/src/types/rpc/walletStatus.ts +29 -0
  87. package/src/types/rpc.ts +150 -0
  88. package/src/types/tracking.ts +60 -0
  89. package/src/types/transport.ts +34 -0
  90. package/src/utils/FrakContext.test.ts +407 -0
  91. package/src/utils/FrakContext.ts +158 -0
  92. package/src/utils/backendUrl.test.ts +83 -0
  93. package/src/utils/backendUrl.ts +62 -0
  94. package/src/utils/clientId.test.ts +41 -0
  95. package/src/utils/clientId.ts +40 -0
  96. package/src/utils/compression/b64.test.ts +181 -0
  97. package/src/utils/compression/b64.ts +29 -0
  98. package/src/utils/compression/compress.test.ts +123 -0
  99. package/src/utils/compression/compress.ts +11 -0
  100. package/src/utils/compression/decompress.test.ts +149 -0
  101. package/src/utils/compression/decompress.ts +11 -0
  102. package/src/utils/compression/index.ts +3 -0
  103. package/src/utils/computeLegacyProductId.ts +11 -0
  104. package/src/utils/constants.test.ts +23 -0
  105. package/src/utils/constants.ts +9 -0
  106. package/src/utils/deepLinkWithFallback.test.ts +243 -0
  107. package/src/utils/deepLinkWithFallback.ts +103 -0
  108. package/src/utils/formatAmount.test.ts +113 -0
  109. package/src/utils/formatAmount.ts +24 -0
  110. package/src/utils/getCurrencyAmountKey.test.ts +44 -0
  111. package/src/utils/getCurrencyAmountKey.ts +15 -0
  112. package/src/utils/getSupportedCurrency.test.ts +51 -0
  113. package/src/utils/getSupportedCurrency.ts +14 -0
  114. package/src/utils/getSupportedLocale.test.ts +64 -0
  115. package/src/utils/getSupportedLocale.ts +16 -0
  116. package/src/utils/iframeHelper.test.ts +450 -0
  117. package/src/utils/iframeHelper.ts +147 -0
  118. package/src/utils/index.ts +36 -0
  119. package/src/utils/merchantId.test.ts +653 -0
  120. package/src/utils/merchantId.ts +143 -0
  121. package/src/utils/sso.ts +127 -0
  122. package/src/utils/ssoUrlListener.test.ts +252 -0
  123. package/src/utils/ssoUrlListener.ts +60 -0
  124. package/src/utils/trackEvent.test.ts +180 -0
  125. package/src/utils/trackEvent.ts +41 -0
  126. package/cdn/bundle.js.LICENSE.txt +0 -10
  127. package/dist/interactions.cjs +0 -1
  128. package/dist/interactions.d.cts +0 -182
  129. package/dist/interactions.d.ts +0 -182
  130. package/dist/interactions.js +0 -1
@@ -0,0 +1,511 @@
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-DTFns_5E.cjs";
2
+
3
+ //#region src/actions/displayEmbeddedWallet.d.ts
4
+ /**
5
+ * Function used to display the Frak embedded wallet popup
6
+ * @param client - The current Frak Client
7
+ * @param params - The parameter used to customise the embedded wallet
8
+ * @returns The embedded wallet display result
9
+ */
10
+ declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbeddedWalletParamsType): Promise<DisplayEmbeddedWalletResultType>;
11
+ //#endregion
12
+ //#region src/actions/displayModal.d.ts
13
+ /**
14
+ * Function used to display a modal
15
+ * @param client - The current Frak Client
16
+ * @param args
17
+ * @param args.steps - The different steps of the modal
18
+ * @param args.metadata - The metadata for the modal (customization, etc)
19
+ * @returns The result of each modal steps
20
+ *
21
+ * @description This function will display a modal to the user with the provided steps and metadata.
22
+ *
23
+ * @remarks
24
+ * - The UI of the displayed modal can be configured with the `customCss` property in the `customizations.css` field of the top-level config.
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.
26
+ * - Steps are automatically reordered in the following sequence:
27
+ * 1. `login` (if needed)
28
+ * 2. All other steps in the order specified
29
+ * 3. `success` (if included, always last)
30
+ *
31
+ * @example
32
+ * Simple sharing modal with steps:
33
+ * 1. Login (Skipped if already logged in)
34
+ * 2. Display a success message with sharing link option
35
+ *
36
+ * ```ts
37
+ * const results = await displayModal(frakConfig, {
38
+ * steps: {
39
+ * // Simple login with no SSO, nor customization
40
+ * login: { allowSso: false },
41
+ * // Success message
42
+ * final: {
43
+ * action: { key: "reward" },
44
+ * // Skip this step, it will be only displayed in the stepper within the modal
45
+ * autoSkip: true,
46
+ * },
47
+ * },
48
+ * });
49
+ *
50
+ * console.log("Login step - wallet", results.login.wallet);
51
+ * ```
52
+ *
53
+ * @example
54
+ * A full modal example, with a few customization options, with the steps:
55
+ * 1. Login (Skipped if already logged in)
56
+ * 2. Authenticate via SIWE
57
+ * 3. Send a transaction
58
+ * 4. Display a success message with sharing link options
59
+ *
60
+ * ```ts
61
+ * const results = await displayModal(frakConfig, {
62
+ * steps: {
63
+ * // Login step
64
+ * login: {
65
+ * allowSso: true,
66
+ * ssoMetadata: {
67
+ * logoUrl: "https://my-app.com/logo.png",
68
+ * homepageLink: "https://my-app.com",
69
+ * },
70
+ * },
71
+ * // Siwe authentication
72
+ * siweAuthenticate: {
73
+ * siwe: {
74
+ * domain: "my-app.com",
75
+ * uri: "https://my-app.com/",
76
+ * nonce: generateSiweNonce(),
77
+ * version: "1",
78
+ * },
79
+ * },
80
+ * // Send batched transaction
81
+ * sendTransaction: {
82
+ * tx: [
83
+ * { to: "0xdeadbeef", data: "0xdeadbeef" },
84
+ * { to: "0xdeadbeef", data: "0xdeadbeef" },
85
+ * ],
86
+ * },
87
+ * // Success message with sharing options
88
+ * final: {
89
+ * action: {
90
+ * key: "sharing",
91
+ * options: {
92
+ * popupTitle: "Share the app",
93
+ * text: "Discover my super app website",
94
+ * link: "https://my-app.com",
95
+ * },
96
+ * },
97
+ * dismissedMetadata: {
98
+ * title: "Dismiss",
99
+ * description: "You won't be rewarded for this sharing action",
100
+ * },
101
+ * },
102
+ * },
103
+ * metadata: {
104
+ * // Header of desktop modals
105
+ * header: {
106
+ * title: "My-App",
107
+ * icon: "https://my-app.com/logo.png",
108
+ * },
109
+ * // Context that will be present in every modal steps
110
+ * context: "My-app overkill flow",
111
+ * },
112
+ * });
113
+ * ```
114
+ */
115
+ declare function displayModal<T extends ModalStepTypes[] = ModalStepTypes[]>(client: FrakClient, {
116
+ steps,
117
+ metadata
118
+ }: DisplayModalParamsType<T>): Promise<ModalRpcStepsResultType<T>>;
119
+ //#endregion
120
+ //#region src/actions/getMerchantInformation.d.ts
121
+ /**
122
+ * Fetch the current merchant information (name, rewards, tiers) from the wallet iframe
123
+ * @param client - The current Frak Client
124
+ * @returns The merchant information including available reward tiers
125
+ *
126
+ * @see {@link @frak-labs/core-sdk!index.GetMerchantInformationReturnType | `GetMerchantInformationReturnType`} for the return type shape
127
+ */
128
+ declare function getMerchantInformation(client: FrakClient): Promise<GetMerchantInformationReturnType>;
129
+ //#endregion
130
+ //#region src/actions/prepareSso.d.ts
131
+ /**
132
+ * Generate SSO URL without opening popup
133
+ *
134
+ * This is a **synchronous**, client-side function that generates the SSO URL
135
+ * without any RPC calls to the wallet iframe. Use this when you need:
136
+ * - Custom URL modifications before opening popup
137
+ * - Pre-generation for advanced popup strategies
138
+ * - URL inspection/logging before SSO flow
139
+ *
140
+ * @param client - The current Frak Client
141
+ * @param args - The SSO parameters
142
+ * @returns Object containing the generated ssoUrl
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * // Generate URL for inspection
147
+ * const { ssoUrl } = prepareSso(client, {
148
+ * metadata: { logoUrl: "..." },
149
+ * directExit: true
150
+ * });
151
+ * console.log("Opening SSO:", ssoUrl);
152
+ *
153
+ * // Add custom params
154
+ * const customUrl = `${ssoUrl}&tracking=abc123`;
155
+ * await openSso(client, { metadata, ssoPopupUrl: customUrl });
156
+ * ```
157
+ *
158
+ * @remarks
159
+ * For most use cases, just use `openSso()` which handles URL generation automatically.
160
+ * Only use `prepareSso()` when you need explicit control over the URL.
161
+ */
162
+ declare function prepareSso(client: FrakClient, args: PrepareSsoParamsType): Promise<PrepareSsoReturnType>;
163
+ //#endregion
164
+ //#region src/actions/referral/processReferral.d.ts
165
+ /**
166
+ * The different states of the referral process
167
+ * @inline
168
+ */
169
+ type ReferralState = "idle" | "processing" | "success" | "no-wallet" | "error" | "no-referrer" | "self-referral";
170
+ /**
171
+ * Options for the referral auto-interaction process
172
+ */
173
+ type ProcessReferralOptions = {
174
+ /**
175
+ * If we want to always append the url with the frak context or not
176
+ * @defaultValue false
177
+ */
178
+ alwaysAppendUrl?: boolean;
179
+ };
180
+ /**
181
+ * This function handle all the heavy lifting of the referral interaction process
182
+ * 1. Check if the user has been referred or not (if not, early exit)
183
+ * 2. Then check if the user is logged in or not
184
+ * 2.1 If not logged in, try a soft login, if it fail, display a modal for the user to login
185
+ * 3. Check if that's not a self-referral (if yes, early exit)
186
+ * 4. Track the referral event
187
+ * 5. Update the current url with the right data
188
+ * 6. Return the resulting referral state
189
+ *
190
+ * If any error occurs during the process, the function will catch it and return an error state
191
+ *
192
+ * @param client - The current Frak Client
193
+ * @param args
194
+ * @param args.walletStatus - The current user wallet status
195
+ * @param args.frakContext - The current frak context
196
+ * @param args.modalConfig - The modal configuration to display if the user is not logged in
197
+ * @param args.options - Some options for the referral interaction
198
+ * @returns A promise with the resulting referral state
199
+ *
200
+ * @see {@link displayModal} for more details about the displayed modal
201
+ * @see {@link @frak-labs/core-sdk!ModalStepTypes} for more details on each modal steps types
202
+ */
203
+ declare function processReferral(client: FrakClient, {
204
+ walletStatus,
205
+ frakContext,
206
+ modalConfig,
207
+ options
208
+ }: {
209
+ walletStatus?: WalletStatusReturnType;
210
+ frakContext?: Partial<FrakContext> | null;
211
+ modalConfig?: DisplayEmbeddedWalletParamsType;
212
+ options?: ProcessReferralOptions;
213
+ }): Promise<ReferralState>;
214
+ //#endregion
215
+ //#region src/actions/referral/referralInteraction.d.ts
216
+ /**
217
+ * Function used to handle referral interactions
218
+ * @param client - The current Frak Client
219
+ * @param args
220
+ * @param args.modalConfig - The modal configuration to display if the user is not logged in
221
+ * @param args.options - Some options for the referral interaction
222
+ *
223
+ * @returns A promise with the resulting referral state, or undefined in case of an error
224
+ *
225
+ * @description This function will automatically handle the referral interaction process
226
+ *
227
+ * @see {@link processReferral} for more details on the automatic referral handling process
228
+ * @see {@link @frak-labs/core-sdk!ModalStepTypes} for more details on each modal steps types
229
+ */
230
+ declare function referralInteraction(client: FrakClient, {
231
+ modalConfig,
232
+ options
233
+ }?: {
234
+ modalConfig?: DisplayEmbeddedWalletParamsType;
235
+ options?: ProcessReferralOptions;
236
+ }): Promise<("no-referrer" | "self-referral" | "success" | "idle" | "processing" | "no-wallet" | "error") | undefined>;
237
+ //#endregion
238
+ //#region src/actions/sendInteraction.d.ts
239
+ /**
240
+ * Send an interaction to the backend via the listener RPC.
241
+ * Fire-and-forget: errors are caught and logged, not thrown.
242
+ *
243
+ * @param client - The Frak client instance
244
+ * @param params - The interaction parameters
245
+ *
246
+ * @description Sends a user interaction event through the wallet iframe RPC. Supports three interaction types: arrival tracking, sharing events, and custom interactions.
247
+ *
248
+ * @example
249
+ * Track a user arrival with referral attribution:
250
+ * ```ts
251
+ * await sendInteraction(client, {
252
+ * type: "arrival",
253
+ * referrerWallet: "0x1234...abcd",
254
+ * landingUrl: window.location.href,
255
+ * utmSource: "twitter",
256
+ * utmMedium: "social",
257
+ * utmCampaign: "launch-2026",
258
+ * });
259
+ * ```
260
+ *
261
+ * @example
262
+ * Track a sharing event:
263
+ * ```ts
264
+ * await sendInteraction(client, { type: "sharing" });
265
+ * ```
266
+ *
267
+ * @example
268
+ * Send a custom interaction:
269
+ * ```ts
270
+ * await sendInteraction(client, {
271
+ * type: "custom",
272
+ * customType: "newsletter_signup",
273
+ * data: { email: "user@example.com" },
274
+ * });
275
+ * ```
276
+ */
277
+ declare function sendInteraction(client: FrakClient, params: SendInteractionParamsType): Promise<void>;
278
+ //#endregion
279
+ //#region src/actions/trackPurchaseStatus.d.ts
280
+ /**
281
+ * Function used to track the status of a purchase
282
+ * when a purchase is tracked, the `purchaseCompleted` interactions will be automatically send for the user when we receive the purchase confirmation via webhook.
283
+ *
284
+ * @param args.customerId - The customer id that made the purchase (on your side)
285
+ * @param args.orderId - The order id of the purchase (on your side)
286
+ * @param args.token - The token of the purchase
287
+ * @param args.merchantId - Optional explicit merchant id to use for the tracking request
288
+ *
289
+ * @description This function will send a request to the backend to listen for the purchase status.
290
+ *
291
+ * @example
292
+ * async function trackPurchase(checkout) {
293
+ * const payload = {
294
+ * customerId: checkout.order.customer.id,
295
+ * orderId: checkout.order.id,
296
+ * token: checkout.token,
297
+ * merchantId: "your-merchant-id",
298
+ * };
299
+ *
300
+ * await trackPurchaseStatus(payload);
301
+ * }
302
+ *
303
+ * @remarks
304
+ * - Merchant id is resolved in this order: explicit `args.merchantId`, `frak-merchant-id` from session storage, then `fetchMerchantId()`.
305
+ * - This function supports anonymous users and will use the `x-frak-client-id` header when available.
306
+ * - At least one identity source must exist (`frak-wallet-interaction-token` or `x-frak-client-id`), otherwise the tracking request is skipped.
307
+ * - This function will print a warning if used in a non-browser environment or if no identity / merchant id can be resolved.
308
+ */
309
+ declare function trackPurchaseStatus(args: {
310
+ customerId: string | number;
311
+ orderId: string | number;
312
+ token: string;
313
+ merchantId?: string;
314
+ }): Promise<void>;
315
+ //#endregion
316
+ //#region src/actions/watchWalletStatus.d.ts
317
+ /**
318
+ * Function used to watch the current frak wallet status
319
+ * @param client - The current Frak Client
320
+ * @param callback - The callback that will receive any wallet status change
321
+ * @returns A promise resolving with the initial wallet status
322
+ *
323
+ * @description This function will return the current wallet status, and will listen to any change in the wallet status.
324
+ *
325
+ * @example
326
+ * await watchWalletStatus(frakConfig, (status: WalletStatusReturnType) => {
327
+ * if (status.key === "connected") {
328
+ * console.log("Wallet connected:", status.wallet);
329
+ * } else {
330
+ * console.log("Wallet not connected");
331
+ * }
332
+ * });
333
+ */
334
+ declare function watchWalletStatus(client: FrakClient, callback?: (status: WalletStatusReturnType) => void): Promise<WalletStatusReturnType>;
335
+ //#endregion
336
+ //#region src/actions/wrapper/modalBuilder.d.ts
337
+ /**
338
+ * Represent the type of the modal step builder
339
+ */
340
+ type ModalStepBuilder<Steps extends ModalStepTypes[] = ModalStepTypes[]> = {
341
+ /**
342
+ * The current modal params
343
+ */
344
+ params: DisplayModalParamsType<Steps>;
345
+ /**
346
+ * Add a send transaction step to the modal
347
+ */
348
+ sendTx: (options: SendTransactionModalStepType["params"]) => ModalStepBuilder<[...Steps, SendTransactionModalStepType]>;
349
+ /**
350
+ * Add a final step of type reward to the modal
351
+ */
352
+ reward: (options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
353
+ /**
354
+ * Add a final step of type sharing to the modal
355
+ */
356
+ sharing: (sharingOptions?: Extract<FinalActionType, {
357
+ key: "sharing";
358
+ }>["options"], options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
359
+ /**
360
+ * Display the modal
361
+ * @param metadataOverride - Function returning optional metadata to override the current modal metadata
362
+ */
363
+ display: (metadataOverride?: (current?: ModalRpcMetadata) => ModalRpcMetadata | undefined) => Promise<ModalRpcStepsResultType<Steps>>;
364
+ };
365
+ /**
366
+ * Represent the output type of the modal builder
367
+ */
368
+ type ModalBuilder = ModalStepBuilder<[LoginModalStepType]>;
369
+ /**
370
+ * Helper to craft Frak modal, and share a base initial config
371
+ * @param client - The current Frak Client
372
+ * @param args
373
+ * @param args.metadata - Common modal metadata (customisation, language etc)
374
+ * @param args.login - Login step parameters
375
+ *
376
+ * @description This function will create a modal builder with the provided metadata and login parameters.
377
+ *
378
+ * @example
379
+ * Here is an example of how to use the `modalBuilder` to create and display a sharing modal:
380
+ *
381
+ * ```js
382
+ * // Create the modal builder
383
+ * const modalBuilder = window.FrakSDK.modalBuilder(frakClient, baseModalConfig);
384
+ *
385
+ * // Configure the information to be shared via the sharing link
386
+ * const sharingConfig = {
387
+ * popupTitle: "Share this with your friends",
388
+ * text: "Discover our product!",
389
+ * link: window.location.href,
390
+ * };
391
+ *
392
+ * // Display the sharing modal
393
+ * function modalShare() {
394
+ * modalBuilder.sharing(sharingConfig).display();
395
+ * }
396
+ * ```
397
+ *
398
+ * @see {@link ModalStepTypes} for more info about each modal step types and their parameters
399
+ * @see {@link ModalRpcMetadata} for more info about the metadata that can be passed to the modal
400
+ * @see {@link ModalRpcStepsResultType} for more info about the result of each modal steps
401
+ * @see {@link displayModal} for more info about how the modal is displayed
402
+ */
403
+ declare function modalBuilder(client: FrakClient, {
404
+ metadata,
405
+ login
406
+ }: {
407
+ metadata?: ModalRpcMetadata;
408
+ login?: LoginModalStepType["params"];
409
+ }): ModalBuilder;
410
+ //#endregion
411
+ //#region src/actions/wrapper/sendTransaction.d.ts
412
+ /**
413
+ * Parameters to directly show a modal used to send a transaction
414
+ * @inline
415
+ */
416
+ type SendTransactionParams = {
417
+ /**
418
+ * The transaction to be sent (either a single tx or multiple ones)
419
+ */
420
+ tx: SendTransactionModalStepType["params"]["tx"];
421
+ /**
422
+ * Custom metadata to be passed to the modal
423
+ */
424
+ metadata?: ModalRpcMetadata;
425
+ };
426
+ /**
427
+ * Function used to send a user transaction, simple wrapper around the displayModal function to ease the send transaction process
428
+ * @param client - The current Frak Client
429
+ * @param args - The parameters
430
+ * @returns The hash of the transaction that was sent in a promise
431
+ *
432
+ * @description This function will display a modal to the user with the provided transaction and metadata.
433
+ *
434
+ * @example
435
+ * const { hash } = await sendTransaction(frakConfig, {
436
+ * tx: {
437
+ * to: "0xdeadbeef",
438
+ * value: toHex(100n),
439
+ * },
440
+ * metadata: {
441
+ * header: {
442
+ * title: "Sending eth",
443
+ * },
444
+ * context: "Send 100wei to 0xdeadbeef",
445
+ * },
446
+ * });
447
+ * console.log("Transaction hash:", hash);
448
+ */
449
+ declare function sendTransaction(client: FrakClient, {
450
+ tx,
451
+ metadata
452
+ }: SendTransactionParams): Promise<SendTransactionReturnType>;
453
+ //#endregion
454
+ //#region src/actions/wrapper/siweAuthenticate.d.ts
455
+ /**
456
+ * Parameter used to directly show a modal used to authenticate with SIWE
457
+ * @inline
458
+ */
459
+ type SiweAuthenticateModalParams = {
460
+ /**
461
+ * Partial SIWE params, since we can rebuild them from the SDK if they are empty
462
+ *
463
+ * If no parameters provider, some fields will be recomputed from the current configuration and environment.
464
+ * - `statement` will be set to a default value
465
+ * - `nonce` will be generated
466
+ * - `uri` will be set to the current domain
467
+ * - `version` will be set to "1"
468
+ * - `domain` will be set to the current window domain
469
+ *
470
+ * @default {}
471
+ */
472
+ siwe?: Partial<SiweAuthenticationParams>;
473
+ /**
474
+ * Custom metadata to be passed to the modal
475
+ */
476
+ metadata?: ModalRpcMetadata;
477
+ };
478
+ /**
479
+ * Function used to launch a siwe authentication
480
+ * @param client - The current Frak Client
481
+ * @param args - The parameters
482
+ * @returns The SIWE authentication result (message + signature) in a promise
483
+ *
484
+ * @description This function will display a modal to the user with the provided SIWE parameters and metadata.
485
+ *
486
+ * @example
487
+ * import { siweAuthenticate } from "@frak-labs/core-sdk/actions";
488
+ * import { parseSiweMessage } from "viem/siwe";
489
+ *
490
+ * const { signature, message } = await siweAuthenticate(frakConfig, {
491
+ * siwe: {
492
+ * statement: "Sign in to My App",
493
+ * domain: "my-app.com",
494
+ * expirationTimeTimestamp: Date.now() + 1000 * 60 * 5,
495
+ * },
496
+ * metadata: {
497
+ * header: {
498
+ * title: "Sign in",
499
+ * },
500
+ * context: "Sign in to My App",
501
+ * },
502
+ * });
503
+ * console.log("Parsed final message:", parseSiweMessage(message));
504
+ * console.log("Siwe signature:", signature);
505
+ */
506
+ declare function siweAuthenticate(client: FrakClient, {
507
+ siwe,
508
+ metadata
509
+ }: SiweAuthenticateModalParams): Promise<SiweAuthenticateReturnType>;
510
+ //#endregion
511
+ export { displayEmbeddedWallet as _, ModalBuilder as a, watchWalletStatus as c, referralInteraction as d, ProcessReferralOptions as f, displayModal 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 };
@@ -0,0 +1 @@
1
+ import{a as e,m as t,o as n,r,t as i}from"./trackEvent-B0S5E6_h.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){return await e.request({method:`frak_getMerchantInformation`})}async function p(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function m(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 h(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}}),m(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,_(t,{modalConfig:{...a,loggedIn:{action:{key:`referred`}}},walletStatus:n})}try{let{status:a,currentWallet:s}=await g({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}),v(a)}}async function g({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 _(e,{modalConfig:t,walletStatus:n}){return n?.key===`connected`?n.wallet??void 0:(await u(e,t??{}))?.wallet??void 0}function v(e){if(e instanceof s)switch(e.code){case c.walletNotConnected:return`no-wallet`;default:return`error`}return`error`}async function y(t,{modalConfig:n,options:r}={}){let i=e.parse({url:window.location.href}),a=await x(t);try{return await h(t,{walletStatus:a,frakContext:i,modalConfig:n,options:r})}catch(e){console.warn(`Error processing referral`,{error:e})}}async function b(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 x(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(S(e,t),t));let n=new o,r=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},i=>{S(e,i),t(i),r||=(n.resolve(i),!0)}),n.promise}function S(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function C(e,{metadata:t,login:n}){return w(e,{steps:{login:n??{}},metadata:t})}function w(e,t){function n(n){return w(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return w(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return w(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 T(e,{tx:t,metadata:n}){return(await d(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}async function E(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{b as a,m as c,d,u as f,x as i,p as l,T as n,y as o,C as r,h as s,E as t,f as u};
@@ -0,0 +1 @@
1
+ const e=require(`./trackEvent-BbX2d3g_.cjs`);let t=require(`viem`),n=require(`@frak-labs/frame-connector`),r=require(`viem/siwe`);async function i(e,t){return await e.request({method:`frak_displayEmbeddedWallet`,params:[t,e.config.metadata]})}async function a(e,{steps:t,metadata:n}){return await e.request({method:`frak_displayModal`,params:[t,n,e.config.metadata]})}async function o(e){return await e.request({method:`frak_getMerchantInformation`})}async function s(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function c(t,n){try{await t.request({method:`frak_sendInteraction`,params:[n,{clientId:e.m()}]})}catch{console.warn(`[Frak SDK] Failed to send interaction:`,n.type)}}async function l(t,{walletStatus:r,frakContext:i,modalConfig:a,options:o}){if(!i?.r)return`no-referrer`;e.t(t,`user_referred_started`,{properties:{referrer:i?.r,walletStatus:r?.key}}),c(t,{type:`arrival`,referrerWallet:i.r,landingUrl:typeof window<`u`?window.location.href:void 0});let s=!1;async function l(){if(!s)return s=!0,d(t,{modalConfig:{...a,loggedIn:{action:{key:`referred`}}},walletStatus:r})}try{let{status:n,currentWallet:a}=await u({initialWalletStatus:r,getFreshWalletStatus:l,frakContext:i});return e.a.replaceUrl({url:window.location?.href,context:o?.alwaysAppendUrl?{r:a}:null}),e.t(t,`user_referred_completed`,{properties:{status:n,referrer:i?.r,wallet:a}}),n}catch(a){return console.log(`Error processing referral`,{error:a}),e.t(t,`user_referred_error`,{properties:{referrer:i?.r,error:a instanceof n.FrakRpcError?`[${a.code}] ${a.name} - ${a.message}`:a instanceof Error?a.message:`undefined`}}),e.a.replaceUrl({url:window.location?.href,context:o?.alwaysAppendUrl?{r:r?.wallet}:null}),f(a)}}async function u({initialWalletStatus:e,getFreshWalletStatus:n,frakContext:r}){let i=e?.wallet;return i||=await n(),i&&(0,t.isAddressEqual)(r.r,i)?{status:`self-referral`,currentWallet:i}:{status:`success`,currentWallet:i}}async function d(e,{modalConfig:t,walletStatus:n}){return n?.key===`connected`?n.wallet??void 0:(await i(e,t??{}))?.wallet??void 0}function f(e){if(e instanceof n.FrakRpcError)switch(e.code){case n.RpcErrorCodes.walletNotConnected:return`no-wallet`;default:return`error`}return`error`}async function p(t,{modalConfig:n,options:r}={}){let i=e.a.parse({url:window.location.href}),a=await h(t);try{return await l(t,{walletStatus:a,frakContext:i,modalConfig:n,options:r})}catch(e){console.warn(`Error processing referral`,{error:e})}}async function m(t){if(typeof window>`u`){console.warn(`[Frak] No window found, can't track purchase`);return}let n=window.sessionStorage.getItem(`frak-wallet-interaction-token`),r=e.m();if(!n&&!r){console.warn(`[Frak] No identity found, skipping purchase check`);return}let i=window.sessionStorage.getItem(`frak-merchant-id`),a=t.merchantId??i??await e.r();if(!a){console.warn(`[Frak] No merchant id found, skipping purchase check`);return}let o={Accept:`application/json`,"Content-Type":`application/json`};n&&(o[`x-wallet-sdk-auth`]=n),r&&(o[`x-frak-client-id`]=r);let s=e.o();await fetch(`${s}/user/track/purchase`,{method:`POST`,headers:o,body:JSON.stringify({customerId:t.customerId,orderId:t.orderId,token:t.token,merchantId:a})})}function h(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(g(e,t),t));let r=new n.Deferred,i=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},n=>{g(e,n),t(n),i||=(r.resolve(n),!0)}),r.promise}function g(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function _(e,{metadata:t,login:n}){return v(e,{steps:{login:n??{}},metadata:t})}function v(e,t){function n(n){return v(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return v(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return v(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function o(n){return n&&(t.metadata=n(t.metadata??{})),await a(e,t)}return{params:t,sendTx:n,reward:r,sharing:i,display:o}}async function y(e,{tx:t,metadata:n}){return(await a(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}async function b(e,{siwe:t,metadata:n}){let i=e.config?.domain??window.location.host,o=t?.statement??`I confirm that I want to use my Frak wallet on: ${e.config.metadata.name}`;return(await a(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:o,nonce:t?.nonce??(0,r.generateSiweNonce)(),uri:t?.uri??`https://${i}`,version:t?.version??`1`,domain:i}}}})).siweAuthenticate}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return o}});
@@ -0,0 +1 @@
1
+ import{bytesToHex as e,hexToBytes as t,keccak256 as n,toHex as r}from"viem";import{jsonEncode as i}from"@frak-labs/frame-connector";function a({domain:e}={}){return n(r((e??window.location.host).replace(`www.`,``)))}const o=`frak-client-id`;function s(){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 c(){if(typeof window>`u`||!window.localStorage)return s();let e=localStorage.getItem(o);return e||(e=s(),localStorage.setItem(o,e)),e}function l(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function u(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 d(e){return l(i(e))}function f(e,t,n,r,i,a){let o=d(p({redirectUrl:t.redirectUrl,directExit:t.directExit,lang:t.lang,merchantId:n,metadata:{name:r,css:i,logoUrl:t.metadata?.logoUrl,homepageLink:t.metadata?.homepageLink},clientId:a??c()})),s=new URL(e);return s.pathname=`/sso`,s.searchParams.set(`p`,o),s.toString()}function p(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 m=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,h=`frak-sso`;async function g(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 o=t.ssoPopupUrl??f(i??`https://wallet.frak.id`,t,a(),n.name,r?.css),s=window.open(o,h,m);if(!s)throw Error(`Popup was blocked. Please allow popups for this site.`);return s.focus(),await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]})??{}}const _=`https://backend.frak.id`;function v(e){return e.includes(`localhost:3000`)||e.includes(`localhost:3010`)}function y(e){return v(e)?`http://localhost:3030`:e.includes(`wallet-dev.frak.id`)||e.includes(`wallet.gcp-dev.frak.id`)?`https://backend.gcp-dev.frak.id`:_}function b(e){if(e)return y(e);if(typeof window<`u`){let e=window.FrakSetup?.client?.config?.walletUrl;if(e)return y(e)}return _}const x=`fCtx`;function S(e){if(e?.r)try{return l(t(e.r))}catch(t){console.error(`Error compressing Frak context`,{e:t,context:e})}}function C(t){if(!(!t||t.length===0))try{return{r:e(u(t),{size:20})}}catch(e){console.error(`Error decompressing Frak context`,{e,context:t})}}function w({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(x);return t?C(t):null}function T({url:e,context:t}){if(!e)return null;let n=w({url:e}),r=n?{...n,...t}:t;if(!r.r)return null;let i=S(r);if(!i)return null;let a=new URL(e);return a.searchParams.set(x,i),a.toString()}function E(e){let t=new URL(e);return t.searchParams.delete(x),t.toString()}function D({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?E(n):T({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}const O={compress:S,decompress:C,parse:w,update:T,remove:E,replaceUrl:D},k=`frak-merchant-id`;let A,j;async function M(e,t){if(A)return A;if(typeof window<`u`){let e=window.sessionStorage.getItem(k);if(e)return A=e,e}if(j)return j;j=N(e,t);let n=await j;return j=void 0,n}async function N(e,t){let n=e??(typeof window<`u`?window.location.hostname:``);if(n)try{let e=b(t),r=await fetch(`${e}/user/merchant/resolve?domain=${encodeURIComponent(n)}`);if(!r.ok){console.warn(`[Frak SDK] Merchant lookup failed for domain ${n}: ${r.status}`);return}let i=await r.json();return A=i.merchantId,typeof window<`u`&&window.sessionStorage.setItem(k,i.merchantId),A}catch(e){console.warn(`[Frak SDK] Failed to fetch merchantId:`,e);return}}function P(){A=void 0,j=void 0,typeof window<`u`&&window.sessionStorage.removeItem(k)}async function F(e,t){return e.metadata?.merchantId?e.metadata.merchantId:M(void 0,t)}function I(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{O as a,m as c,d,u as f,a as h,F as i,h as l,c as m,P as n,b as o,l as p,M as r,g as s,I as t,f as u};
@@ -0,0 +1 @@
1
+ let e=require(`viem`),t=require(`@frak-labs/frame-connector`);function n({domain:t}={}){return(0,e.keccak256)((0,e.toHex)((t??window.location.host).replace(`www.`,``)))}const r=`frak-client-id`;function i(){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 a(){if(typeof window>`u`||!window.localStorage)return i();let e=localStorage.getItem(r);return e||(e=i(),localStorage.setItem(r,e)),e}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,o){let s=c(u({redirectUrl:t.redirectUrl,directExit:t.directExit,lang:t.lang,merchantId:n,metadata:{name:r,css:i,logoUrl:t.metadata?.logoUrl,homepageLink:t.metadata?.homepageLink},clientId:o??a()})),l=new URL(e);return l.pathname=`/sso`,l.searchParams.set(`p`,s),l.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:r,customizations:i,walletUrl:a}=e.config;if(t.openInSameWindow??!!t.redirectUrl)return await e.request({method:`frak_openSso`,params:[t,r.name,i?.css]});let o=t.ssoPopupUrl??l(a??`https://wallet.frak.id`,t,n(),r.name,i?.css),s=window.open(o,f,d);if(!s)throw Error(`Popup was blocked. Please allow popups for this site.`);return s.focus(),await e.request({method:`frak_openSso`,params:[t,r.name,i?.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)?`http://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}const v=`fCtx`;function y(t){if(t?.r)try{return o((0,e.hexToBytes)(t.r))}catch(e){console.error(`Error compressing Frak context`,{e,context:t})}}function b(t){if(!(!t||t.length===0))try{return{r:(0,e.bytesToHex)(s(t),{size:20})}}catch(e){console.error(`Error decompressing Frak context`,{e,context:t})}}function x({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(v);return t?b(t):null}function S({url:e,context:t}){if(!e)return null;let n=x({url:e}),r=n?{...n,...t}:t;if(!r.r)return null;let i=y(r);if(!i)return null;let a=new URL(e);return a.searchParams.set(v,i),a.toString()}function C(e){let t=new URL(e);return t.searchParams.delete(v),t.toString()}function w({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?C(n):S({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}const T={compress:y,decompress:b,parse:x,update:S,remove:C,replaceUrl:w},E=`frak-merchant-id`;let D,O;async function k(e,t){if(D)return D;if(typeof window<`u`){let e=window.sessionStorage.getItem(E);if(e)return D=e,e}if(O)return O;O=A(e,t);let n=await O;return O=void 0,n}async function A(e,t){let n=e??(typeof window<`u`?window.location.hostname:``);if(n)try{let e=_(t),r=await fetch(`${e}/user/merchant/resolve?domain=${encodeURIComponent(n)}`);if(!r.ok){console.warn(`[Frak SDK] Merchant lookup failed for domain ${n}: ${r.status}`);return}let i=await r.json();return D=i.merchantId,typeof window<`u`&&window.sessionStorage.setItem(E,i.merchantId),D}catch(e){console.warn(`[Frak SDK] Failed to fetch merchantId:`,e);return}}function j(){D=void 0,O=void 0,typeof window<`u`&&window.sessionStorage.removeItem(E)}async function M(e,t){return e.metadata?.merchantId?e.metadata.merchantId:k(void 0,t)}function N(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,`a`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return l}});
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "url": "https://twitter.com/QNivelais"
12
12
  }
13
13
  ],
14
- "version": "0.1.0",
14
+ "version": "0.1.1-beta.2c88e0f4",
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",
@@ -34,7 +34,8 @@
34
34
  "type": "module",
35
35
  "files": [
36
36
  "/dist",
37
- "/cdn"
37
+ "/cdn",
38
+ "/src"
38
39
  ],
39
40
  "browser": "./cdn/bundle.js",
40
41
  "exports": {
@@ -60,17 +61,6 @@
60
61
  "default": "./dist/actions.cjs"
61
62
  }
62
63
  },
63
- "./interactions": {
64
- "development": "./src/interactions/index.ts",
65
- "import": {
66
- "types": "./dist/interactions.d.ts",
67
- "default": "./dist/interactions.js"
68
- },
69
- "require": {
70
- "types": "./dist/interactions.d.cts",
71
- "default": "./dist/interactions.cjs"
72
- }
73
- },
74
64
  "./bundle": {
75
65
  "import": {
76
66
  "types": "./dist/bundle.d.ts",
@@ -86,33 +76,37 @@
86
76
  "lint": "biome lint .",
87
77
  "format:check": "biome check .",
88
78
  "format": "biome check --write .",
89
- "clean": "rimraf dist",
90
- "build": "rslib build",
91
- "build:watch": "rslib build --watch",
79
+ "clean": "rimraf dist cdn",
80
+ "build": "tsdown",
81
+ "build:watch": "tsdown --watch",
92
82
  "check-exports": "attw --pack --profile node16 .",
93
- "typecheck": "tsc --noEmit",
83
+ "typecheck": "tsgo --noEmit",
84
+ "test": "vitest",
85
+ "test:ui": "vitest --ui",
86
+ "test:coverage": "vitest --coverage",
94
87
  "prepublish": "bun run lint && bun run build",
95
88
  "publish": "echo 'Publishing core...'"
96
89
  },
97
90
  "peerDependencies": {
98
- "viem": "^2.23.14"
91
+ "viem": "^2.x"
99
92
  },
100
93
  "dependencies": {
101
- "@frak-labs/frame-connector": "0.1.0",
102
- "@jsonjoy.com/json-pack": "^1.2.0",
103
- "@openpanel/web": "^1.0.1"
94
+ "@frak-labs/frame-connector": "0.1.0-beta.2c88e0f4",
95
+ "@openpanel/web": "^1.0.7"
104
96
  },
105
97
  "devDependencies": {
106
98
  "@arethetypeswrong/cli": "^0.18.2",
107
99
  "@frak-labs/dev-tooling": "0.0.0",
108
- "@microsoft/api-extractor": "^7.52.8",
109
- "@rsbuild/plugin-node-polyfill": "^1.3.0",
110
- "@rslib/core": "^0.9.2",
111
- "@types/node": "^24.0.1",
112
- "dotenv": "^17.0.0",
113
- "typescript": "^5.8.3"
114
- },
115
- "browserslist": [
116
- "extends @frak-labs/browserslist-config"
117
- ]
100
+ "@frak-labs/test-foundation": "0.1.0",
101
+ "@rolldown/plugin-node-polyfills": "^1.0.3",
102
+ "@types/jsdom": "^27.0.0",
103
+ "@types/node": "^24.10.13",
104
+ "@vitest/coverage-v8": "^4.0.18",
105
+ "@vitest/ui": "^4.0.18",
106
+ "jsdom": "^28.0.0",
107
+ "tsdown": "^0.20.3",
108
+ "typescript": "^5.9.3",
109
+ "viem": "^2.39.0",
110
+ "vitest": "^4.0.18"
111
+ }
118
112
  }