@frak-labs/core-sdk 0.0.19-beta.f259d7fc → 0.1.0-beta.263acd1e

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 (139) 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 -1400
  6. package/dist/actions.d.ts +3 -1400
  7. package/dist/actions.js +1 -1
  8. package/dist/bundle.cjs +1 -13
  9. package/dist/bundle.d.cts +6 -1927
  10. package/dist/bundle.d.ts +6 -1927
  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 -1269
  20. package/dist/index.d.ts +4 -1269
  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 +24 -19
  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.ts +57 -0
  52. package/src/actions/sendInteraction.test.ts +219 -0
  53. package/src/actions/sendInteraction.ts +32 -0
  54. package/src/actions/trackPurchaseStatus.test.ts +287 -0
  55. package/src/actions/trackPurchaseStatus.ts +53 -0
  56. package/src/actions/watchWalletStatus.test.ts +372 -0
  57. package/src/actions/watchWalletStatus.ts +94 -0
  58. package/src/actions/wrapper/modalBuilder.ts +212 -0
  59. package/src/actions/wrapper/sendTransaction.ts +62 -0
  60. package/src/actions/wrapper/siweAuthenticate.ts +94 -0
  61. package/src/bundle.ts +3 -0
  62. package/src/clients/DebugInfo.ts +182 -0
  63. package/src/clients/createIFrameFrakClient.ts +287 -0
  64. package/src/clients/index.ts +3 -0
  65. package/src/clients/setupClient.test.ts +343 -0
  66. package/src/clients/setupClient.ts +73 -0
  67. package/src/clients/transports/iframeLifecycleManager.test.ts +399 -0
  68. package/src/clients/transports/iframeLifecycleManager.ts +90 -0
  69. package/src/constants/interactionTypes.ts +44 -0
  70. package/src/constants/locales.ts +14 -0
  71. package/src/constants/productTypes.ts +33 -0
  72. package/src/index.ts +101 -0
  73. package/src/interactions/index.ts +5 -0
  74. package/src/interactions/pressEncoder.test.ts +215 -0
  75. package/src/interactions/pressEncoder.ts +53 -0
  76. package/src/interactions/purchaseEncoder.test.ts +291 -0
  77. package/src/interactions/purchaseEncoder.ts +99 -0
  78. package/src/interactions/referralEncoder.test.ts +170 -0
  79. package/src/interactions/referralEncoder.ts +47 -0
  80. package/src/interactions/retailEncoder.test.ts +107 -0
  81. package/src/interactions/retailEncoder.ts +37 -0
  82. package/src/interactions/webshopEncoder.test.ts +56 -0
  83. package/src/interactions/webshopEncoder.ts +30 -0
  84. package/src/types/client.ts +14 -0
  85. package/src/types/compression.ts +22 -0
  86. package/src/types/config.ts +111 -0
  87. package/src/types/context.ts +13 -0
  88. package/src/types/index.ts +71 -0
  89. package/src/types/lifecycle/client.ts +46 -0
  90. package/src/types/lifecycle/iframe.ts +35 -0
  91. package/src/types/lifecycle/index.ts +2 -0
  92. package/src/types/rpc/displayModal.ts +84 -0
  93. package/src/types/rpc/embedded/index.ts +68 -0
  94. package/src/types/rpc/embedded/loggedIn.ts +55 -0
  95. package/src/types/rpc/embedded/loggedOut.ts +28 -0
  96. package/src/types/rpc/interaction.ts +43 -0
  97. package/src/types/rpc/modal/final.ts +46 -0
  98. package/src/types/rpc/modal/generic.ts +46 -0
  99. package/src/types/rpc/modal/index.ts +20 -0
  100. package/src/types/rpc/modal/login.ts +32 -0
  101. package/src/types/rpc/modal/openSession.ts +25 -0
  102. package/src/types/rpc/modal/siweAuthenticate.ts +37 -0
  103. package/src/types/rpc/modal/transaction.ts +33 -0
  104. package/src/types/rpc/productInformation.ts +59 -0
  105. package/src/types/rpc/sso.ts +80 -0
  106. package/src/types/rpc/walletStatus.ts +35 -0
  107. package/src/types/rpc.ts +158 -0
  108. package/src/types/transport.ts +34 -0
  109. package/src/utils/FrakContext.test.ts +407 -0
  110. package/src/utils/FrakContext.ts +158 -0
  111. package/src/utils/compression/b64.test.ts +181 -0
  112. package/src/utils/compression/b64.ts +29 -0
  113. package/src/utils/compression/compress.test.ts +123 -0
  114. package/src/utils/compression/compress.ts +11 -0
  115. package/src/utils/compression/decompress.test.ts +145 -0
  116. package/src/utils/compression/decompress.ts +11 -0
  117. package/src/utils/compression/index.ts +3 -0
  118. package/src/utils/computeProductId.test.ts +80 -0
  119. package/src/utils/computeProductId.ts +11 -0
  120. package/src/utils/constants.test.ts +23 -0
  121. package/src/utils/constants.ts +4 -0
  122. package/src/utils/formatAmount.test.ts +113 -0
  123. package/src/utils/formatAmount.ts +18 -0
  124. package/src/utils/getCurrencyAmountKey.test.ts +44 -0
  125. package/src/utils/getCurrencyAmountKey.ts +15 -0
  126. package/src/utils/getSupportedCurrency.test.ts +51 -0
  127. package/src/utils/getSupportedCurrency.ts +14 -0
  128. package/src/utils/getSupportedLocale.test.ts +64 -0
  129. package/src/utils/getSupportedLocale.ts +16 -0
  130. package/src/utils/iframeHelper.test.ts +450 -0
  131. package/src/utils/iframeHelper.ts +143 -0
  132. package/src/utils/index.ts +21 -0
  133. package/src/utils/sso.test.ts +361 -0
  134. package/src/utils/sso.ts +119 -0
  135. package/src/utils/ssoUrlListener.ts +60 -0
  136. package/src/utils/trackEvent.test.ts +162 -0
  137. package/src/utils/trackEvent.ts +26 -0
  138. package/cdn/bundle.js +0 -19
  139. package/cdn/bundle.js.LICENSE.txt +0 -10
