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

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