@frak-labs/core-sdk 0.1.0 → 0.1.1-beta.4dfea079

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-CscYhyUi.d.cts +525 -0
  12. package/dist/computeLegacyProductId-WbD1gXV9.d.ts +525 -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-CC1-loUk.d.cts +1019 -0
  18. package/dist/openSso-tkqaDQLV.d.ts +1019 -0
  19. package/dist/setupClient-BjIbK6XJ.cjs +13 -0
  20. package/dist/setupClient-D_HId3e2.js +13 -0
  21. package/dist/siweAuthenticate-B_Z2OZmj.cjs +1 -0
  22. package/dist/siweAuthenticate-CQ4OfPuA.js +1 -0
  23. package/dist/siweAuthenticate-CR4Dpji6.d.cts +467 -0
  24. package/dist/siweAuthenticate-udoruuy9.d.ts +467 -0
  25. package/dist/trackEvent-CGIryq5h.cjs +1 -0
  26. package/dist/trackEvent-YfUh4jrx.js +1 -0
  27. package/package.json +24 -30
  28. package/src/actions/displayEmbeddedWallet.test.ts +194 -0
  29. package/src/actions/displayEmbeddedWallet.ts +20 -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 +9 -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 +24 -0
  43. package/src/actions/trackPurchaseStatus.test.ts +287 -0
  44. package/src/actions/trackPurchaseStatus.ts +56 -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 +289 -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 +174 -0
  62. package/src/constants/interactionTypes.ts +15 -0
  63. package/src/constants/locales.ts +14 -0
  64. package/src/index.ts +110 -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 +75 -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 +146 -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 +14 -0
  106. package/src/utils/deepLinkWithFallback.test.ts +243 -0
  107. package/src/utils/deepLinkWithFallback.ts +97 -0
  108. package/src/utils/formatAmount.test.ts +113 -0
  109. package/src/utils/formatAmount.ts +18 -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 +564 -0
  120. package/src/utils/merchantId.ts +122 -0
  121. package/src/utils/sso.ts +126 -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 +31 -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,1019 @@
