@frak-labs/core-sdk 0.1.0-beta.afa252b0 → 0.1.0-beta.c7e026e5

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 (143) hide show
  1. package/cdn/bundle.iife.js +14 -0
  2. package/dist/actions-CEEObPYc.js +1 -0
  3. package/dist/actions-DbQhWYx8.cjs +1 -0
  4. package/dist/actions.cjs +1 -1
  5. package/dist/actions.d.cts +3 -1481
  6. package/dist/actions.d.ts +3 -1481
  7. package/dist/actions.js +1 -1
  8. package/dist/bundle.cjs +1 -13
  9. package/dist/bundle.d.cts +6 -2087
  10. package/dist/bundle.d.ts +6 -2087
  11. package/dist/bundle.js +1 -13
  12. package/dist/index-7OZ39x1U.d.ts +195 -0
  13. package/dist/index-C6FxkWPC.d.cts +511 -0
  14. package/dist/index-UFX7xCg3.d.ts +351 -0
  15. package/dist/index-d8xS4ryI.d.ts +511 -0
  16. package/dist/index-p4FqSp8z.d.cts +351 -0
  17. package/dist/index-zDq-VlKx.d.cts +195 -0
  18. package/dist/index.cjs +1 -13
  19. package/dist/index.d.cts +4 -1387
  20. package/dist/index.d.ts +4 -1387
  21. package/dist/index.js +1 -13
  22. package/dist/interaction-DMJ3ZfaF.d.cts +45 -0
  23. package/dist/interaction-KX1h9a7V.d.ts +45 -0
  24. package/dist/interactions-DnfM3oe0.js +1 -0
  25. package/dist/interactions-EIXhNLf6.cjs +1 -0
  26. package/dist/interactions.cjs +1 -1
  27. package/dist/interactions.d.cts +2 -182
  28. package/dist/interactions.d.ts +2 -182
  29. package/dist/interactions.js +1 -1
  30. package/dist/openSso-D--Airj6.d.cts +1018 -0
  31. package/dist/openSso-DsKJ4y0j.d.ts +1018 -0
  32. package/dist/productTypes-BUkXJKZ7.cjs +1 -0
  33. package/dist/productTypes-CGb1MmBF.js +1 -0
  34. package/dist/src-B_xO0AR6.cjs +13 -0
  35. package/dist/src-D2d52OZa.js +13 -0
  36. package/dist/trackEvent-CHnYa85W.js +1 -0
  37. package/dist/trackEvent-GuQm_1Nm.cjs +1 -0
  38. package/package.json +23 -18
  39. package/src/actions/displayEmbeddedWallet.test.ts +194 -0
  40. package/src/actions/displayEmbeddedWallet.ts +20 -0
  41. package/src/actions/displayModal.test.ts +387 -0
  42. package/src/actions/displayModal.ts +131 -0
  43. package/src/actions/getProductInformation.test.ts +133 -0
  44. package/src/actions/getProductInformation.ts +14 -0
  45. package/src/actions/index.ts +29 -0
  46. package/src/actions/openSso.test.ts +407 -0
  47. package/src/actions/openSso.ts +116 -0
  48. package/src/actions/prepareSso.test.ts +223 -0
  49. package/src/actions/prepareSso.ts +48 -0
  50. package/src/actions/referral/processReferral.ts +230 -0
  51. package/src/actions/referral/referralInteraction.test.ts +153 -0
  52. package/src/actions/referral/referralInteraction.ts +57 -0
  53. package/src/actions/sendInteraction.test.ts +219 -0
  54. package/src/actions/sendInteraction.ts +32 -0
  55. package/src/actions/trackPurchaseStatus.test.ts +287 -0
  56. package/src/actions/trackPurchaseStatus.ts +53 -0
  57. package/src/actions/watchWalletStatus.test.ts +372 -0
  58. package/src/actions/watchWalletStatus.ts +94 -0
  59. package/src/actions/wrapper/modalBuilder.test.ts +253 -0
  60. package/src/actions/wrapper/modalBuilder.ts +212 -0
  61. package/src/actions/wrapper/sendTransaction.test.ts +164 -0
  62. package/src/actions/wrapper/sendTransaction.ts +62 -0
  63. package/src/actions/wrapper/siweAuthenticate.test.ts +290 -0
  64. package/src/actions/wrapper/siweAuthenticate.ts +94 -0
  65. package/src/bundle.ts +3 -0
  66. package/src/clients/DebugInfo.ts +182 -0
  67. package/src/clients/createIFrameFrakClient.ts +287 -0
  68. package/src/clients/index.ts +3 -0
  69. package/src/clients/setupClient.test.ts +343 -0
  70. package/src/clients/setupClient.ts +73 -0
  71. package/src/clients/transports/iframeLifecycleManager.test.ts +399 -0
  72. package/src/clients/transports/iframeLifecycleManager.ts +90 -0
  73. package/src/constants/interactionTypes.ts +44 -0
  74. package/src/constants/locales.ts +14 -0
  75. package/src/constants/productTypes.ts +33 -0
  76. package/src/index.ts +101 -0
  77. package/src/interactions/index.ts +5 -0
  78. package/src/interactions/pressEncoder.test.ts +215 -0
  79. package/src/interactions/pressEncoder.ts +53 -0
  80. package/src/interactions/purchaseEncoder.test.ts +291 -0
  81. package/src/interactions/purchaseEncoder.ts +99 -0
  82. package/src/interactions/referralEncoder.test.ts +170 -0
  83. package/src/interactions/referralEncoder.ts +47 -0
  84. package/src/interactions/retailEncoder.test.ts +107 -0
  85. package/src/interactions/retailEncoder.ts +37 -0
  86. package/src/interactions/webshopEncoder.test.ts +56 -0
  87. package/src/interactions/webshopEncoder.ts +30 -0
  88. package/src/types/client.ts +14 -0
  89. package/src/types/compression.ts +22 -0
  90. package/src/types/config.ts +111 -0
  91. package/src/types/context.ts +13 -0
  92. package/src/types/index.ts +71 -0
  93. package/src/types/lifecycle/client.ts +46 -0
  94. package/src/types/lifecycle/iframe.ts +35 -0
  95. package/src/types/lifecycle/index.ts +2 -0
  96. package/src/types/rpc/displayModal.ts +84 -0
  97. package/src/types/rpc/embedded/index.ts +68 -0
  98. package/src/types/rpc/embedded/loggedIn.ts +55 -0
  99. package/src/types/rpc/embedded/loggedOut.ts +28 -0
  100. package/src/types/rpc/interaction.ts +43 -0
  101. package/src/types/rpc/modal/final.ts +46 -0
  102. package/src/types/rpc/modal/generic.ts +46 -0
  103. package/src/types/rpc/modal/index.ts +20 -0
  104. package/src/types/rpc/modal/login.ts +32 -0
  105. package/src/types/rpc/modal/openSession.ts +25 -0
  106. package/src/types/rpc/modal/siweAuthenticate.ts +37 -0
  107. package/src/types/rpc/modal/transaction.ts +33 -0
  108. package/src/types/rpc/productInformation.ts +59 -0
  109. package/src/types/rpc/sso.ts +80 -0
  110. package/src/types/rpc/walletStatus.ts +35 -0
  111. package/src/types/rpc.ts +158 -0
  112. package/src/types/transport.ts +34 -0
  113. package/src/utils/FrakContext.test.ts +407 -0
  114. package/src/utils/FrakContext.ts +158 -0
  115. package/src/utils/compression/b64.test.ts +181 -0
  116. package/src/utils/compression/b64.ts +29 -0
  117. package/src/utils/compression/compress.test.ts +123 -0
  118. package/src/utils/compression/compress.ts +11 -0
  119. package/src/utils/compression/decompress.test.ts +145 -0
  120. package/src/utils/compression/decompress.ts +11 -0
  121. package/src/utils/compression/index.ts +3 -0
  122. package/src/utils/computeProductId.test.ts +80 -0
  123. package/src/utils/computeProductId.ts +11 -0
  124. package/src/utils/constants.test.ts +23 -0
  125. package/src/utils/constants.ts +4 -0
  126. package/src/utils/formatAmount.test.ts +113 -0
  127. package/src/utils/formatAmount.ts +18 -0
  128. package/src/utils/getCurrencyAmountKey.test.ts +44 -0
  129. package/src/utils/getCurrencyAmountKey.ts +15 -0
  130. package/src/utils/getSupportedCurrency.test.ts +51 -0
  131. package/src/utils/getSupportedCurrency.ts +14 -0
  132. package/src/utils/getSupportedLocale.test.ts +64 -0
  133. package/src/utils/getSupportedLocale.ts +16 -0
  134. package/src/utils/iframeHelper.test.ts +450 -0
  135. package/src/utils/iframeHelper.ts +143 -0
  136. package/src/utils/index.ts +21 -0
  137. package/src/utils/sso.test.ts +361 -0
  138. package/src/utils/sso.ts +119 -0
  139. package/src/utils/ssoUrlListener.ts +60 -0
  140. package/src/utils/trackEvent.test.ts +162 -0
  141. package/src/utils/trackEvent.ts +26 -0
  142. package/cdn/bundle.js +0 -19
  143. package/cdn/bundle.js.LICENSE.txt +0 -10