@@ -1,1400 +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 start a SSO
544
- * This is a one-shot request
545
- */
546
- {
547
- Method: "frak_sso";
548
- Parameters: [
549
- params: OpenSsoParamsType,
550
- name: string,
551
- customCss?: string
552
- ];
553
- ReturnType: OpenSsoReturnType;
554
- },
555
- /**
556
- * Method to get current product information's
557
- * - Is product minted?
558
- * - Does it have running campaign?
559
- * - Estimated reward on actions
560
- * This is a one-shot request
561
- */
562
- {
563
- Method: "frak_getProductInformation";
564
- Parameters?: undefined;
565
- ReturnType: GetProductInformationReturnType;
566
- },
567
- /**
568
- * Method to show the embedded wallet, with potential customization
569
- * This is a one-shot request
570
- */
571
- {
572
- Method: "frak_displayEmbeddedWallet";
573
- Parameters: [
574
- request: DisplayEmbeddedWalletParamsType,
575
- metadata: FrakWalletSdkConfig["metadata"]
576
- ];
577
- ReturnType: DisplayEmbeddedWalletResultType;
578
- }
579
- ];
580
-
581
- /**
582
- * IFrame transport interface
583
- */
584
- declare type IFrameTransport = {
585
- /**
586
- * Wait for the connection to be established
587
- */
588
- waitForConnection: Promise<boolean>;
589
- /**
590
- * Wait for the setup to be done
591
- */
592
- waitForSetup: Promise<void>;
593
- /**
594
- * Function used to perform a single request via the iframe transport
595
- */
596
- request: RpcClient<IFrameRpcSchema, LifecycleMessage>["request"];
597
- /**
598
- * Function used to listen to a request response via the iframe transport
599
- */
600
- listenerRequest: RpcClient<IFrameRpcSchema, LifecycleMessage>["listen"];
601
- /**
602
- * Function used to destroy the iframe transport
603
- */
604
- destroy: () => Promise<void>;
605
- };
606
-
607
- /**
608
- * Each interactions types according to the product types
609
- */
610
- declare const interactionTypes: {
611
- readonly press: {
612
- readonly openArticle: "0xc0a24ffb";
613
- readonly readArticle: "0xd5bd0fbe";
614
- };
615
- readonly dapp: {
616
- readonly proofVerifiableStorageUpdate: "0x2ab2aeef";
617
- readonly callableVerifiableStorageUpdate: "0xa07da986";
618
- };
619
- readonly webshop: {
620
- readonly open: "0xb311798f";
621
- };
622
- readonly referral: {
623
- readonly referred: "0x010cc3b9";
624
- readonly createLink: "0xb2c0f17c";
625
- };
626
- readonly purchase: {
627
- readonly started: "0xd87e90c3";
628
- readonly completed: "0x8403aeb4";
629
- readonly unsafeCompleted: "0x4d5b14e0";
630
- };
631
- readonly retail: {
632
- readonly customerMeeting: "0x74489004";
633
- };
634
- };
635
-
636
- /**
637
- * All the languages available
638
- * @category Config
639
- */
640
- declare type Language = "fr" | "en";
641
-
642
- /**
643
- * A localized i18n config
644
- * @category Config
645
- */
646
- declare type LocalizedI18nConfig = `${string}.css` | {
647
- [key: string]: string;
648
- };
649
-
650
- /**
651
- * Some configuration options for the embedded view
652
- *
653
- * @group Embedded wallet
654
- */
655
- declare type LoggedInEmbeddedView = {
656
- /**
657
- * The main action to display on the logged in embedded view
658
- */
659
- action?: EmbeddedViewActionSharing | EmbeddedViewActionReferred;
660
- };
661
-
662
- /**
663
- * The view when a user is logged out
664
- * @group Embedded wallet
665
- */
666
- declare type LoggedOutEmbeddedView = {
667
- /**
668
- * Metadata option when displaying the embedded view
669
- */
670
- metadata?: {
671
- /**
672
- * The main CTA for the logged out view
673
- * - can include some variable, available ones are:
674
- * - {REWARD} -> The maximum reward a user can receive when interacting on your website
675
- * - can be formatted in markdown
676
- *
677
- * If not set, it will default to a internationalized message
678
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
679
- */
680
- text?: string;
681
- /**
682
- * The text that will be displayed on the login button
683
- *
684
- * If not set, it will default to a internationalized message
685
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
686
- */
687
- buttonText?: string;
688
- };
689
- };
690
-
691
- /**
692
- * The login step for a Modal
693
- *
694
- * **Input**: Do we allow SSO or not? Is yes then the SSO metadata
695
- * **Output**: The logged in wallet address
696
- *
697
- * @group Modal Display
698
- */
699
- declare type LoginModalStepType = GenericModalStepType<"login", LoginWithSso | LoginWithoutSso, {
700
- wallet: Address;
701
- }>;
702
-
703
- /** @inline */
704
- declare type LoginWithoutSso = {
705
- allowSso?: false;
706
- ssoMetadata?: never;
707
- };
708
-
709
- /** @inline */
710
- declare type LoginWithSso = {
711
- allowSso: true;
712
- ssoMetadata?: SsoMetadata;
713
- };
714
-
715
- /**
716
- * Represent the output type of the modal builder
717
- */
718
- export declare type ModalBuilder = ModalStepBuilder<[
719
- LoginModalStepType,
720
- OpenInteractionSessionModalStepType
721
- ]>;
722
-
723
- /**
724
- * Helper to craft Frak modal, and share a base initial config
725
- * @param client - The current Frak Client
726
- * @param args
727
- * @param args.metadata - Common modal metadata (customisation, language etc)
728
- * @param args.login - Login step parameters
729
- * @param args.openSession - Open session step parameters
730
- *
731
- * @description This function will create a modal builder with the provided metadata, login and open session parameters.
732
- *
733
- * @example
734
- * Here is an example of how to use the `modalBuilder` to create and display a sharing modal:
735
- *
736
- * ```js
737
- * // Create the modal builder
738
- * const modalBuilder = window.FrakSDK.modalBuilder(frakClient, baseModalConfig);
739
- *
740
- * // Configure the information to be shared via the sharing link
741
- * const sharingConfig = {
742
- * popupTitle: "Share this with your friends",
743
- * text: "Discover our product!",
744
- * link: window.location.href,
745
- * };
746
- *
747
- * // Display the sharing modal
748
- * function modalShare() {
749
- * modalBuilder.sharing(sharingConfig).display();
750
- * }
751
- * ```
752
- *
753
- * @see {@link ModalStepTypes} for more info about each modal step types and their parameters
754
- * @see {@link ModalRpcMetadata} for more info about the metadata that can be passed to the modal
755
- * @see {@link ModalRpcStepsResultType} for more info about the result of each modal steps
756
- * @see {@link displayModal} for more info about how the modal is displayed
757
- */
758
- export declare function modalBuilder(client: FrakClient, { metadata, login, openSession, }: {
759
- metadata?: ModalRpcMetadata;
760
- login?: LoginModalStepType["params"];
761
- openSession?: OpenInteractionSessionModalStepType["params"];
762
- }): ModalBuilder;
763
-
764
- /**
765
- * RPC metadata for the modal, used on top level modal configuration
766
- * @group Modal Display
767
- * @group RPC Schema
768
- */
769
- declare type ModalRpcMetadata = {
770
- header?: {
771
- title?: string;
772
- icon?: string;
773
- };
774
- targetInteraction?: FullInteractionTypesKey;
775
- /**
776
- * Some i18n override for the displayed modal (i.e. update the displayed text only for this modal)
777
- */
778
- i18n?: I18nConfig;
779
- } & ({
780
- isDismissible: true;
781
- /**
782
- * @deprecated Use `config.customizations.i18n` or `metadata.i18n` instead
783
- */
784
- dismissActionTxt?: string;
785
- } | {
786
- isDismissible?: false;
787
- dismissActionTxt?: never;
788
- });
789
-
790
- /**
791
- * Type for the RPC input of a modal
792
- * Just the `params` type of each `ModalStepTypes`
793
- * @typeParam T - The list of modal steps we expect to have in the modal
794
- * @group Modal Display
795
- * @group RPC Schema
796
- */
797
- declare type ModalRpcStepsInput<T extends ModalStepTypes[] = ModalStepTypes[]> = {
798
- [K in T[number]["key"]]?: Extract<T[number], {
799
- key: K;
800
- }>["params"];
801
- };
802
-
803
- /**
804
- * Type for the result of a modal request
805
- * Just the `returns` type of each `ModalStepTypes`
806
- * @typeParam T - The list of modal steps we expect to have in the modal
807
- * @group Modal Display
808
- * @group RPC Schema
809
- */
810
- declare type ModalRpcStepsResultType<T extends ModalStepTypes[] = ModalStepTypes[]> = {
811
- [K in T[number]["key"]]: Extract<T[number], {
812
- key: K;
813
- }>["returns"];
814
- };
815
-
816
- /**
817
- * Represent the type of the modal step builder
818
- */
819
- export declare type ModalStepBuilder<Steps extends ModalStepTypes[] = ModalStepTypes[]> = {
820
- /**
821
- * The current modal params
822
- */
823
- params: DisplayModalParamsType<Steps>;
824
- /**
825
- * Add a send transaction step to the modal
826
- */
827
- sendTx: (options: SendTransactionModalStepType["params"]) => ModalStepBuilder<[...Steps, SendTransactionModalStepType]>;
828
- /**
829
- * Add a final step of type reward to the modal
830
- */
831
- reward: (options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
832
- /**
833
- * Add a final step of type sharing to the modal
834
- */
835
- sharing: (sharingOptions?: Extract<FinalActionType, {
836
- key: "sharing";
837
- }>["options"], options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
838
- /**
839
- * Display the modal
840
- * @param metadataOverride - Function returning optional metadata to override the current modal metadata
841
- */
842
- display: (metadataOverride?: (current?: ModalRpcMetadata) => ModalRpcMetadata | undefined) => Promise<ModalRpcStepsResultType<Steps>>;
843
- };
844
-
845
- /**
846
- * Metadata that can be used to customize a modal step
847
- * @group Modal Display
848
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
849
- */
850
- declare type ModalStepMetadata = {
851
- metadata?: {
852
- /**
853
- * Custom title for the step
854
- * If none provided, it will use an internationalized text
855
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
856
- */
857
- title?: string;
858
- /**
859
- * Custom description for the step
860
- * If none provided, it will use an internationalized text
861
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
862
- */
863
- description?: string;
864
- /**
865
- * Custom text for the primary action of the step
866
- * If none provided, it will use an internationalized text
867
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
868
- */
869
- primaryActionText?: string;
870
- /**
871
- * Custom text for the secondary action of the step
872
- * If none provided, it will use an internationalized text
873
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
874
- */
875
- secondaryActionText?: string;
876
- };
877
- };
878
-
879
- /**
880
- * Generic type of steps we will display in the modal to the end user
881
- * @group Modal Display
882
- */
883
- declare type ModalStepTypes = LoginModalStepType | SiweAuthenticateModalStepType | SendTransactionModalStepType | OpenInteractionSessionModalStepType | FinalModalStepType;
884
-
885
- /**
886
- * The open interaction session step for a Modal
887
- *
888
- * **Input**: None
889
- * **Output**: The interactions session period (start and end timestamp)
890
- *
891
- * @group Modal Display
892
- */
893
- declare type OpenInteractionSessionModalStepType = GenericModalStepType<"openSession", object, OpenInteractionSessionReturnType>;
894
-
895
- /**
896
- * Return type of the open session modal step
897
- * @inline
898
- * @ignore
899
- */
900
- declare type OpenInteractionSessionReturnType = {
901
- startTimestamp: number;
902
- endTimestamp: number;
903
- };
904
-
905
- /**
906
- * Function used to open the SSO
907
- * @param client - The current Frak Client
908
- * @param args - The SSO parameters
909
- *
910
- * @description This function will open the SSO with the provided parameters.
911
- *
912
- * @example
913
- * First we build the sso metadata
914
- * ```ts
915
- * // Build the metadata
916
- * const metadata: SsoMetadata = {
917
- * logoUrl: "https://my-app.com/logo.png",
918
- * homepageLink: "https://my-app.com",
919
- * };
920
- * ```
921
- *
922
- * Then, either use it with direct exit (and so user is directly redirected to your website), or a custom redirect URL
923
- * :::code-group
924
- * ```ts [Direct exit]
925
- * // Trigger an sso opening with redirection
926
- * await openSso(frakConfig, {
927
- * directExit: true,
928
- * metadata,
929
- * });
930
- * ```
931
- * ```ts [Redirection]
932
- * // Trigger an sso opening within a popup with direct exit
933
- * await openSso(frakConfig, {
934
- * redirectUrl: "https://my-app.com/frak-sso",
935
- * metadata,
936
- * });
937
- * ```
938
- * ```ts [With tracking]
939
- * // Trigger an sso with consumeKey for tracking
940
- * const result = await openSso(frakConfig, {
941
- * directExit: true,
942
- * generateConsumeKey: true,
943
- * metadata,
944
- * });
945
- * console.log(result.consumeKey); // Use this to track SSO status
946
- * ```
947
- * :::
948
- */
949
- export declare function openSso(client: FrakClient, args: OpenSsoParamsType): Promise<OpenSsoReturnType>;
950
-
951
- /**
952
- * Params to start a SSO
953
- * @group RPC Schema
954
- */
955
- declare type OpenSsoParamsType = {
956
- /**
957
- * Redirect URL after the SSO (optional)
958
- */
959
- redirectUrl?: string;
960
- /**
961
- * If the SSO should directly exit after completion
962
- * @defaultValue true
963
- */
964
- directExit?: boolean;
965
- /**
966
- * If true, opens SSO in same window instead of popup
967
- * Defaults to true when redirectUrl is provided, false otherwise
968
- */
969
- openInSameWindow?: boolean;
970
- /**
971
- * Language of the SSO page (optional)
972
- * It will default to the current user language (or "en" if unsupported language)
973
- */
974
- lang?: "en" | "fr";
975
- /**
976
- * Custom SSO metadata
977
- */
978
- metadata: SsoMetadata;
979
- };
980
-
981
- /**
982
- * Response after an SSO has been openned
983
- */
984
- declare type OpenSsoReturnType = {
985
- /**
986
- * Optional wallet address, returned when SSO completes via postMessage
987
- * Note: Only present when SSO flow completes (not immediately on open)
988
- */
989
- wallet?: Hex;
990
- };
991
-
992
- /**
993
- * Represent a prepared user interaction, ready to be sent on-chain via the wallet
994
- */
995
- declare type PreparedInteraction = {
996
- handlerTypeDenominator: Hex;
997
- interactionData: Hex;
998
- };
999
-
1000
- /**
1001
- * This function handle all the heavy lifting of the referral interaction process
1002
- * 1. Check if the user has been referred or not (if not, early exit)
1003
- * 2. Then check if the user is logged in or not
1004
- * 2.1 If not logged in, try a soft login, if it fail, display a modal for the user to login
1005
- * 3. Check if that's not a self-referral (if yes, early exit)
1006
- * 4. Check if the user has an interaction session or not
1007
- * 4.1 If not, display a modal for the user to open a session
1008
- * 5. Push the referred interaction
1009
- * 6. Update the current url with the right data
1010
- * 7. Return the resulting referral state
1011
- *
1012
- * If any error occurs during the process, the function will catch it and return an error state
1013
- *
1014
- * @param client - The current Frak Client
1015
- * @param args
1016
- * @param args.walletStatus - The current user wallet status
1017
- * @param args.frakContext - The current frak context
1018
- * @param args.modalConfig - The modal configuration to display if the user is not logged in
1019
- * @param args.productId - The product id to interact with (if not specified will be recomputed from the current domain)
1020
- * @param args.options - Some options for the referral interaction
1021
- * @returns A promise with the resulting referral state
1022
- *
1023
- * @see {@link displayModal} for more details about the displayed modal
1024
- * @see {@link sendInteraction} for more details on the interaction submission part
1025
- * @see {@link ReferralInteractionEncoder} for more details about the referred interaction
1026
- * @see {@link ModalStepTypes} for more details on each modal steps types
1027
- */
1028
- export declare function processReferral(client: FrakClient, { walletStatus, frakContext, modalConfig, productId, options, }: {
1029
- walletStatus?: WalletStatusReturnType;
1030
- frakContext?: Partial<FrakContext> | null;
1031
- modalConfig?: DisplayEmbeddedWalletParamsType;
1032
- productId?: Hex;
1033
- options?: ProcessReferralOptions;
1034
- }): Promise<ReferralState>;
1035
-
1036
- /**
1037
- * Options for the referral auto-interaction process
1038
- */
1039
- export declare type ProcessReferralOptions = {
1040
- /**
1041
- * If we want to always append the url with the frak context or not
1042
- * @defaultValue false
1043
- */
1044
- alwaysAppendUrl?: boolean;
1045
- };
1046
-
1047
- /**
1048
- * List of the product types per denominator
1049
- */
1050
- declare const productTypes: {
1051
- dapp: number;
1052
- press: number;
1053
- webshop: number;
1054
- retail: number;
1055
- referral: number;
1056
- purchase: number;
1057
- };
1058
-
1059
- /**
1060
- * The keys for each product types
1061
- * @inline
1062
- */
1063
- declare type ProductTypesKey = keyof typeof productTypes;
1064
-
1065
- /**
1066
- * Function used to display a modal
1067
- * @param client - The current Frak Client
1068
- * @param args
1069
- * @param args.productId - The product id to interact with (if not specified will be recomputed from the current domain)
1070
- * @param args.modalConfig - The modal configuration to display if the user is not logged in
1071
- * @param args.options - Some options for the referral interaction
1072
- *
1073
- * @returns A promise with the resulting referral state, or undefined in case of an error
1074
- *
1075
- * @description This function will automatically handle the referral interaction process
1076
- *
1077
- * @see {@link processReferral} for more details on the automatic referral handling process
1078
- * @see {@link ModalStepTypes} for more details on each modal steps types
1079
- */
1080
- export declare function referralInteraction(client: FrakClient, { productId, modalConfig, options, }?: {
1081
- productId?: Hex;
1082
- modalConfig?: DisplayEmbeddedWalletParamsType;
1083
- options?: ProcessReferralOptions;
1084
- }): Promise<("error" | "idle" | "processing" | "success" | "no-wallet" | "no-session" | "no-referrer" | "self-referral") | undefined>;
1085
-
1086
- /**
1087
- * The different states of the referral process
1088
- * @inline
1089
- */
1090
- declare type ReferralState = "idle" | "processing" | "success" | "no-wallet" | "no-session" | "error" | "no-referrer" | "self-referral";
1091
-
1092
- /**
1093
- * Function used to send an interaction
1094
- * @param client - The current Frak Client
1095
- * @param args
1096
- *
1097
- * @example
1098
- * const interaction = PressInteractionEncoder.openArticle({
1099
- * articleId: keccak256(toHex("article-slug")),
1100
- * });
1101
- * const { delegationId } = await sendInteraction(frakConfig, {
1102
- * interaction,
1103
- * });
1104
- * console.log("Delegated interaction id", delegationId);
1105
- */
1106
- export declare function sendInteraction(client: FrakClient, { productId, interaction, validation }: SendInteractionParamsType): Promise<SendInteractionReturnType>;
1107
-
1108
- /**
1109
- * Parameters that will be used to send an interaction to the blockchain
1110
- * @inline
1111
- */
1112
- declare type SendInteractionParamsType = {
1113
- /**
1114
- * The product id where this interaction has been made
1115
- * @defaultValue keccak256(toHex(window.location.host))
1116
- */
1117
- productId?: Hex;
1118
- /**
1119
- * The prepared interaction, built from an Interaction Encoder
1120
- */
1121
- interaction: PreparedInteraction;
1122
- /**
1123
- * A pre-computed interaction signature
1124
- * If none provided, the delegated interaction validator of your product will sign it (you can manage it in the business dashboard)
1125
- *
1126
- * @defaultValue undefined
1127
- */
1128
- validation?: Hex;
1129
- };
1130
-
1131
- /**
1132
- * Return type of the send interaction rpc request
1133
- * @group RPC Schema
1134
- */
1135
- declare type SendInteractionReturnType = {
1136
- /**
1137
- * The id of the interaction in the interaction pool
1138
- */
1139
- delegationId: string;
1140
- };
1141
-
1142
- /**
1143
- * Function used to send a user transaction, simple wrapper around the displayModal function to ease the send transaction process
1144
- * @param client - The current Frak Client
1145
- * @param args - The parameters
1146
- * @returns The hash of the transaction that was sent in a promise
1147
- *
1148
- * @description This function will display a modal to the user with the provided transaction and metadata.
1149
- *
1150
- * @example
1151
- * const { hash } = await sendTransaction(frakConfig, {
1152
- * tx: {
1153
- * to: "0xdeadbeef",
1154
- * value: toHex(100n),
1155
- * },
1156
- * metadata: {
1157
- * header: {
1158
- * title: "Sending eth",
1159
- * },
1160
- * context: "Send 100wei to 0xdeadbeef",
1161
- * },
1162
- * });
1163
- * console.log("Transaction hash:", hash);
1164
- */
1165
- export declare function sendTransaction(client: FrakClient, { tx, metadata }: SendTransactionParams): Promise<SendTransactionReturnType>;
1166
-
1167
- /**
1168
- * The send transaction step for a Modal
1169
- *
1170
- * **Input**: Either a single tx or an array of tx to be sent
1171
- * **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)
1172
- *
1173
- * @group Modal Display
1174
- */
1175
- declare type SendTransactionModalStepType = GenericModalStepType<"sendTransaction", {
1176
- tx: SendTransactionTxType | SendTransactionTxType[];
1177
- }, SendTransactionReturnType>;
1178
-
1179
- /**
1180
- * Parameters to directly show a modal used to send a transaction
1181
- * @inline
1182
- */
1183
- export declare type SendTransactionParams = {
1184
- /**
1185
- * The transaction to be sent (either a single tx or multiple ones)
1186
- */
1187
- tx: SendTransactionModalStepType["params"]["tx"];
1188
- /**
1189
- * Custom metadata to be passed to the modal
1190
- */
1191
- metadata?: ModalRpcMetadata;
1192
- };
1193
-
1194
- /**
1195
- * Return type of the send transaction rpc request
1196
- * @inline
1197
- */
1198
- declare type SendTransactionReturnType = {
1199
- hash: Hex;
1200
- };
1201
-
1202
- /**
1203
- * Generic format representing a tx to be sent
1204
- */
1205
- declare type SendTransactionTxType = {
1206
- to: Address;
1207
- data?: Hex;
1208
- value?: Hex;
1209
- };
1210
-
1211
- /**
1212
- * Function used to launch a siwe authentication
1213
- * @param client - The current Frak Client
1214
- * @param args - The parameters
1215
- * @returns The SIWE authentication result (message + signature) in a promise
1216
- *
1217
- * @description This function will display a modal to the user with the provided SIWE parameters and metadata.
1218
- *
1219
- * @example
1220
- * import { siweAuthenticate } from "@frak-labs/core-sdk/actions";
1221
- * import { parseSiweMessage } from "viem/siwe";
1222
- *
1223
- * const { signature, message } = await siweAuthenticate(frakConfig, {
1224
- * siwe: {
1225
- * statement: "Sign in to My App",
1226
- * domain: "my-app.com",
1227
- * expirationTimeTimestamp: Date.now() + 1000 * 60 * 5,
1228
- * },
1229
- * metadata: {
1230
- * header: {
1231
- * title: "Sign in",
1232
- * },
1233
- * context: "Sign in to My App",
1234
- * },
1235
- * });
1236
- * console.log("Parsed final message:", parseSiweMessage(message));
1237
- * console.log("Siwe signature:", signature);
1238
- */
1239
- export declare function siweAuthenticate(client: FrakClient, { siwe, metadata }: SiweAuthenticateModalParams): Promise<SiweAuthenticateReturnType>;
1240
-
1241
- /**
1242
- * Parameter used to directly show a modal used to authenticate with SIWE
1243
- * @inline
1244
- */
1245
- export declare type SiweAuthenticateModalParams = {
1246
- /**
1247
- * Partial SIWE params, since we can rebuild them from the SDK if they are empty
1248
- *
1249
- * If no parameters provider, some fields will be recomputed from the current configuration and environment.
1250
- * - `statement` will be set to a default value
1251
- * - `nonce` will be generated
1252
- * - `uri` will be set to the current domain
1253
- * - `version` will be set to "1"
1254
- * - `domain` will be set to the current window domain
1255
- *
1256
- * @default {}
1257
- */
1258
- siwe?: Partial<SiweAuthenticationParams>;
1259
- /**
1260
- * Custom metadata to be passed to the modal
1261
- */
1262
- metadata?: ModalRpcMetadata;
1263
- };
1264
-
1265
- /**
1266
- * The SIWE authentication step for a Modal
1267
- *
1268
- * **Input**: SIWE message parameters
1269
- * **Output**: SIWE result (message signed and wallet signature)
1270
- *
1271
- * @group Modal Display
1272
- */
1273
- declare type SiweAuthenticateModalStepType = GenericModalStepType<"siweAuthenticate", {
1274
- siwe: SiweAuthenticationParams;
1275
- }, SiweAuthenticateReturnType>;
1276
-
1277
- /**
1278
- * Return type of the Siwe transaction rpc request
1279
- * @inline
1280
- */
1281
- declare type SiweAuthenticateReturnType = {
1282
- signature: Hex;
1283
- message: string;
1284
- };
1285
-
1286
- /**
1287
- * Parameters used send a SIWE rpc request
1288
- */
1289
- declare type SiweAuthenticationParams = Omit<SiweMessage, "address" | "chainId" | "expirationTime" | "issuedAt" | "notBefore"> & {
1290
- expirationTimeTimestamp?: number;
1291
- notBeforeTimestamp?: number;
1292
- };
1293
-
1294
- /**
1295
- * SSO Metadata
1296
- */
1297
- declare type SsoMetadata = {
1298
- /**
1299
- * URL to your client, if provided will be displayed in the SSO header
1300
- */
1301
- logoUrl?: string;
1302
- /**
1303
- * Link to your homepage, if referenced your app name will contain a link on the sso page
1304
- */
1305
- homepageLink?: string;
1306
- };
1307
-
1308
- /**
1309
- * The type for the amount of tokens
1310
- */
1311
- declare type TokenAmountType = {
1312
- amount: number;
1313
- eurAmount: number;
1314
- usdAmount: number;
1315
- gbpAmount: number;
1316
- };
1317
-
1318
- /**
1319
- * Function used to track the status of a purchase
1320
- * when a purchase is tracked, the `purchaseCompleted` interactions will be automatically send for the user when we receive the purchase confirmation via webhook.
1321
- *
1322
- * @param args.customerId - The customer id that made the purchase (on your side)
1323
- * @param args.orderId - The order id of the purchase (on your side)
1324
- * @param args.token - The token of the purchase
1325
- *
1326
- * @description This function will send a request to the backend to listen for the purchase status.
1327
- *
1328
- * @example
1329
- * async function trackPurchase(checkout) {
1330
- * const payload = {
1331
- * customerId: checkout.order.customer.id,
1332
- * orderId: checkout.order.id,
1333
- * token: checkout.token,
1334
- * };
1335
- *
1336
- * await trackPurchaseStatus(payload);
1337
- * }
1338
- *
1339
- * @remarks
1340
- * - The `trackPurchaseStatus` function requires the `frak-wallet-interaction-token` stored in the session storage to authenticate the request.
1341
- * - This function will print a warning if used in a non-browser environment or if the wallet interaction token is not available.
1342
- */
1343
- export declare function trackPurchaseStatus(args: {
1344
- customerId: string | number;
1345
- orderId: string | number;
1346
- token: string;
1347
- }): Promise<void>;
1348
-
1349
- /**
1350
- * @ignore
1351
- * @inline
1352
- */
1353
- declare type WalletConnected = {
1354
- key: "connected";
1355
- wallet: Address;
1356
- interactionToken?: string;
1357
- interactionSession?: {
1358
- startTimestamp: number;
1359
- endTimestamp: number;
1360
- };
1361
- };
1362
-
1363
- /**
1364
- * @ignore
1365
- * @inline
1366
- */
1367
- declare type WalletNotConnected = {
1368
- key: "not-connected";
1369
- wallet?: never;
1370
- interactionToken?: never;
1371
- interactionSession?: never;
1372
- };
1373
-
1374
- /**
1375
- * RPC Response for the method `frak_listenToWalletStatus`
1376
- * @group RPC Schema
1377
- */
1378
- declare type WalletStatusReturnType = WalletConnected | WalletNotConnected;
1379
-
1380
- /**
1381
- * Function used to watch the current frak wallet status
1382
- * @param client - The current Frak Client
1383
- * @param callback - The callback that will receive any wallet status change
1384
- * @returns A promise resolving with the initial wallet status
1385
- *
1386
- * @description This function will return the current wallet status, and will listen to any change in the wallet status.
1387
- *
1388
- * @example
1389
- * await watchWalletStatus(frakConfig, (status: WalletStatusReturnType) => {
1390
- * if (status.key === "connected") {
1391
- * console.log("Wallet connected:", status.wallet);
1392
- * console.log("Current interaction session:", status.interactionSession);
1393
- * } else {
1394
- * console.log("Wallet not connected");
1395
- * }
1396
- * });
1397
- */
1398
- export declare function watchWalletStatus(client: FrakClient, callback?: (status: WalletStatusReturnType) => void): Promise<WalletStatusReturnType>;
1399
-
1400
- 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 };