1
+ import { Address, Hex } from "viem";
2
+ import { LifecycleMessage, RpcClient } from "@frak-labs/frame-connector";
3
+ import { OpenPanel } from "@openpanel/web";
4
+ import { SiweMessage } from "viem/siwe";
5
+
6
+ //#region src/types/config.d.ts
7
+ /**
8
+ * All the currencies available
9
+ * @category Config
10
+ */
11
+ type Currency = "eur" | "usd" | "gbp";
12
+ /**
13
+ * All the languages available
14
+ * @category Config
15
+ */
16
+ type Language = "fr" | "en";
17
+ /**
18
+ * Configuration for the Frak Wallet SDK
19
+ * @category Config
20
+ */
21
+ type FrakWalletSdkConfig = {
22
+ /**
23
+ * The Frak wallet url
24
+ * @defaultValue "https://wallet.frak.id"
25
+ */
26
+ walletUrl?: string;
27
+ /**
28
+ * Some metadata about your implementation of the Frak SDK
29
+ */
30
+ metadata: {
31
+ /**
32
+ * Your application name (will be displayed in a few modals and in SSO)
33
+ */
34
+ name: string;
35
+ /**
36
+ * Your merchant ID from the Frak dashboard (UUID format)
37
+ * Used for referral tracking and analytics
38
+ * If not provided, will be auto-fetched from the backend using your domain
39
+ */
40
+ merchantId?: string;
41
+ /**
42
+ * Language to display in the modal
43
+ * If undefined, will default to the browser language
44
+ */
45
+ lang?: Language;
46
+ /**
47
+ * The currency to display in the modal
48
+ * @defaultValue `"eur"`
49
+ */
50
+ currency?: Currency;
51
+ /**
52
+ * The logo URL that will be displayed in a few components
53
+ */
54
+ logoUrl?: string;
55
+ /**
56
+ * The homepage link that could be displayed in a few components
57
+ */
58
+ homepageLink?: string;
59
+ };
60
+ /**
61
+ * Some customization for the modal
62
+ */
63
+ customizations?: {
64
+ /**
65
+ * Custom CSS styles to apply to the modals and components
66
+ */
67
+ css?: `${string}.css`;
68
+ /**
69
+ * Custom i18n configuration for the modal
70
+ */
71
+ i18n?: I18nConfig;
72
+ };
73
+ /**
74
+ * The domain name of your application
75
+ * @defaultValue window.location.host
76
+ */
77
+ domain?: string;
78
+ };
79
+ /**
80
+ * Custom i18n configuration for the modal
81
+ * See [i18next json format](https://www.i18next.com/misc/json-format#i18next-json-v4)
82
+ *
83
+ * Available variables
84
+ * - `{{ productName }}` : The name of your website (`metadata.name`)
85
+ * - `{{ productOrigin }}` : The origin url of your website
86
+ * - `{{ estimatedReward }}` : The estimated reward for the user (based on the specific `targetInteraction` you can specify, or the max referrer reward if no target interaction is specified)
87
+ *
88
+ * Context of the translation [see i18n context](https://www.i18next.com/translation-function/context)
89
+ * - For modal display, the key of the final action (`sharing`, `reward`, or undefined)
90
+ * - For embedded wallet display, the key of the logged in action (`sharing` or undefined)
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * // Multi language config
95
+ * const multiI18n = {
96
+ * fr: {
97
+ * "sdk.modal.title": "Titre de modal",
98
+ * "sdk.modal.description": "Description de modal, avec {{ estimatedReward }} de gains possible",
99
+ * },
100
+ * en: "https://example.com/en.json"
101
+ * }
102
+ *
103
+ * // Single language config
104
+ * const singleI18n = {
105
+ * "sdk.modal.title": "Modal title",
106
+ * "sdk.modal.description": "Modal description, with {{ estimatedReward }} of gains possible",
107
+ * }
108
+ * ```
109
+ *
110
+ * @category Config
111
+ */
112
+ type I18nConfig = Record<Language, LocalizedI18nConfig> | LocalizedI18nConfig;
113
+ /**
114
+ * A localized i18n config
115
+ * @category Config
116
+ */
117
+ type LocalizedI18nConfig = `${string}.css` | {
118
+ [key: string]: string;
119
+ };
120
+ //#endregion
121
+ //#region src/types/lifecycle/client.d.ts
122
+ /**
123
+ * Event related to the iframe lifecycle
124
+ * @ignore
125
+ */
126
+ type ClientLifecycleEvent = CustomCssEvent | CustomI18nEvent | RestoreBackupEvent | HearbeatEvent | HandshakeResponse | SsoRedirectCompleteEvent | DeepLinkFailedEvent;
127
+ type CustomCssEvent = {
128
+ clientLifecycle: "modal-css";
129
+ data: {
130
+ cssLink: string;
131
+ };
132
+ };
133
+ type CustomI18nEvent = {
134
+ clientLifecycle: "modal-i18n";
135
+ data: {
136
+ i18n: I18nConfig;
137
+ };
138
+ };
139
+ type RestoreBackupEvent = {
140
+ clientLifecycle: "restore-backup";
141
+ data: {
142
+ backup: string;
143
+ };
144
+ };
145
+ type HearbeatEvent = {
146
+ clientLifecycle: "heartbeat";
147
+ data?: never;
148
+ };
149
+ type HandshakeResponse = {
150
+ clientLifecycle: "handshake-response";
151
+ data: {
152
+ token: string;
153
+ currentUrl: string;
154
+ /**
155
+ * The anonymous client ID for identity tracking
156
+ * Generated by SDK, stored in partner site's localStorage
157
+ */
158
+ clientId: string;
159
+ /**
160
+ * Pending merge token extracted from URL (?fmt= parameter)
161
+ * When present, listener should execute identity merge in background
162
+ * URL is cleaned after handshake response is sent
163
+ */
164
+ pendingMergeToken?: string;
165
+ /**
166
+ * Explicit domain from SDK config (FrakWalletSdkConfig.domain)
167
+ * When present, listener should prefer this over URL-derived domain
168
+ * for merchant resolution (handles proxied/tunneled environments)
169
+ */
170
+ configDomain?: string;
171
+ };
172
+ };
173
+ type SsoRedirectCompleteEvent = {
174
+ clientLifecycle: "sso-redirect-complete";
175
+ data: {
176
+ compressed: string;
177
+ };
178
+ };
179
+ type DeepLinkFailedEvent = {
180
+ clientLifecycle: "deep-link-failed";
181
+ data: {
182
+ originalUrl: string;
183
+ };
184
+ };
185
+ //#endregion
186
+ //#region src/types/lifecycle/iframe.d.ts
187
+ /**
188
+ * Event related to the iframe lifecycle
189
+ * @ignore
190
+ */
191
+ type IFrameLifecycleEvent = {
192
+ iframeLifecycle: "connected" | "show" | "hide" | "remove-backup";
193
+ data?: never;
194
+ } | DoBackupEvent | HandshakeRequestEvent | RedirectRequestEvent;
195
+ type DoBackupEvent = {
196
+ iframeLifecycle: "do-backup";
197
+ data: {
198
+ backup?: string;
199
+ };
200
+ };
201
+ type HandshakeRequestEvent = {
202
+ iframeLifecycle: "handshake";
203
+ data: {
204
+ token: string;
205
+ };
206
+ };
207
+ type RedirectRequestEvent = {
208
+ iframeLifecycle: "redirect";
209
+ data: {
210
+ /**
211
+ * The base url to redirect to
212
+ * If it contain a query param `u`, the client need will suffix the current url to the base url
213
+ */
214
+ baseRedirectUrl: string;
215
+ /**
216
+ * Optional merge token for anonymous identity merging
217
+ * When provided, appended as ?fmt= query parameter to the final redirect URL
218
+ * Used when redirecting out of social browsers to preserve identity across contexts
219
+ */
220
+ mergeToken?: string;
221
+ };
222
+ };
223
+ //#endregion
224
+ //#region src/constants/interactionTypes.d.ts
225
+ /**
226
+ * The supported interaction type keys
227
+ *
228
+ * - `referral` - User arrived via a referral link
229
+ * - `create_referral_link` - User created/shared a referral link
230
+ * - `purchase` - User completed a purchase
231
+ * - `custom.${string}` - Custom interaction type defined per campaign
232
+ *
233
+ * @inline
234
+ */
235
+ type InteractionTypeKey = "referral" | "create_referral_link" | "purchase" | `custom.${string}`;
236
+ //#endregion
237
+ //#region src/types/rpc/modal/generic.d.ts
238
+ /**
239
+ * Represent a generic modal step type
240
+ * @ignore
241
+ * @inline
242
+ */
243
+ type GenericModalStepType<TKey, TParams, TReturns> = {
244
+ key: TKey;
245
+ params: TParams extends never ? ModalStepMetadata : ModalStepMetadata & TParams;
246
+ returns: TReturns;
247
+ };
248
+ /**
249
+ * Metadata that can be used to customize a modal step
250
+ * @group Modal Display
251
+ * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
252
+ */
253
+ type ModalStepMetadata = {
254
+ metadata?: {
255
+ /**
256
+ * Custom title for the step
257
+ * If none provided, it will use an internationalized text
258
+ * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
259
+ */
260
+ title?: string;
261
+ /**
262
+ * Custom description for the step
263
+ * If none provided, it will use an internationalized text
264
+ * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
265
+ */
266
+ description?: string;
267
+ /**
268
+ * Custom text for the primary action of the step
269
+ * If none provided, it will use an internationalized text
270
+ * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
271
+ */
272
+ primaryActionText?: string;
273
+ /**
274
+ * Custom text for the secondary action of the step
275
+ * If none provided, it will use an internationalized text
276
+ * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
277
+ */
278
+ secondaryActionText?: string;
279
+ };
280
+ };
281
+ //#endregion
282
+ //#region src/types/rpc/modal/final.d.ts
283
+ /**
284
+ * The final modal step type, could be used to display sharing options or a success reward screen.
285
+ *
286
+ * **Input**: What type final step to display?
287
+ * **Output**: None
288
+ *
289
+ * @group Modal Display
290
+ */
291
+ type FinalModalStepType = GenericModalStepType<"final", {
292
+ dismissedMetadata?: ModalStepMetadata["metadata"];
293
+ action: FinalActionType;
294
+ autoSkip?: boolean;
295
+ }, object>;
296
+ /**
297
+ * The different types of final actions we can display in the final step
298
+ * @group Modal Display
299
+ */
300
+ type FinalActionType = {
301
+ key: "sharing";
302
+ options?: {
303
+ /**
304
+ * @deprecated Use the top level `config.metadata.i18n` instead
305
+ */
306
+ popupTitle?: string;
307
+ /**
308
+ * @deprecated Use the top level `config.metadata.i18n` instead
309
+ */
310
+ text?: string;
311
+ link?: string;
312
+ };
313
+ } | {
314
+ key: "reward";
315
+ options?: never;
316
+ };
317
+ //#endregion
318
+ //#region src/types/rpc/sso.d.ts
319
+ /**
320
+ * SSO Metadata
321
+ */
322
+ type SsoMetadata = {
323
+ /**
324
+ * URL to your client, if provided will be displayed in the SSO header
325
+ */
326
+ logoUrl?: string;
327
+ /**
328
+ * Link to your homepage, if referenced your app name will contain a link on the sso page
329
+ */
330
+ homepageLink?: string;
331
+ };
332
+ /**
333
+ * Params for preparing SSO (generating URL)
334
+ * Same as OpenSsoParamsType but without openInSameWindow (popup-only operation)
335
+ * @group RPC Schema
336
+ */
337
+ type PrepareSsoParamsType = {
338
+ /**
339
+ * Redirect URL after the SSO (optional)
340
+ */
341
+ redirectUrl?: string;
342
+ /**
343
+ * If the SSO should directly exit after completion
344
+ * @defaultValue true
345
+ */
346
+ directExit?: boolean;
347
+ /**
348
+ * Language of the SSO page (optional)
349
+ * It will default to the current user language (or "en" if unsupported language)
350
+ */
351
+ lang?: "en" | "fr";
352
+ /**
353
+ * Custom SSO metadata
354
+ */
355
+ metadata?: SsoMetadata;
356
+ };
357
+ /**
358
+ * Response after preparing SSO
359
+ * @group RPC Schema
360
+ */
361
+ type PrepareSsoReturnType = {
362
+ /**
363
+ * The SSO URL that should be opened in a popup
364
+ */
365
+ ssoUrl: string;
366
+ };
367
+ /**
368
+ * Response after an SSO has been openned
369
+ */
370
+ type OpenSsoReturnType = {
371
+ /**
372
+ * Optional wallet address, returned when SSO completes via postMessage
373
+ * Note: Only present when SSO flow completes (not immediately on open)
374
+ */
375
+ wallet?: Hex;
376
+ };
377
+ /**
378
+ * Params to start a SSO
379
+ * @group RPC Schema
380
+ */
381
+ type OpenSsoParamsType = PrepareSsoParamsType & {
382
+ /**
383
+ * Indicate whether we want todo the flow within the same window context, or if we want to do it with an external popup window openned
384
+ * Note: Default true if redirectUrl is present, otherwise, false
385
+ */
386
+ openInSameWindow?: boolean;
387
+ /**
388
+ * Custom SSO popup url if user want additionnal customisation
389
+ */
390
+ ssoPopupUrl?: string;
391
+ };
392
+ //#endregion
393
+ //#region src/types/rpc/modal/login.d.ts
394
+ /** @inline */
395
+ type LoginWithSso = {
396
+ allowSso: true;
397
+ ssoMetadata?: SsoMetadata;
398
+ };
399
+ /** @inline */
400
+ type LoginWithoutSso = {
401
+ allowSso?: false;
402
+ ssoMetadata?: never;
403
+ };
404
+ /**
405
+ * The login step for a Modal
406
+ *
407
+ * **Input**: Do we allow SSO or not? Is yes then the SSO metadata
408
+ * **Output**: The logged in wallet address
409
+ *
410
+ * @group Modal Display
411
+ */
412
+ type LoginModalStepType = GenericModalStepType<"login", LoginWithSso | LoginWithoutSso, {
413
+ wallet: Address;
414
+ webauthnProof?: {
415
+ challenge: Hex;
416
+ authenticatorResponse: string;
417
+ };
418
+ }>;
419
+ //#endregion
420
+ //#region src/types/rpc/modal/siweAuthenticate.d.ts
421
+ /**
422
+ * Parameters used send a SIWE rpc request
423
+ */
424
+ type SiweAuthenticationParams = Omit<SiweMessage, "address" | "chainId" | "expirationTime" | "issuedAt" | "notBefore"> & {
425
+ expirationTimeTimestamp?: number;
426
+ notBeforeTimestamp?: number;
427
+ };
428
+ /**
429
+ * Return type of the Siwe transaction rpc request
430
+ * @inline
431
+ */
432
+ type SiweAuthenticateReturnType = {
433
+ signature: Hex;
434
+ message: string;
435
+ };
436
+ /**
437
+ * The SIWE authentication step for a Modal
438
+ *
439
+ * **Input**: SIWE message parameters
440
+ * **Output**: SIWE result (message signed and wallet signature)
441
+ *
442
+ * @group Modal Display
443
+ */
444
+ type SiweAuthenticateModalStepType = GenericModalStepType<"siweAuthenticate", {
445
+ siwe: SiweAuthenticationParams;
446
+ }, SiweAuthenticateReturnType>;
447
+ //#endregion
448
+ //#region src/types/rpc/modal/transaction.d.ts
449
+ /**
450
+ * Generic format representing a tx to be sent
451
+ */
452
+ type SendTransactionTxType = {
453
+ to: Address;
454
+ data?: Hex;
455
+ value?: Hex;
456
+ };
457
+ /**
458
+ * Return type of the send transaction rpc request
459
+ * @inline
460
+ */
461
+ type SendTransactionReturnType = {
462
+ hash: Hex;
463
+ };
464
+ /**
465
+ * The send transaction step for a Modal
466
+ *
467
+ * **Input**: Either a single tx or an array of tx to be sent
468
+ * **Output**: The hash of the tx(s) hash (in case of multiple tx, still returns a single hash because it's bundled on the wallet level)
469
+ *
470
+ * @group Modal Display
471
+ */
472
+ type SendTransactionModalStepType = GenericModalStepType<"sendTransaction", {
473
+ tx: SendTransactionTxType | SendTransactionTxType[];
474
+ }, SendTransactionReturnType>;
475
+ //#endregion
476
+ //#region src/types/rpc/displayModal.d.ts
477
+ /**
478
+ * Generic type of steps we will display in the modal to the end user
479
+ * @group Modal Display
480
+ */
481
+ type ModalStepTypes = LoginModalStepType | SiweAuthenticateModalStepType | SendTransactionModalStepType | FinalModalStepType;
482
+ /**
483
+ * Type for the result of a modal request
484
+ * Just the `returns` type of each `ModalStepTypes`
485
+ * @typeParam T - The list of modal steps we expect to have in the modal
486
+ * @group Modal Display
487
+ * @group RPC Schema
488
+ */
489
+ type ModalRpcStepsResultType<T extends ModalStepTypes[] = ModalStepTypes[]> = { [K in T[number]["key"]]: Extract<T[number], {
490
+ key: K;
491
+ }>["returns"] };
492
+ /**
493
+ * Type for the RPC input of a modal
494
+ * Just the `params` type of each `ModalStepTypes`
495
+ * @typeParam T - The list of modal steps we expect to have in the modal
496
+ * @group Modal Display
497
+ * @group RPC Schema
498
+ */
499
+ type ModalRpcStepsInput<T extends ModalStepTypes[] = ModalStepTypes[]> = { [K in T[number]["key"]]?: Extract<T[number], {
500
+ key: K;
501
+ }>["params"] };
502
+ /**
503
+ * RPC metadata for the modal, used on top level modal configuration
504
+ * @group Modal Display
505
+ * @group RPC Schema
506
+ */
507
+ type ModalRpcMetadata = {
508
+ header?: {
509
+ title?: string;
510
+ icon?: string;
511
+ };
512
+ targetInteraction?: InteractionTypeKey;
513
+ /**
514
+ * Some i18n override for the displayed modal (i.e. update the displayed text only for this modal)
515
+ */
516
+ i18n?: I18nConfig;
517
+ } & ({
518
+ isDismissible: true;
519
+ /**
520
+ * @deprecated Use `config.customizations.i18n` or `metadata.i18n` instead
521
+ */
522
+ dismissActionTxt?: string;
523
+ } | {
524
+ isDismissible?: false;
525
+ dismissActionTxt?: never;
526
+ });
527
+ /**
528
+ * Params used to display a modal
529
+ * @typeParam T - The list of modal steps we expect to have in the modal
530
+ * @group Modal Display
531
+ */
532
+ type DisplayModalParamsType<T extends ModalStepTypes[]> = {
533
+ steps: ModalRpcStepsInput<T>;
534
+ metadata?: ModalRpcMetadata;
535
+ };
536
+ //#endregion
537
+ //#region src/types/rpc/embedded/loggedIn.d.ts
538
+ /**
539
+ * The different type of action we can have on the embedded view (once the user is logged in)
540
+ *
541
+ * @group Embedded wallet
542
+ */
543
+ type EmbeddedViewActionSharing = {
544
+ key: "sharing";
545
+ /**
546
+ * Some sharing options
547
+ */
548
+ options?: {
549
+ /**
550
+ * The title that will be displayed on the system popup once the system sharing window is open
551
+ * @deprecated Use the top level `config.metadata.i18n` instead
552
+ */
553
+ popupTitle?: string;
554
+ /**
555
+ * The text that will be shared alongside the link.
556
+ * Can contain the variable `{LINK}` to specify where the link is placed, otherwise it will be added at the end
557
+ * @deprecated Use the top level `config.metadata.i18n` instead
558
+ */
559
+ text?: string;
560
+ /**
561
+ * The link to be shared (will be suffixed with the Frak sharing context)
562
+ */
563
+ link?: string;
564
+ };
565
+ };
566
+ /**
567
+ * The action to display on the logged out embedded view when the user is referred
568
+ *
569
+ * @group Embedded wallet
570
+ */
571
+ type EmbeddedViewActionReferred = {
572
+ key: "referred";
573
+ /**
574
+ * No options for a referred action
575
+ */
576
+ options?: never;
577
+ };
578
+ /**
579
+ * Some configuration options for the embedded view
580
+ *
581
+ * @group Embedded wallet
582
+ */
583
+ type LoggedInEmbeddedView = {
584
+ /**
585
+ * The main action to display on the logged in embedded view
586
+ */
587
+ action?: EmbeddedViewActionSharing | EmbeddedViewActionReferred;
588
+ };
589
+ //#endregion
590
+ //#region src/types/rpc/embedded/loggedOut.d.ts
591
+ /**
592
+ * The view when a user is logged out
593
+ * @group Embedded wallet
594
+ */
595
+ type LoggedOutEmbeddedView = {
596
+ /**
597
+ * Metadata option when displaying the embedded view
598
+ */
599
+ metadata?: {
600
+ /**
601
+ * The main CTA for the logged out view
602
+ * - can include some variable, available ones are:
603
+ * - `{REWARD}` -> The maximum reward a user can receive when interacting on your website
604
+ * - can be formatted in markdown
605
+ *
606
+ * If not set, it will default to a internationalized message
607
+ * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
608
+ */
609
+ text?: string;
610
+ /**
611
+ * The text that will be displayed on the login button
612
+ *
613
+ * If not set, it will default to a internationalized message
614
+ * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
615
+ */
616
+ buttonText?: string;
617
+ };
618
+ };
619
+ //#endregion
620
+ //#region src/types/rpc/embedded/index.d.ts
621
+ /**
622
+ * The params used to display the embedded wallet
623
+ *
624
+ * @group Embedded wallet
625
+ */
626
+ type DisplayEmbeddedWalletParamsType = {
627
+ /**
628
+ * The embedded view to display once the user is logged in
629
+ */
630
+ loggedIn?: LoggedInEmbeddedView;
631
+ /**
632
+ * The embedded view to display once the user is logged out
633
+ */
634
+ loggedOut?: LoggedOutEmbeddedView;
635
+ /**
636
+ * Some metadata to customize the embedded view
637
+ */
638
+ metadata?: {
639
+ /**
640
+ * The logo to display on the embedded wallet
641
+ * If undefined, will default to no logo displayed
642
+ */
643
+ logo?: string;
644
+ /**
645
+ * Link to the homepage of the calling website
646
+ * If undefined, will default to the domain of the calling website
647
+ */
648
+ homepageLink?: string;
649
+ /**
650
+ * The target interaction behind this modal
651
+ */
652
+ targetInteraction?: InteractionTypeKey;
653
+ /**
654
+ * The position of the component
655
+ */
656
+ position?: "left" | "right";
657
+ /**
658
+ * Some i18n override for the displayed modal (i.e. update the displayed text only for this modal)
659
+ */
660
+ i18n?: I18nConfig;
661
+ };
662
+ };
663
+ /**
664
+ * The result of the display embedded wallet rpc request
665
+ *
666
+ * @group Embedded wallet
667
+ */
668
+ type DisplayEmbeddedWalletResultType = {
669
+ wallet: Address;
670
+ };
671
+ //#endregion
672
+ //#region src/types/rpc/interaction.d.ts
673
+ /**
674
+ * Parameters for sending interactions via RPC
675
+ *
676
+ * Note: merchantId and clientId come from WalletRpcContext
677
+ * and are NOT included in the params - they are resolved by the listener
678
+ *
679
+ * @group RPC Schema
680
+ */
681
+ type SendInteractionParamsType = {
682
+ type: "arrival";
683
+ referrerWallet?: Address;
684
+ landingUrl?: string;
685
+ utmSource?: string;
686
+ utmMedium?: string;
687
+ utmCampaign?: string;
688
+ utmTerm?: string;
689
+ utmContent?: string;
690
+ } | {
691
+ type: "sharing";
692
+ } | {
693
+ type: "custom";
694
+ customType: string;
695
+ data?: Record<string, unknown>;
696
+ idempotencyKey?: string;
697
+ };
698
+ //#endregion
699
+ //#region src/types/rpc/merchantInformation.d.ts
700
+ /**
701
+ * The type for the amount of tokens
702
+ */
703
+ type TokenAmountType = {
704
+ amount: number;
705
+ eurAmount: number;
706
+ usdAmount: number;
707
+ gbpAmount: number;
708
+ };
709
+ /**
710
+ * A tier definition for tiered rewards
711
+ */
712
+ type RewardTier = {
713
+ minValue: number;
714
+ maxValue?: number;
715
+ amount: TokenAmountType;
716
+ };
717
+ /**
718
+ * Estimated reward amount — discriminated union by payout type
719
+ *
720
+ * - `fixed`: A known token amount (with fiat equivalents)
721
+ * - `percentage`: A percent of a purchase field (e.g. 5% of purchase_amount), with optional min/max caps
722
+ * - `tiered`: Amount depends on a field value matching tier brackets
723
+ */
724
+ type EstimatedReward = {
725
+ payoutType: "fixed";
726
+ amount: TokenAmountType;
727
+ } | {
728
+ payoutType: "percentage";
729
+ percent: number;
730
+ percentOf: string;
731
+ maxAmount?: TokenAmountType;
732
+ minAmount?: TokenAmountType;
733
+ } | {
734
+ payoutType: "tiered";
735
+ tierField: string;
736
+ tiers: RewardTier[];
737
+ };
738
+ /**
739
+ * Response of the `frak_getMerchantInformation` RPC method
740
+ * @group RPC Schema
741
+ */
742
+ type GetMerchantInformationReturnType = {
743
+ /**
744
+ * Current merchant id
745
+ */
746
+ id: string;
747
+ /**
748
+ * Some metadata
749
+ */
750
+ onChainMetadata: {
751
+ /**
752
+ * Name of the merchant on-chain
753
+ */
754
+ name: string;
755
+ /**
756
+ * Domain of the merchant on-chain
757
+ */
758
+ domain: string;
759
+ };
760
+ rewards: {
761
+ token?: Address;
762
+ campaignId: string;
763
+ interactionTypeKey: InteractionTypeKey;
764
+ referrer?: EstimatedReward;
765
+ referee?: EstimatedReward;
766
+ }[];
767
+ };
768
+ //#endregion
769
+ //#region src/types/rpc/walletStatus.d.ts
770
+ /**
771
+ * RPC Response for the method `frak_listenToWalletStatus`
772
+ * @group RPC Schema
773
+ */
774
+ type WalletStatusReturnType = WalletConnected | WalletNotConnected;
775
+ /**
776
+ * @ignore
777
+ * @inline
778
+ */
779
+ type WalletConnected = {
780
+ key: "connected";
781
+ wallet: Address;
782
+ interactionToken?: string;
783
+ };
784
+ /**
785
+ * @ignore
786
+ * @inline
787
+ */
788
+ type WalletNotConnected = {
789
+ key: "not-connected";
790
+ wallet?: never;
791
+ interactionToken?: never;
792
+ };
793
+ //#endregion
794
+ //#region src/types/rpc.d.ts
795
+ /**
796
+ * RPC interface that's used for the iframe communication
797
+ *
798
+ * Define all the methods available within the iFrame RPC client with response type annotations
799
+ *
800
+ * @group RPC Schema
801
+ *
802
+ * @remarks
803
+ * Each method in the schema now includes a ResponseType field that indicates:
804
+ * - "promise": One-shot request that resolves once
805
+ * - "stream": Streaming request that can emit multiple values
806
+ *
807
+ * ### Methods:
808
+ *
809
+ * #### frak_listenToWalletStatus
810
+ * - Params: None
811
+ * - Returns: {@link WalletStatusReturnType}
812
+ * - Response Type: stream (emits updates when wallet status changes)
813
+ *
814
+ * #### frak_displayModal
815
+ * - Params: [requests: {@link ModalRpcStepsInput}, metadata?: {@link ModalRpcMetadata}, configMetadata: {@link FrakWalletSdkConfig}["metadata"]]
816
+ * - Returns: {@link ModalRpcStepsResultType}
817
+ * - Response Type: promise (one-shot)
818
+ *
819
+ * #### frak_sso
820
+ * - Params: [params: {@link OpenSsoParamsType}, name: string, customCss?: string]
821
+ * - Returns: {@link OpenSsoReturnType}
822
+ * - Response Type: promise (one-shot)
823
+ *
824
+ * #### frak_getMerchantInformation
825
+ * - Params: None
826
+ * - Returns: {@link GetMerchantInformationReturnType}
827
+ * - Response Type: promise (one-shot)
828
+ *
829
+ * #### frak_displayEmbeddedWallet
830
+ * - Params: [request: {@link DisplayEmbeddedWalletParamsType}, metadata: {@link FrakWalletSdkConfig}["metadata"]]
831
+ * - Returns: {@link DisplayEmbeddedWalletResultType}
832
+ * - Response Type: promise (one-shot)
833
+ */
834
+ type IFrameRpcSchema = [
835
+ /**
836
+ * Method used to listen to the wallet status
837
+ * This is a streaming method that emits updates when wallet status changes
838
+ */
839
+ {
840
+ Method: "frak_listenToWalletStatus";
841
+ Parameters?: undefined;
842
+ ReturnType: WalletStatusReturnType;
843
+ },
844
+ /**
845
+ * Method to display a modal with the provided steps
846
+ * This is a one-shot request
847
+ */
848
+ {
849
+ Method: "frak_displayModal";
850
+ Parameters: [requests: ModalRpcStepsInput, metadata: ModalRpcMetadata | undefined, configMetadata: FrakWalletSdkConfig["metadata"]];
851
+ ReturnType: ModalRpcStepsResultType;
852
+ },
853
+ /**
854
+ * Method to prepare SSO (generate URL for popup)
855
+ * Returns the SSO URL that should be opened in a popup
856
+ * Only used for popup flows (not redirect flows)
857
+ */
858
+ {
859
+ Method: "frak_prepareSso";
860
+ Parameters: [params: PrepareSsoParamsType, name: string, customCss?: string];
861
+ ReturnType: PrepareSsoReturnType;
862
+ },
863
+ /**
864
+ * Method to open/trigger SSO
865
+ * Either triggers redirect (if openInSameWindow/redirectUrl)
866
+ * Or waits for popup completion (if popup mode)
867
+ * This method handles BOTH redirect and popup flows
868
+ */
869
+ {
870
+ Method: "frak_openSso";
871
+ Parameters: [params: OpenSsoParamsType, name: string, customCss?: string];
872
+ ReturnType: OpenSsoReturnType;
873
+ },
874
+ /**
875
+ * Method to get current merchant information
876
+ * - Is merchant registered?
877
+ * - Does it have running campaign?
878
+ * - Estimated reward on actions
879
+ * This is a one-shot request
880
+ */
881
+ {
882
+ Method: "frak_getMerchantInformation";
883
+ Parameters?: undefined;
884
+ ReturnType: GetMerchantInformationReturnType;
885
+ },
886
+ /**
887
+ * Method to show the embedded wallet, with potential customization
888
+ * This is a one-shot request
889
+ */
890
+ {
891
+ Method: "frak_displayEmbeddedWallet";
892
+ Parameters: [request: DisplayEmbeddedWalletParamsType, metadata: FrakWalletSdkConfig["metadata"]];
893
+ ReturnType: DisplayEmbeddedWalletResultType;
894
+ },
895
+ /**
896
+ * Method to send interactions (arrival, sharing, custom events)
897
+ * Fire-and-forget method - no return value expected
898
+ * merchantId and clientId are resolved from context
899
+ */
900
+ {
901
+ Method: "frak_sendInteraction";
902
+ Parameters: [interaction: SendInteractionParamsType];
903
+ ReturnType: undefined;
904
+ }];
905
+ //#endregion
906
+ //#region src/types/transport.d.ts
907
+ /**
908
+ * IFrame transport interface
909
+ */
910
+ type IFrameTransport = {
911
+ /**
912
+ * Wait for the connection to be established
913
+ */
914
+ waitForConnection: Promise<boolean>;
915
+ /**
916
+ * Wait for the setup to be done
917
+ */
918
+ waitForSetup: Promise<void>;
919
+ /**
920
+ * Function used to perform a single request via the iframe transport
921
+ */
922
+ request: RpcClient<IFrameRpcSchema, LifecycleMessage>["request"];
923
+ /**
924
+ * Function used to listen to a request response via the iframe transport
925
+ */
926
+ listenerRequest: RpcClient<IFrameRpcSchema, LifecycleMessage>["listen"];
927
+ /**
928
+ * Function used to destroy the iframe transport
929
+ */
930
+ destroy: () => Promise<void>;
931
+ };
932
+ /**
933
+ * Represent an iframe event
934
+ */
935
+ type FrakLifecycleEvent = IFrameLifecycleEvent | ClientLifecycleEvent;
936
+ //#endregion
937
+ //#region src/types/client.d.ts
938
+ /**
939
+ * Representing a Frak client, used to interact with the Frak Wallet
940
+ */
941
+ type FrakClient = {
942
+ config: FrakWalletSdkConfig;
943
+ debugInfo: {
944
+ formatDebugInfo: (error: Error | unknown | string) => string;
945
+ };
946
+ openPanel?: OpenPanel;
947
+ } & IFrameTransport;
948
+ //#endregion
949
+ //#region src/types/context.d.ts
950
+ /**
951
+ * The current Frak Context
952
+ *
953
+ * For now, only contain a referrer address.
954
+ *
955
+ * @ignore
956
+ */
957
+ type FrakContext = {
958
+ r: Address;
959
+ };
960
+ //#endregion
961
+ //#region src/actions/openSso.d.ts
962
+ declare const ssoPopupFeatures = "menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800";
963
+ declare const ssoPopupName = "frak-sso";
964
+ /**
965
+ * Function used to open the SSO
966
+ * @param client - The current Frak Client
967
+ * @param args - The SSO parameters
968
+ *
969
+ * @description Two SSO flow modes:
970
+ *
971
+ * **Redirect Mode** (openInSameWindow: true):
972
+ * - Wallet generates URL and triggers redirect
973
+ * - Used when redirectUrl is provided
974
+ *
975
+ * **Popup Mode** (openInSameWindow: false/omitted):
976
+ * - SDK generates URL client-side (or uses provided ssoPopupUrl)
977
+ * - Opens popup synchronously (prevents popup blockers)
978
+ * - Waits for SSO completion via postMessage
979
+ *
980
+ * @example
981
+ * First we build the sso metadata
982
+ * ```ts
983
+ * // Build the metadata
984
+ * const metadata: SsoMetadata = {
985
+ * logoUrl: "https://my-app.com/logo.png",
986
+ * homepageLink: "https://my-app.com",
987
+ * };
988
+ * ```
989
+ *
990
+ * Then, either use it with direct exit (and so user is directly redirected to your website), or a custom redirect URL
991
+ * :::code-group
992
+ * ```ts [Popup (default)]
993
+ * // Opens in popup, SDK generates URL automatically
994
+ * await openSso(frakConfig, {
995
+ * directExit: true,
996
+ * metadata,
997
+ * });
998
+ * ```
999
+ * ```ts [Redirect]
1000
+ * // Opens in same window with redirect
1001
+ * await openSso(frakConfig, {
1002
+ * redirectUrl: "https://my-app.com/frak-sso",
1003
+ * metadata,
1004
+ * openInSameWindow: true,
1005
+ * });
1006
+ * ```
1007
+ * ```ts [Custom popup URL]
1008
+ * // Advanced: provide custom SSO URL
1009
+ * const { ssoUrl } = await prepareSso(frakConfig, { metadata });
1010
+ * await openSso(frakConfig, {
1011
+ * metadata,
1012
+ * ssoPopupUrl: `${ssoUrl}&custom=param`,
1013
+ * });
1014
+ * ```
1015
+ * :::
1016
+ */
1017
+ declare function openSso(client: FrakClient, args: OpenSsoParamsType): Promise<OpenSsoReturnType>;
1018
+ //#endregion
1019
+ export { SiweAuthenticateReturnType as A, ModalStepMetadata as B, ModalRpcStepsInput as C, SendTransactionReturnType as D, SendTransactionModalStepType as E, PrepareSsoParamsType as F, FrakWalletSdkConfig as G, IFrameLifecycleEvent as H, PrepareSsoReturnType as I, LocalizedI18nConfig as J, I18nConfig as K, SsoMetadata as L, LoginModalStepType as M, OpenSsoParamsType as N, SendTransactionTxType as O, OpenSsoReturnType as P, FinalActionType as R, ModalRpcMetadata as S, ModalStepTypes as T, ClientLifecycleEvent as U, InteractionTypeKey as V, Currency as W, LoggedOutEmbeddedView as _, FrakClient as a, LoggedInEmbeddedView as b, IFrameRpcSchema as c, GetMerchantInformationReturnType as d, RewardTier as f, DisplayEmbeddedWalletResultType as g, DisplayEmbeddedWalletParamsType as h, FrakContext as i, SiweAuthenticationParams as j, SiweAuthenticateModalStepType as k, WalletStatusReturnType as l, SendInteractionParamsType as m, ssoPopupFeatures as n, FrakLifecycleEvent as o, TokenAmountType as p, Language as q, ssoPopupName as r, IFrameTransport as s, openSso as t, EstimatedReward as u, EmbeddedViewActionReferred as v, ModalRpcStepsResultType as w, DisplayModalParamsType as x, EmbeddedViewActionSharing as y, FinalModalStepType as z };