@@ -1,1481 +1,3 @@
1
- import type { Address } from 'viem';
2
- import { Hex } from 'viem';
3
- import type { LifecycleMessage } from '@frak-labs/frame-connector';
4
- import type { OpenPanel } from '@openpanel/web';
5
- import type { RpcClient } from '@frak-labs/frame-connector';
6
- import type { SiweMessage } from 'viem/siwe';
7
-
8
- /**
9
- * All the currencies available
10
- * @category Config
11
- */
12
- declare type Currency = "eur" | "usd" | "gbp";
13
-
14
- /**
15
- * Function used to display the Frak embedded wallet popup
16
- * @param client - The current Frak Client
17
- * @param params - The parameter used to customise the embedded wallet
18
- */
19
- export declare function displayEmbeddedWallet(client: FrakClient, params: DisplayEmbeddedWalletParamsType): Promise<DisplayEmbeddedWalletResultType>;
20
-
21
- /**
22
- * The params used to display the embedded wallet
23
- *
24
- * @group Embedded wallet
25
- */
26
- declare type DisplayEmbeddedWalletParamsType = {
27
- /**
28
- * The embedded view to display once the user is logged in
29
- */
30
- loggedIn?: LoggedInEmbeddedView;
31
- /**
32
- * The embedded view to display once the user is logged out
33
- */
34
- loggedOut?: LoggedOutEmbeddedView;
35
- /**
36
- * Some metadata to customize the embedded view
37
- */
38
- metadata?: {
39
- /**
40
- * The logo to display on the embedded wallet
41
- * If undefined, will default to no logo displayed
42
- */
43
- logo?: string;
44
- /**
45
- * Link to the homepage of the calling website
46
- * If undefined, will default to the domain of the calling website
47
- */
48
- homepageLink?: string;
49
- /**
50
- * The target interaction behind this modal
51
- */
52
- targetInteraction?: FullInteractionTypesKey;
53
- /**
54
- * The position of the component
55
- */
56
- position?: "left" | "right";
57
- /**
58
- * Some i18n override for the displayed modal (i.e. update the displayed text only for this modal)
59
- */
60
- i18n?: I18nConfig;
61
- };
62
- };
63
-
64
- /**
65
- * The result of the display embedded wallet rpc request
66
- *
67
- * @group Embedded wallet
68
- */
69
- declare type DisplayEmbeddedWalletResultType = {
70
- wallet: Address;
71
- };
72
-
73
- /**
74
- * Function used to display a modal
75
- * @param client - The current Frak Client
76
- * @param args
77
- * @param args.steps - The different steps of the modal
78
- * @param args.metadata - The metadata for the modal (customization, etc)
79
- * @returns The result of each modal steps
80
- *
81
- * @description This function will display a modal to the user with the provided steps and metadata.
82
- *
83
- * @remarks
84
- * - The UI of the displayed modal can be configured with the `customCss` property in the `customizations.css` field of the top-level config.
85
- * - The `login` and `openSession` steps will be automatically skipped if the user is already logged in or has an active session. It's safe to include these steps in all cases to ensure proper user state.
86
- * - Steps are automatically reordered in the following sequence:
87
- * 1. `login` (if needed)
88
- * 2. `openSession` (if needed)
89
- * 3. All other steps in the order specified
90
- * 4. `success` (if included, always last)
91
- *
92
- * @example
93
- * Simple sharing modal with steps:
94
- * 1. Login (Skipped if already logged in)
95
- * 2. Open a session (Skipped if already opened)
96
- * 3. Display a success message with sharing link option
97
- *
98
- * ```ts
99
- * const results = await displayModal(frakConfig, {
100
- * steps: {
101
- * // Simple login with no SSO, nor customization
102
- * login: { allowSso: false },
103
- * // Simple session opening, with no customization
104
- * openSession: {},
105
- * // Success message
106
- * final: {
107
- * action: { key: "reward" },
108
- * // Skip this step, it will be only displayed in the stepper within the modal
109
- * autoSkip: true,
110
- * },
111
- * },
112
- * });
113
- *
114
- * console.log("Login step - wallet", results.login.wallet);
115
- * console.log("Open session step - start + end", {
116
- * start: results.openSession.startTimestamp,
117
- * end: results.openSession.endTimestamp,
118
- * });
119
- * ```
120
- *
121
- * @example
122
- * A full modal example, with a few customization options, with the steps:
123
- * 1. Login (Skipped if already logged in)
124
- * 2. Open a session (Skipped if already opened)
125
- * 3. Authenticate via SIWE
126
- * 4. Send a transaction
127
- * 5. Display a success message with sharing link options
128
- *
129
- * ```ts
130
- * const results = await displayModal(frakConfig, {
131
- * steps: {
132
- * // Login step
133
- * login: {
134
- * allowSso: true,
135
- * ssoMetadata: {
136
- * logoUrl: "https://my-app.com/logo.png",
137
- * homepageLink: "https://my-app.com",
138
- * },
139
- * },
140
- * // Simple session opening, with no customisation
141
- * openSession: {},
142
- * // Siwe authentication
143
- * siweAuthenticate: {
144
- * siwe: {
145
- * domain: "my-app.com",
146
- * uri: "https://my-app.com/",
147
- * nonce: generateSiweNonce(),
148
- * version: "1",
149
- * },
150
- * },
151
- * // Send batched transaction
152
- * sendTransaction: {
153
- * tx: [
154
- * { to: "0xdeadbeef", data: "0xdeadbeef" },
155
- * { to: "0xdeadbeef", data: "0xdeadbeef" },
156
- * ],
157
- * },
158
- * // Success message with sharing options
159
- * final: {
160
- * action: {
161
- * key: "sharing",
162
- * options: {
163
- * popupTitle: "Share the app",
164
- * text: "Discover my super app website",
165
- * link: "https://my-app.com",
166
- * },
167
- * },
168
- * dismissedMetadata: {
169
- * title: "Dismiss",
170
- * description: "You won't be rewarded for this sharing action",
171
- * },
172
- * },
173
- * },
174
- * metadata: {
175
- * // Header of desktop modals
176
- * header: {
177
- * title: "My-App",
178
- * icon: "https://my-app.com/logo.png",
179
- * },
180
- * // Context that will be present in every modal steps
181
- * context: "My-app overkill flow",
182
- * },
183
- * });
184
- * ```
185
- */
186
- export declare function displayModal<T extends ModalStepTypes[] = ModalStepTypes[]>(client: FrakClient, { steps, metadata }: DisplayModalParamsType<T>): Promise<ModalRpcStepsResultType<T>>;
187
-
188
- /**
189
- * Params used to display a modal
190
- * @typeParam T - The list of modal steps we expect to have in the modal
191
- * @group Modal Display
192
- */
193
- declare type DisplayModalParamsType<T extends ModalStepTypes[]> = {
194
- steps: ModalRpcStepsInput<T>;
195
- metadata?: ModalRpcMetadata;
196
- };
197
-
198
- /**
199
- * The action to display on the logged out embedded view when the user is referred
200
- *
201
- * @group Embedded wallet
202
- */
203
- declare type EmbeddedViewActionReferred = {
204
- key: "referred";
205
- /**
206
- * No options for a referred action
207
- */
208
- options?: never;
209
- };
210
-
211
- /**
212
- * The different type of action we can have on the embedded view (once the user is logged in)
213
- *
214
- * @group Embedded wallet
215
- */
216
- declare type EmbeddedViewActionSharing = {
217
- key: "sharing";
218
- /**
219
- * Some sharing options
220
- */
221
- options?: {
222
- /**
223
- * The title that will be displayed on the system popup once the system sharing window is open
224
- * @deprecated Use the top level `config.metadata.i18n` instead
225
- */
226
- popupTitle?: string;
227
- /**
228
- * The text that will be shared alongside the link.
229
- * Can contain the variable {LINK} to specify where the link is placed, otherwise it will be added at the end
230
- * @deprecated Use the top level `config.metadata.i18n` instead
231
- */
232
- text?: string;
233
- /**
234
- * The link to be shared (will be suffixed with the Frak sharing context)
235
- */
236
- link?: string;
237
- };
238
- };
239
-
240
- /**
241
- * The different types of final actions we can display in the final step
242
- * @group Modal Display
243
- */
244
- declare type FinalActionType = {
245
- key: "sharing";
246
- options?: {
247
- /**
248
- * @deprecated Use the top level `config.metadata.i18n` instead
249
- */
250
- popupTitle?: string;
251
- /**
252
- * @deprecated Use the top level `config.metadata.i18n` instead
253
- */
254
- text?: string;
255
- link?: string;
256
- };
257
- } | {
258
- key: "reward";
259
- options?: never;
260
- };
261
-
262
- /**
263
- * The final modal step type, could be used to display sharing options or a success reward screen.
264
- *
265
- * **Input**: What type final step to display?
266
- * **Output**: None
267
- *
268
- * @group Modal Display
269
- */
270
- declare type FinalModalStepType = GenericModalStepType<"final", {
271
- dismissedMetadata?: ModalStepMetadata["metadata"];
272
- action: FinalActionType;
273
- autoSkip?: boolean;
274
- }, object>;
275
-
276
- /**
277
- * Representing a Frak client, used to interact with the Frak Wallet
278
- */
279
- declare type FrakClient = {
280
- config: FrakWalletSdkConfig;
281
- debugInfo: {
282
- formatDebugInfo: (error: Error | unknown | string) => string;
283
- };
284
- openPanel?: OpenPanel;
285
- } & IFrameTransport;
286
-
287
- /**
288
- * The current Frak Context
289
- *
290
- * For now, only contain a referrer address.
291
- *
292
- * @ignore
293
- */
294
- declare type FrakContext = {
295
- r: Address;
296
- };
297
-
298
- /**
299
- * Configuration for the Frak Wallet SDK
300
- * @category Config
301
- */
302
- declare type FrakWalletSdkConfig = {
303
- /**
304
- * The Frak wallet url
305
- * @defaultValue "https://wallet.frak.id"
306
- */
307
- walletUrl?: string;
308
- /**
309
- * Some metadata about your implementation of the Frak SDK
310
- */
311
- metadata: {
312
- /**
313
- * Your application name (will be displayed in a few modals and in SSO)
314
- */
315
- name: string;
316
- /**
317
- * Language to display in the modal
318
- * If undefined, will default to the browser language
319
- */
320
- lang?: Language;
321
- /**
322
- * The currency to display in the modal
323
- * @defaultValue `"eur"`
324
- */
325
- currency?: Currency;
326
- /**
327
- * The logo URL that will be displayed in a few components
328
- */
329
- logoUrl?: string;
330
- /**
331
- * The homepage link that could be displayed in a few components
332
- */
333
- homepageLink?: string;
334
- };
335
- /**
336
- * Some customization for the modal
337
- */
338
- customizations?: {
339
- /**
340
- * Custom CSS styles to apply to the modals and components
341
- */
342
- css?: `${string}.css`;
343
- /**
344
- * Custom i18n configuration for the modal
345
- */
346
- i18n?: I18nConfig;
347
- };
348
- /**
349
- * The domain name of your application
350
- * @defaultValue window.location.host
351
- */
352
- domain?: string;
353
- };
354
-
355
- /**
356
- * The keys for each interaction types (e.g. `press.openArticle`) -> category_type.interaction_type
357
- * @inline
358
- */
359
- declare type FullInteractionTypesKey = {
360
- [Category in keyof typeof interactionTypes]: `${Category & string}.${keyof (typeof interactionTypes)[Category] & string}`;
361
- }[keyof typeof interactionTypes];
362
-
363
- /**
364
- * Represent a generic modal step type
365
- * @ignore
366
- * @inline
367
- */
368
- declare type GenericModalStepType<TKey, TParams, TReturns> = {
369
- key: TKey;
370
- params: TParams extends never ? ModalStepMetadata : ModalStepMetadata & TParams;
371
- returns: TReturns;
372
- };
373
-
374
- /**
375
- * Function used to get the current product information
376
- * @param client - The current Frak Client
377
- * @returns The product information in a promise
378
- */
379
- export declare function getProductInformation(client: FrakClient): Promise<GetProductInformationReturnType>;
380
-
381
- /**
382
- * Response of the `frak_getProductInformation` RPC method
383
- * @group RPC Schema
384
- */
385
- declare type GetProductInformationReturnType = {
386
- /**
387
- * Current product id
388
- */
389
- id: Hex;
390
- /**
391
- * Some metadata
392
- */
393
- onChainMetadata: {
394
- /**
395
- * Name of the product on-chain
396
- */
397
- name: string;
398
- /**
399
- * Domain of the product on-chain
400
- */
401
- domain: string;
402
- /**
403
- * The supported product types
404
- */
405
- productTypes: ProductTypesKey[];
406
- };
407
- /**
408
- * The max potential reward for the referrer
409
- */
410
- maxReferrer?: TokenAmountType;
411
- /**
412
- * The max potential reward for the referee
413
- */
414
- maxReferee?: TokenAmountType;
415
- /**
416
- * List of all the potentials reward arround this product
417
- */
418
- rewards: {
419
- token: Address;
420
- campaign: Address;
421
- interactionTypeKey: FullInteractionTypesKey;
422
- referrer: TokenAmountType;
423
- referee: TokenAmountType;
424
- }[];
425
- };
426
-
427
- /**
428
- * Custom i18n configuration for the modal
429
- * See [i18next json format](https://www.i18next.com/misc/json-format#i18next-json-v4)
430
- *
431
- * Available variables
432
- * - `{{ productName }}` : The name of your website (`metadata.name`)
433
- * - `{{ productOrigin }}` : The origin url of your website
434
- * - `{{ 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)
435
- *
436
- * Context of the translation [see i18n context](https://www.i18next.com/translation-function/context)
437
- * - For modal display, the key of the final action (`sharing`, `reward`, or undefined)
438
- * - For embedded wallet display, the key of the logged in action (`sharing` or undefined)
439
- *
440
- * @example
441
- * ```ts
442
- * // Multi language config
443
- * const multiI18n = {
444
- * fr: {
445
- * "sdk.modal.title": "Titre de modal",
446
- * "sdk.modal.description": "Description de modal, avec {{ estimatedReward }} de gains possible",
447
- * },
448
- * en: "https://example.com/en.json"
449
- * }
450
- *
451
- * // Single language config
452
- * const singleI18n = {
453
- * "sdk.modal.title": "Modal title",
454
- * "sdk.modal.description": "Modal description, with {{ estimatedReward }} of gains possible",
455
- * }
456
- * ```
457
- *
458
- * @category Config
459
- */
460
- declare type I18nConfig = Record<Language, LocalizedI18nConfig> | LocalizedI18nConfig;
461
-
462
- /**
463
- * RPC interface that's used for the iframe communication
464
- *
465
- * Define all the methods available within the iFrame RPC client with response type annotations
466
- *
467
- * @group RPC Schema
468
- *
469
- * @remarks
470
- * Each method in the schema now includes a ResponseType field that indicates:
471
- * - "promise": One-shot request that resolves once
472
- * - "stream": Streaming request that can emit multiple values
473
- *
474
- * ### Methods:
475
- *
476
- * #### frak_listenToWalletStatus
477
- * - Params: None
478
- * - Returns: {@link WalletStatusReturnType}
479
- * - Response Type: stream (emits updates when wallet status changes)
480
- *
481
- * #### frak_displayModal
482
- * - Params: [requests: {@link ModalRpcStepsInput}, metadata?: {@link ModalRpcMetadata}, configMetadata: {@link FrakWalletSdkConfig}["metadata"]]
483
- * - Returns: {@link ModalRpcStepsResultType}
484
- * - Response Type: promise (one-shot)
485
- *
486
- * #### frak_sendInteraction
487
- * - Params: [productId: Hex, interaction: {@link PreparedInteraction}, signature?: Hex]
488
- * - Returns: {@link SendInteractionReturnType}
489
- * - Response Type: promise (one-shot)
490
- *
491
- * #### frak_sso
492
- * - Params: [params: {@link OpenSsoParamsType}, name: string, customCss?: string]
493
- * - Returns: {@link OpenSsoReturnType}
494
- * - Response Type: promise (one-shot)
495
- *
496
- * #### frak_getProductInformation
497
- * - Params: None
498
- * - Returns: {@link GetProductInformationReturnType}
499
- * - Response Type: promise (one-shot)
500
- *
501
- * #### frak_displayEmbeddedWallet
502
- * - Params: [request: {@link DisplayEmbeddedWalletParamsType}, metadata: {@link FrakWalletSdkConfig}["metadata"]]
503
- * - Returns: {@link DisplayEmbeddedWalletResultType}
504
- * - Response Type: promise (one-shot)
505
- */
506
- declare type IFrameRpcSchema = [
507
- /**
508
- * Method used to listen to the wallet status
509
- * This is a streaming method that emits updates when wallet status changes
510
- */
511
- {
512
- Method: "frak_listenToWalletStatus";
513
- Parameters?: undefined;
514
- ReturnType: WalletStatusReturnType;
515
- },
516
- /**
517
- * Method to display a modal with the provided steps
518
- * This is a one-shot request
519
- */
520
- {
521
- Method: "frak_displayModal";
522
- Parameters: [
523
- requests: ModalRpcStepsInput,
524
- metadata: ModalRpcMetadata | undefined,
525
- configMetadata: FrakWalletSdkConfig["metadata"]
526
- ];
527
- ReturnType: ModalRpcStepsResultType;
528
- },
529
- /**
530
- * Method to transmit a user interaction
531
- * This is a one-shot request
532
- */
533
- {
534
- Method: "frak_sendInteraction";
535
- Parameters: [
536
- productId: Hex,
537
- interaction: PreparedInteraction,
538
- signature?: Hex
539
- ];
540
- ReturnType: SendInteractionReturnType;
541
- },
542
- /**
543
- * Method to prepare SSO (generate URL for popup)
544
- * Returns the SSO URL that should be opened in a popup
545
- * Only used for popup flows (not redirect flows)
546
- */
547
- {
548
- Method: "frak_prepareSso";
549
- Parameters: [
550
- params: PrepareSsoParamsType,
551
- name: string,
552
- customCss?: string
553
- ];
554
- ReturnType: PrepareSsoReturnType;
555
- },
556
- /**
557
- * Method to open/trigger SSO
558
- * Either triggers redirect (if openInSameWindow/redirectUrl)
559
- * Or waits for popup completion (if popup mode)
560
- * This method handles BOTH redirect and popup flows
561
- */
562
- {
563
- Method: "frak_openSso";
564
- Parameters: [
565
- params: OpenSsoParamsType,
566
- name: string,
567
- customCss?: string
568
- ];
569
- ReturnType: OpenSsoReturnType;
570
- },
571
- /**
572
- * Method to get current product information's
573
- * - Is product minted?
574
- * - Does it have running campaign?
575
- * - Estimated reward on actions
576
- * This is a one-shot request
577
- */
578
- {
579
- Method: "frak_getProductInformation";
580
- Parameters?: undefined;
581
- ReturnType: GetProductInformationReturnType;
582
- },
583
- /**
584
- * Method to show the embedded wallet, with potential customization
585
- * This is a one-shot request
586
- */
587
- {
588
- Method: "frak_displayEmbeddedWallet";
589
- Parameters: [
590
- request: DisplayEmbeddedWalletParamsType,
591
- metadata: FrakWalletSdkConfig["metadata"]
592
- ];
593
- ReturnType: DisplayEmbeddedWalletResultType;
594
- }
595
- ];
596
-
597
- /**
598
- * IFrame transport interface
599
- */
600
- declare type IFrameTransport = {
601
- /**
602
- * Wait for the connection to be established
603
- */
604
- waitForConnection: Promise<boolean>;
605
- /**
606
- * Wait for the setup to be done
607
- */
608
- waitForSetup: Promise<void>;
609
- /**
610
- * Function used to perform a single request via the iframe transport
611
- */
612
- request: RpcClient<IFrameRpcSchema, LifecycleMessage>["request"];
613
- /**
614
- * Function used to listen to a request response via the iframe transport
615
- */
616
- listenerRequest: RpcClient<IFrameRpcSchema, LifecycleMessage>["listen"];
617
- /**
618
- * Function used to destroy the iframe transport
619
- */
620
- destroy: () => Promise<void>;
621
- };
622
-
623
- /**
624
- * Each interactions types according to the product types
625
- */
626
- declare const interactionTypes: {
627
- readonly press: {
628
- readonly openArticle: "0xc0a24ffb";
629
- readonly readArticle: "0xd5bd0fbe";
630
- };
631
- readonly dapp: {
632
- readonly proofVerifiableStorageUpdate: "0x2ab2aeef";
633
- readonly callableVerifiableStorageUpdate: "0xa07da986";
634
- };
635
- readonly webshop: {
636
- readonly open: "0xb311798f";
637
- };
638
- readonly referral: {
639
- readonly referred: "0x010cc3b9";
640
- readonly createLink: "0xb2c0f17c";
641
- };
642
- readonly purchase: {
643
- readonly started: "0xd87e90c3";
644
- readonly completed: "0x8403aeb4";
645
- readonly unsafeCompleted: "0x4d5b14e0";
646
- };
647
- readonly retail: {
648
- readonly customerMeeting: "0x74489004";
649
- };
650
- };
651
-
652
- /**
653
- * All the languages available
654
- * @category Config
655
- */
656
- declare type Language = "fr" | "en";
657
-
658
- /**
659
- * A localized i18n config
660
- * @category Config
661
- */
662
- declare type LocalizedI18nConfig = `${string}.css` | {
663
- [key: string]: string;
664
- };
665
-
666
- /**
667
- * Some configuration options for the embedded view
668
- *
669
- * @group Embedded wallet
670
- */
671
- declare type LoggedInEmbeddedView = {
672
- /**
673
- * The main action to display on the logged in embedded view
674
- */
675
- action?: EmbeddedViewActionSharing | EmbeddedViewActionReferred;
676
- };
677
-
678
- /**
679
- * The view when a user is logged out
680
- * @group Embedded wallet
681
- */
682
- declare type LoggedOutEmbeddedView = {
683
- /**
684
- * Metadata option when displaying the embedded view
685
- */
686
- metadata?: {
687
- /**
688
- * The main CTA for the logged out view
689
- * - can include some variable, available ones are:
690
- * - {REWARD} -> The maximum reward a user can receive when interacting on your website
691
- * - can be formatted in markdown
692
- *
693
- * If not set, it will default to a internationalized message
694
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
695
- */
696
- text?: string;
697
- /**
698
- * The text that will be displayed on the login button
699
- *
700
- * If not set, it will default to a internationalized message
701
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
702
- */
703
- buttonText?: string;
704
- };
705
- };
706
-
707
- /**
708
- * The login step for a Modal
709
- *
710
- * **Input**: Do we allow SSO or not? Is yes then the SSO metadata
711
- * **Output**: The logged in wallet address
712
- *
713
- * @group Modal Display
714
- */
715
- declare type LoginModalStepType = GenericModalStepType<"login", LoginWithSso | LoginWithoutSso, {
716
- wallet: Address;
717
- }>;
718
-
719
- /** @inline */
720
- declare type LoginWithoutSso = {
721
- allowSso?: false;
722
- ssoMetadata?: never;
723
- };
724
-
725
- /** @inline */
726
- declare type LoginWithSso = {
727
- allowSso: true;
728
- ssoMetadata?: SsoMetadata;
729
- };
730
-
731
- /**
732
- * Represent the output type of the modal builder
733
- */
734
- export declare type ModalBuilder = ModalStepBuilder<[
735
- LoginModalStepType,
736
- OpenInteractionSessionModalStepType
737
- ]>;
738
-
739
- /**
740
- * Helper to craft Frak modal, and share a base initial config
741
- * @param client - The current Frak Client
742
- * @param args
743
- * @param args.metadata - Common modal metadata (customisation, language etc)
744
- * @param args.login - Login step parameters
745
- * @param args.openSession - Open session step parameters
746
- *
747
- * @description This function will create a modal builder with the provided metadata, login and open session parameters.
748
- *
749
- * @example
750
- * Here is an example of how to use the `modalBuilder` to create and display a sharing modal:
751
- *
752
- * ```js
753
- * // Create the modal builder
754
- * const modalBuilder = window.FrakSDK.modalBuilder(frakClient, baseModalConfig);
755
- *
756
- * // Configure the information to be shared via the sharing link
757
- * const sharingConfig = {
758
- * popupTitle: "Share this with your friends",
759
- * text: "Discover our product!",
760
- * link: window.location.href,
761
- * };
762
- *
763
- * // Display the sharing modal
764
- * function modalShare() {
765
- * modalBuilder.sharing(sharingConfig).display();
766
- * }
767
- * ```
768
- *
769
- * @see {@link ModalStepTypes} for more info about each modal step types and their parameters
770
- * @see {@link ModalRpcMetadata} for more info about the metadata that can be passed to the modal
771
- * @see {@link ModalRpcStepsResultType} for more info about the result of each modal steps
772
- * @see {@link displayModal} for more info about how the modal is displayed
773
- */
774
- export declare function modalBuilder(client: FrakClient, { metadata, login, openSession, }: {
775
- metadata?: ModalRpcMetadata;
776
- login?: LoginModalStepType["params"];
777
- openSession?: OpenInteractionSessionModalStepType["params"];
778
- }): ModalBuilder;
779
-
780
- /**
781
- * RPC metadata for the modal, used on top level modal configuration
782
- * @group Modal Display
783
- * @group RPC Schema
784
- */
785
- declare type ModalRpcMetadata = {
786
- header?: {
787
- title?: string;
788
- icon?: string;
789
- };
790
- targetInteraction?: FullInteractionTypesKey;
791
- /**
792
- * Some i18n override for the displayed modal (i.e. update the displayed text only for this modal)
793
- */
794
- i18n?: I18nConfig;
795
- } & ({
796
- isDismissible: true;
797
- /**
798
- * @deprecated Use `config.customizations.i18n` or `metadata.i18n` instead
799
- */
800
- dismissActionTxt?: string;
801
- } | {
802
- isDismissible?: false;
803
- dismissActionTxt?: never;
804
- });
805
-
806
- /**
807
- * Type for the RPC input of a modal
808
- * Just the `params` type of each `ModalStepTypes`
809
- * @typeParam T - The list of modal steps we expect to have in the modal
810
- * @group Modal Display
811
- * @group RPC Schema
812
- */
813
- declare type ModalRpcStepsInput<T extends ModalStepTypes[] = ModalStepTypes[]> = {
814
- [K in T[number]["key"]]?: Extract<T[number], {
815
- key: K;
816
- }>["params"];
817
- };
818
-
819
- /**
820
- * Type for the result of a modal request
821
- * Just the `returns` type of each `ModalStepTypes`
822
- * @typeParam T - The list of modal steps we expect to have in the modal
823
- * @group Modal Display
824
- * @group RPC Schema
825
- */
826
- declare type ModalRpcStepsResultType<T extends ModalStepTypes[] = ModalStepTypes[]> = {
827
- [K in T[number]["key"]]: Extract<T[number], {
828
- key: K;
829
- }>["returns"];
830
- };
831
-
832
- /**
833
- * Represent the type of the modal step builder
834
- */
835
- export declare type ModalStepBuilder<Steps extends ModalStepTypes[] = ModalStepTypes[]> = {
836
- /**
837
- * The current modal params
838
- */
839
- params: DisplayModalParamsType<Steps>;
840
- /**
841
- * Add a send transaction step to the modal
842
- */
843
- sendTx: (options: SendTransactionModalStepType["params"]) => ModalStepBuilder<[...Steps, SendTransactionModalStepType]>;
844
- /**
845
- * Add a final step of type reward to the modal
846
- */
847
- reward: (options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
848
- /**
849
- * Add a final step of type sharing to the modal
850
- */
851
- sharing: (sharingOptions?: Extract<FinalActionType, {
852
- key: "sharing";
853
- }>["options"], options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
854
- /**
855
- * Display the modal
856
- * @param metadataOverride - Function returning optional metadata to override the current modal metadata
857
- */
858
- display: (metadataOverride?: (current?: ModalRpcMetadata) => ModalRpcMetadata | undefined) => Promise<ModalRpcStepsResultType<Steps>>;
859
- };
860
-
861
- /**
862
- * Metadata that can be used to customize a modal step
863
- * @group Modal Display
864
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
865
- */
866
- declare type ModalStepMetadata = {
867
- metadata?: {
868
- /**
869
- * Custom title for the step
870
- * If none provided, it will use an internationalized text
871
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
872
- */
873
- title?: string;
874
- /**
875
- * Custom description for the step
876
- * If none provided, it will use an internationalized text
877
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
878
- */
879
- description?: string;
880
- /**
881
- * Custom text for the primary action of the step
882
- * If none provided, it will use an internationalized text
883
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
884
- */
885
- primaryActionText?: string;
886
- /**
887
- * Custom text for the secondary action of the step
888
- * If none provided, it will use an internationalized text
889
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
890
- */
891
- secondaryActionText?: string;
892
- };
893
- };
894
-
895
- /**
896
- * Generic type of steps we will display in the modal to the end user
897
- * @group Modal Display
898
- */
899
- declare type ModalStepTypes = LoginModalStepType | SiweAuthenticateModalStepType | SendTransactionModalStepType | OpenInteractionSessionModalStepType | FinalModalStepType;
900
-
901
- /**
902
- * The open interaction session step for a Modal
903
- *
904
- * **Input**: None
905
- * **Output**: The interactions session period (start and end timestamp)
906
- *
907
- * @group Modal Display
908
- */
909
- declare type OpenInteractionSessionModalStepType = GenericModalStepType<"openSession", object, OpenInteractionSessionReturnType>;
910
-
911
- /**
912
- * Return type of the open session modal step
913
- * @inline
914
- * @ignore
915
- */
916
- declare type OpenInteractionSessionReturnType = {
917
- startTimestamp: number;
918
- endTimestamp: number;
919
- };
920
-
921
- /**
922
- * Function used to open the SSO
923
- * @param client - The current Frak Client
924
- * @param args - The SSO parameters
925
- *
926
- * @description Two SSO flow modes:
927
- *
928
- * **Redirect Mode** (openInSameWindow: true):
929
- * - Wallet generates URL and triggers redirect
930
- * - Used when redirectUrl is provided
931
- *
932
- * **Popup Mode** (openInSameWindow: false/omitted):
933
- * - SDK generates URL client-side (or uses provided ssoPopupUrl)
934
- * - Opens popup synchronously (prevents popup blockers)
935
- * - Waits for SSO completion via postMessage
936
- *
937
- * @example
938
- * First we build the sso metadata
939
- * ```ts
940
- * // Build the metadata
941
- * const metadata: SsoMetadata = {
942
- * logoUrl: "https://my-app.com/logo.png",
943
- * homepageLink: "https://my-app.com",
944
- * };
945
- * ```
946
- *
947
- * Then, either use it with direct exit (and so user is directly redirected to your website), or a custom redirect URL
948
- * :::code-group
949
- * ```ts [Popup (default)]
950
- * // Opens in popup, SDK generates URL automatically
951
- * await openSso(frakConfig, {
952
- * directExit: true,
953
- * metadata,
954
- * });
955
- * ```
956
- * ```ts [Redirect]
957
- * // Opens in same window with redirect
958
- * await openSso(frakConfig, {
959
- * redirectUrl: "https://my-app.com/frak-sso",
960
- * metadata,
961
- * openInSameWindow: true,
962
- * });
963
- * ```
964
- * ```ts [Custom popup URL]
965
- * // Advanced: provide custom SSO URL
966
- * const { ssoUrl } = await prepareSso(frakConfig, { metadata });
967
- * await openSso(frakConfig, {
968
- * metadata,
969
- * ssoPopupUrl: `${ssoUrl}&custom=param`,
970
- * });
971
- * ```
972
- * :::
973
- */
974
- export declare function openSso(client: FrakClient, args: OpenSsoParamsType): Promise<OpenSsoReturnType>;
975
-
976
- /**
977
- * Params to start a SSO
978
- * @group RPC Schema
979
- */
980
- declare type OpenSsoParamsType = PrepareSsoParamsType & {
981
- /**
982
- * 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
983
- * Note: Default true if redirectUrl is present, otherwise, false
984
- */
985
- openInSameWindow?: boolean;
986
- /**
987
- * Custom SSO popup url if user want additionnal customisation
988
- */
989
- ssoPopupUrl?: string;
990
- };
991
-
992
- /**
993
- * Response after an SSO has been openned
994
- */
995
- declare type OpenSsoReturnType = {
996
- /**
997
- * Optional wallet address, returned when SSO completes via postMessage
998
- * Note: Only present when SSO flow completes (not immediately on open)
999
- */
1000
- wallet?: Hex;
1001
- };
1002
-
1003
- /**
1004
- * Represent a prepared user interaction, ready to be sent on-chain via the wallet
1005
- */
1006
- declare type PreparedInteraction = {
1007
- handlerTypeDenominator: Hex;
1008
- interactionData: Hex;
1009
- };
1010
-
1011
- /**
1012
- * Generate SSO URL without opening popup
1013
- *
1014
- * This is a **synchronous**, client-side function that generates the SSO URL
1015
- * without any RPC calls to the wallet iframe. Use this when you need:
1016
- * - Custom URL modifications before opening popup
1017
- * - Pre-generation for advanced popup strategies
1018
- * - URL inspection/logging before SSO flow
1019
- *
1020
- * @param client - The current Frak Client
1021
- * @param args - The SSO parameters
1022
- * @returns Object containing the generated ssoUrl
1023
- *
1024
- * @example
1025
- * ```ts
1026
- * // Generate URL for inspection
1027
- * const { ssoUrl } = prepareSso(client, {
1028
- * metadata: { logoUrl: "..." },
1029
- * directExit: true
1030
- * });
1031
- * console.log("Opening SSO:", ssoUrl);
1032
- *
1033
- * // Add custom params
1034
- * const customUrl = `${ssoUrl}&tracking=abc123`;
1035
- * await openSso(client, { metadata, ssoPopupUrl: customUrl });
1036
- * ```
1037
- *
1038
- * @remarks
1039
- * For most use cases, just use `openSso()` which handles URL generation automatically.
1040
- * Only use `prepareSso()` when you need explicit control over the URL.
1041
- */
1042
- export declare function prepareSso(client: FrakClient, args: PrepareSsoParamsType): Promise<PrepareSsoReturnType>;
1043
-
1044
- /**
1045
- * Params for preparing SSO (generating URL)
1046
- * Same as OpenSsoParamsType but without openInSameWindow (popup-only operation)
1047
- * @group RPC Schema
1048
- */
1049
- declare type PrepareSsoParamsType = {
1050
- /**
1051
- * Redirect URL after the SSO (optional)
1052
- */
1053
- redirectUrl?: string;
1054
- /**
1055
- * If the SSO should directly exit after completion
1056
- * @defaultValue true
1057
- */
1058
- directExit?: boolean;
1059
- /**
1060
- * Language of the SSO page (optional)
1061
- * It will default to the current user language (or "en" if unsupported language)
1062
- */
1063
- lang?: "en" | "fr";
1064
- /**
1065
- * Custom SSO metadata
1066
- */
1067
- metadata?: SsoMetadata;
1068
- };
1069
-
1070
- /**
1071
- * Response after preparing SSO
1072
- * @group RPC Schema
1073
- */
1074
- declare type PrepareSsoReturnType = {
1075
- /**
1076
- * The SSO URL that should be opened in a popup
1077
- */
1078
- ssoUrl: string;
1079
- };
1080
-
1081
- /**
1082
- * This function handle all the heavy lifting of the referral interaction process
1083
- * 1. Check if the user has been referred or not (if not, early exit)
1084
- * 2. Then check if the user is logged in or not
1085
- * 2.1 If not logged in, try a soft login, if it fail, display a modal for the user to login
1086
- * 3. Check if that's not a self-referral (if yes, early exit)
1087
- * 4. Check if the user has an interaction session or not
1088
- * 4.1 If not, display a modal for the user to open a session
1089
- * 5. Push the referred interaction
1090
- * 6. Update the current url with the right data
1091
- * 7. Return the resulting referral state
1092
- *
1093
- * If any error occurs during the process, the function will catch it and return an error state
1094
- *
1095
- * @param client - The current Frak Client
1096
- * @param args
1097
- * @param args.walletStatus - The current user wallet status
1098
- * @param args.frakContext - The current frak context
1099
- * @param args.modalConfig - The modal configuration to display if the user is not logged in
1100
- * @param args.productId - The product id to interact with (if not specified will be recomputed from the current domain)
1101
- * @param args.options - Some options for the referral interaction
1102
- * @returns A promise with the resulting referral state
1103
- *
1104
- * @see {@link displayModal} for more details about the displayed modal
1105
- * @see {@link sendInteraction} for more details on the interaction submission part
1106
- * @see {@link ReferralInteractionEncoder} for more details about the referred interaction
1107
- * @see {@link ModalStepTypes} for more details on each modal steps types
1108
- */
1109
- export declare function processReferral(client: FrakClient, { walletStatus, frakContext, modalConfig, productId, options, }: {
1110
- walletStatus?: WalletStatusReturnType;
1111
- frakContext?: Partial<FrakContext> | null;
1112
- modalConfig?: DisplayEmbeddedWalletParamsType;
1113
- productId?: Hex;
1114
- options?: ProcessReferralOptions;
1115
- }): Promise<ReferralState>;
1116
-
1117
- /**
1118
- * Options for the referral auto-interaction process
1119
- */
1120
- export declare type ProcessReferralOptions = {
1121
- /**
1122
- * If we want to always append the url with the frak context or not
1123
- * @defaultValue false
1124
- */
1125
- alwaysAppendUrl?: boolean;
1126
- };
1127
-
1128
- /**
1129
- * List of the product types per denominator
1130
- */
1131
- declare const productTypes: {
1132
- dapp: number;
1133
- press: number;
1134
- webshop: number;
1135
- retail: number;
1136
- referral: number;
1137
- purchase: number;
1138
- };
1139
-
1140
- /**
1141
- * The keys for each product types
1142
- * @inline
1143
- */
1144
- declare type ProductTypesKey = keyof typeof productTypes;
1145
-
1146
- /**
1147
- * Function used to display a modal
1148
- * @param client - The current Frak Client
1149
- * @param args
1150
- * @param args.productId - The product id to interact with (if not specified will be recomputed from the current domain)
1151
- * @param args.modalConfig - The modal configuration to display if the user is not logged in
1152
- * @param args.options - Some options for the referral interaction
1153
- *
1154
- * @returns A promise with the resulting referral state, or undefined in case of an error
1155
- *
1156
- * @description This function will automatically handle the referral interaction process
1157
- *
1158
- * @see {@link processReferral} for more details on the automatic referral handling process
1159
- * @see {@link ModalStepTypes} for more details on each modal steps types
1160
- */
1161
- export declare function referralInteraction(client: FrakClient, { productId, modalConfig, options, }?: {
1162
- productId?: Hex;
1163
- modalConfig?: DisplayEmbeddedWalletParamsType;
1164
- options?: ProcessReferralOptions;
1165
- }): Promise<("error" | "idle" | "processing" | "success" | "no-wallet" | "no-session" | "no-referrer" | "self-referral") | undefined>;
1166
-
1167
- /**
1168
- * The different states of the referral process
1169
- * @inline
1170
- */
1171
- declare type ReferralState = "idle" | "processing" | "success" | "no-wallet" | "no-session" | "error" | "no-referrer" | "self-referral";
1172
-
1173
- /**
1174
- * Function used to send an interaction
1175
- * @param client - The current Frak Client
1176
- * @param args
1177
- *
1178
- * @example
1179
- * const interaction = PressInteractionEncoder.openArticle({
1180
- * articleId: keccak256(toHex("article-slug")),
1181
- * });
1182
- * const { delegationId } = await sendInteraction(frakConfig, {
1183
- * interaction,
1184
- * });
1185
- * console.log("Delegated interaction id", delegationId);
1186
- */
1187
- export declare function sendInteraction(client: FrakClient, { productId, interaction, validation }: SendInteractionParamsType): Promise<SendInteractionReturnType>;
1188
-
1189
- /**
1190
- * Parameters that will be used to send an interaction to the blockchain
1191
- * @inline
1192
- */
1193
- declare type SendInteractionParamsType = {
1194
- /**
1195
- * The product id where this interaction has been made
1196
- * @defaultValue keccak256(toHex(window.location.host))
1197
- */
1198
- productId?: Hex;
1199
- /**
1200
- * The prepared interaction, built from an Interaction Encoder
1201
- */
1202
- interaction: PreparedInteraction;
1203
- /**
1204
- * A pre-computed interaction signature
1205
- * If none provided, the delegated interaction validator of your product will sign it (you can manage it in the business dashboard)
1206
- *
1207
- * @defaultValue undefined
1208
- */
1209
- validation?: Hex;
1210
- };
1211
-
1212
- /**
1213
- * Return type of the send interaction rpc request
1214
- * @group RPC Schema
1215
- */
1216
- declare type SendInteractionReturnType = {
1217
- /**
1218
- * The id of the interaction in the interaction pool
1219
- */
1220
- delegationId: string;
1221
- };
1222
-
1223
- /**
1224
- * Function used to send a user transaction, simple wrapper around the displayModal function to ease the send transaction process
1225
- * @param client - The current Frak Client
1226
- * @param args - The parameters
1227
- * @returns The hash of the transaction that was sent in a promise
1228
- *
1229
- * @description This function will display a modal to the user with the provided transaction and metadata.
1230
- *
1231
- * @example
1232
- * const { hash } = await sendTransaction(frakConfig, {
1233
- * tx: {
1234
- * to: "0xdeadbeef",
1235
- * value: toHex(100n),
1236
- * },
1237
- * metadata: {
1238
- * header: {
1239
- * title: "Sending eth",
1240
- * },
1241
- * context: "Send 100wei to 0xdeadbeef",
1242
- * },
1243
- * });
1244
- * console.log("Transaction hash:", hash);
1245
- */
1246
- export declare function sendTransaction(client: FrakClient, { tx, metadata }: SendTransactionParams): Promise<SendTransactionReturnType>;
1247
-
1248
- /**
1249
- * The send transaction step for a Modal
1250
- *
1251
- * **Input**: Either a single tx or an array of tx to be sent
1252
- * **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)
1253
- *
1254
- * @group Modal Display
1255
- */
1256
- declare type SendTransactionModalStepType = GenericModalStepType<"sendTransaction", {
1257
- tx: SendTransactionTxType | SendTransactionTxType[];
1258
- }, SendTransactionReturnType>;
1259
-
1260
- /**
1261
- * Parameters to directly show a modal used to send a transaction
1262
- * @inline
1263
- */
1264
- export declare type SendTransactionParams = {
1265
- /**
1266
- * The transaction to be sent (either a single tx or multiple ones)
1267
- */
1268
- tx: SendTransactionModalStepType["params"]["tx"];
1269
- /**
1270
- * Custom metadata to be passed to the modal
1271
- */
1272
- metadata?: ModalRpcMetadata;
1273
- };
1274
-
1275
- /**
1276
- * Return type of the send transaction rpc request
1277
- * @inline
1278
- */
1279
- declare type SendTransactionReturnType = {
1280
- hash: Hex;
1281
- };
1282
-
1283
- /**
1284
- * Generic format representing a tx to be sent
1285
- */
1286
- declare type SendTransactionTxType = {
1287
- to: Address;
1288
- data?: Hex;
1289
- value?: Hex;
1290
- };
1291
-
1292
- /**
1293
- * Function used to launch a siwe authentication
1294
- * @param client - The current Frak Client
1295
- * @param args - The parameters
1296
- * @returns The SIWE authentication result (message + signature) in a promise
1297
- *
1298
- * @description This function will display a modal to the user with the provided SIWE parameters and metadata.
1299
- *
1300
- * @example
1301
- * import { siweAuthenticate } from "@frak-labs/core-sdk/actions";
1302
- * import { parseSiweMessage } from "viem/siwe";
1303
- *
1304
- * const { signature, message } = await siweAuthenticate(frakConfig, {
1305
- * siwe: {
1306
- * statement: "Sign in to My App",
1307
- * domain: "my-app.com",
1308
- * expirationTimeTimestamp: Date.now() + 1000 * 60 * 5,
1309
- * },
1310
- * metadata: {
1311
- * header: {
1312
- * title: "Sign in",
1313
- * },
1314
- * context: "Sign in to My App",
1315
- * },
1316
- * });
1317
- * console.log("Parsed final message:", parseSiweMessage(message));
1318
- * console.log("Siwe signature:", signature);
1319
- */
1320
- export declare function siweAuthenticate(client: FrakClient, { siwe, metadata }: SiweAuthenticateModalParams): Promise<SiweAuthenticateReturnType>;
1321
-
1322
- /**
1323
- * Parameter used to directly show a modal used to authenticate with SIWE
1324
- * @inline
1325
- */
1326
- export declare type SiweAuthenticateModalParams = {
1327
- /**
1328
- * Partial SIWE params, since we can rebuild them from the SDK if they are empty
1329
- *
1330
- * If no parameters provider, some fields will be recomputed from the current configuration and environment.
1331
- * - `statement` will be set to a default value
1332
- * - `nonce` will be generated
1333
- * - `uri` will be set to the current domain
1334
- * - `version` will be set to "1"
1335
- * - `domain` will be set to the current window domain
1336
- *
1337
- * @default {}
1338
- */
1339
- siwe?: Partial<SiweAuthenticationParams>;
1340
- /**
1341
- * Custom metadata to be passed to the modal
1342
- */
1343
- metadata?: ModalRpcMetadata;
1344
- };
1345
-
1346
- /**
1347
- * The SIWE authentication step for a Modal
1348
- *
1349
- * **Input**: SIWE message parameters
1350
- * **Output**: SIWE result (message signed and wallet signature)
1351
- *
1352
- * @group Modal Display
1353
- */
1354
- declare type SiweAuthenticateModalStepType = GenericModalStepType<"siweAuthenticate", {
1355
- siwe: SiweAuthenticationParams;
1356
- }, SiweAuthenticateReturnType>;
1357
-
1358
- /**
1359
- * Return type of the Siwe transaction rpc request
1360
- * @inline
1361
- */
1362
- declare type SiweAuthenticateReturnType = {
1363
- signature: Hex;
1364
- message: string;
1365
- };
1366
-
1367
- /**
1368
- * Parameters used send a SIWE rpc request
1369
- */
1370
- declare type SiweAuthenticationParams = Omit<SiweMessage, "address" | "chainId" | "expirationTime" | "issuedAt" | "notBefore"> & {
1371
- expirationTimeTimestamp?: number;
1372
- notBeforeTimestamp?: number;
1373
- };
1374
-
1375
- /**
1376
- * SSO Metadata
1377
- */
1378
- declare type SsoMetadata = {
1379
- /**
1380
- * URL to your client, if provided will be displayed in the SSO header
1381
- */
1382
- logoUrl?: string;
1383
- /**
1384
- * Link to your homepage, if referenced your app name will contain a link on the sso page
1385
- */
1386
- homepageLink?: string;
1387
- };
1388
-
1389
- /**
1390
- * The type for the amount of tokens
1391
- */
1392
- declare type TokenAmountType = {
1393
- amount: number;
1394
- eurAmount: number;
1395
- usdAmount: number;
1396
- gbpAmount: number;
1397
- };
1398
-
1399
- /**
1400
- * Function used to track the status of a purchase
1401
- * when a purchase is tracked, the `purchaseCompleted` interactions will be automatically send for the user when we receive the purchase confirmation via webhook.
1402
- *
1403
- * @param args.customerId - The customer id that made the purchase (on your side)
1404
- * @param args.orderId - The order id of the purchase (on your side)
1405
- * @param args.token - The token of the purchase
1406
- *
1407
- * @description This function will send a request to the backend to listen for the purchase status.
1408
- *
1409
- * @example
1410
- * async function trackPurchase(checkout) {
1411
- * const payload = {
1412
- * customerId: checkout.order.customer.id,
1413
- * orderId: checkout.order.id,
1414
- * token: checkout.token,
1415
- * };
1416
- *
1417
- * await trackPurchaseStatus(payload);
1418
- * }
1419
- *
1420
- * @remarks
1421
- * - The `trackPurchaseStatus` function requires the `frak-wallet-interaction-token` stored in the session storage to authenticate the request.
1422
- * - This function will print a warning if used in a non-browser environment or if the wallet interaction token is not available.
1423
- */
1424
- export declare function trackPurchaseStatus(args: {
1425
- customerId: string | number;
1426
- orderId: string | number;
1427
- token: string;
1428
- }): Promise<void>;
1429
-
1430
- /**
1431
- * @ignore
1432
- * @inline
1433
- */
1434
- declare type WalletConnected = {
1435
- key: "connected";
1436
- wallet: Address;
1437
- interactionToken?: string;
1438
- interactionSession?: {
1439
- startTimestamp: number;
1440
- endTimestamp: number;
1441
- };
1442
- };
1443
-
1444
- /**
1445
- * @ignore
1446
- * @inline
1447
- */
1448
- declare type WalletNotConnected = {
1449
- key: "not-connected";
1450
- wallet?: never;
1451
- interactionToken?: never;
1452
- interactionSession?: never;
1453
- };
1454
-
1455
- /**
1456
- * RPC Response for the method `frak_listenToWalletStatus`
1457
- * @group RPC Schema
1458
- */
1459
- declare type WalletStatusReturnType = WalletConnected | WalletNotConnected;
1460
-
1461
- /**
1462
- * Function used to watch the current frak wallet status
1463
- * @param client - The current Frak Client
1464
- * @param callback - The callback that will receive any wallet status change
1465
- * @returns A promise resolving with the initial wallet status
1466
- *
1467
- * @description This function will return the current wallet status, and will listen to any change in the wallet status.
1468
- *
1469
- * @example
1470
- * await watchWalletStatus(frakConfig, (status: WalletStatusReturnType) => {
1471
- * if (status.key === "connected") {
1472
- * console.log("Wallet connected:", status.wallet);
1473
- * console.log("Current interaction session:", status.interactionSession);
1474
- * } else {
1475
- * console.log("Wallet not connected");
1476
- * }
1477
- * });
1478
- */
1479
- export declare function watchWalletStatus(client: FrakClient, callback?: (status: WalletStatusReturnType) => void): Promise<WalletStatusReturnType>;
1480
-
1481
- export { }
1
+ import { t as openSso } from "./openSso-D--Airj6.cjs";
2
+ import { _ as displayEmbeddedWallet, a as ModalBuilder, c as watchWalletStatus, d as referralInteraction, f as ProcessReferralOptions, g as displayModal, h as getProductInformation, i as sendTransaction, l as trackPurchaseStatus, m as prepareSso, n as siweAuthenticate, o as ModalStepBuilder, p as processReferral, r as SendTransactionParams, s as modalBuilder, t as SiweAuthenticateModalParams, u as sendInteraction } from "./index-C6FxkWPC.cjs";
3
+ export { ModalBuilder, ModalStepBuilder, ProcessReferralOptions, SendTransactionParams, SiweAuthenticateModalParams, displayEmbeddedWallet, displayModal, getProductInformation, modalBuilder, openSso, prepareSso, processReferral, referralInteraction, sendInteraction, sendTransaction, siweAuthenticate, trackPurchaseStatus, watchWalletStatus };