@frak-labs/core-sdk 0.0.19 → 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 -2022
  10. package/dist/bundle.d.ts +6 -2022
  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 -1373
  20. package/dist/index.d.ts +4 -1373
  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 +27 -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.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 { OpenPanel } from '@openpanel/web';
4
- import type { Prettify } from 'viem/chains';
5
- import type { RpcSchema } from 'viem';
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
- * Type that extract the possible return type from a RPC Schema
242
- * @ignore
243
- */
244
- declare type ExtractedMethodFromRpc<TRpcSchema extends RpcSchema, TMethod extends ExtractedParametersFromRpc<TRpcSchema>["method"] = ExtractedParametersFromRpc<TRpcSchema>["method"]> = Extract<TRpcSchema[number], {
245
- Method: TMethod;
246
- }>;
247
-
248
- /**
249
- * Type that extract the possible parameters from a RPC Schema
250
- * @ignore
251
- */
252
- declare type ExtractedParametersFromRpc<TRpcSchema extends RpcSchema> = {
253
- [K in keyof TRpcSchema]: Prettify<{
254
- method: TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Method"] : string;
255
- } & (TRpcSchema[K] extends TRpcSchema[number] ? TRpcSchema[K]["Parameters"] extends undefined ? {
256
- params?: never;
257
- } : {
258
- params: TRpcSchema[K]["Parameters"];
259
- } : never)>;
260
- }[number];
261
-
262
- /**
263
- * Type that extract the possible return type from a RPC Schema
264
- * @ignore
265
- */
266
- declare type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>> = ExtractedMethodFromRpc<TRpcSchema, TParameters["method"]>["ReturnType"];
267
-
268
- /**
269
- * The different types of final actions we can display in the final step
270
- * @group Modal Display
271
- */
272
- declare type FinalActionType = {
273
- key: "sharing";
274
- options?: {
275
- /**
276
- * @deprecated Use the top level `config.metadata.i18n` instead
277
- */
278
- popupTitle?: string;
279
- /**
280
- * @deprecated Use the top level `config.metadata.i18n` instead
281
- */
282
- text?: string;
283
- link?: string;
284
- };
285
- } | {
286
- key: "reward";
287
- options?: never;
288
- };
289
-
290
- /**
291
- * The final modal step type, could be used to display sharing options or a success reward screen.
292
- *
293
- * **Input**: What type final step to display?
294
- * **Output**: None
295
- *
296
- * @group Modal Display
297
- */
298
- declare type FinalModalStepType = GenericModalStepType<"final", {
299
- dismissedMetadata?: ModalStepMetadata["metadata"];
300
- action: FinalActionType;
301
- autoSkip?: boolean;
302
- }, object>;
303
-
304
- /**
305
- * Representing a Frak client, used to interact with the Frak Wallet
306
- */
307
- declare type FrakClient = {
308
- config: FrakWalletSdkConfig;
309
- debugInfo: {
310
- formatDebugInfo: (error: Error | unknown | string) => string;
311
- };
312
- openPanel?: OpenPanel;
313
- } & IFrameTransport;
314
-
315
- /**
316
- * The current Frak Context
317
- *
318
- * For now, only contain a referrer address.
319
- *
320
- * @ignore
321
- */
322
- declare type FrakContext = {
323
- r: Address;
324
- };
325
-
326
- /**
327
- * Configuration for the Frak Wallet SDK
328
- * @category Config
329
- */
330
- declare type FrakWalletSdkConfig = {
331
- /**
332
- * The Frak wallet url
333
- * @defaultValue "https://wallet.frak.id"
334
- */
335
- walletUrl?: string;
336
- /**
337
- * Some metadata about your implementation of the Frak SDK
338
- */
339
- metadata: {
340
- /**
341
- * Your application name (will be displayed in a few modals and in SSO)
342
- */
343
- name: string;
344
- /**
345
- * Language to display in the modal
346
- * If undefined, will default to the browser language
347
- */
348
- lang?: Language;
349
- /**
350
- * The currency to display in the modal
351
- * @defaultValue `"eur"`
352
- */
353
- currency?: Currency;
354
- /**
355
- * The logo URL that will be displayed in a few components
356
- */
357
- logoUrl?: string;
358
- /**
359
- * The homepage link that could be displayed in a few components
360
- */
361
- homepageLink?: string;
362
- };
363
- /**
364
- * Some customization for the modal
365
- */
366
- customizations?: {
367
- /**
368
- * Custom CSS styles to apply to the modals and components
369
- */
370
- css?: `${string}.css`;
371
- /**
372
- * Custom i18n configuration for the modal
373
- */
374
- i18n?: I18nConfig;
375
- };
376
- /**
377
- * The domain name of your application
378
- * @defaultValue window.location.host
379
- */
380
- domain?: string;
381
- };
382
-
383
- /**
384
- * The keys for each interaction types (e.g. `press.openArticle`) -> category_type.interaction_type
385
- * @inline
386
- */
387
- declare type FullInteractionTypesKey = {
388
- [Category in keyof typeof interactionTypes]: `${Category & string}.${keyof (typeof interactionTypes)[Category] & string}`;
389
- }[keyof typeof interactionTypes];
390
-
391
- /**
392
- * Represent a generic modal step type
393
- * @ignore
394
- * @inline
395
- */
396
- declare type GenericModalStepType<TKey, TParams, TReturns> = {
397
- key: TKey;
398
- params: TParams extends never ? ModalStepMetadata : ModalStepMetadata & TParams;
399
- returns: TReturns;
400
- };
401
-
402
- /**
403
- * Function used to get the current product information
404
- * @param client - The current Frak Client
405
- * @returns The product information in a promise
406
- */
407
- export declare function getProductInformation(client: FrakClient): Promise<GetProductInformationReturnType>;
408
-
409
- /**
410
- * Response of the `frak_getProductInformation` RPC method
411
- * @group RPC Schema
412
- */
413
- declare type GetProductInformationReturnType = {
414
- /**
415
- * Current product id
416
- */
417
- id: Hex;
418
- /**
419
- * Some metadata
420
- */
421
- onChainMetadata: {
422
- /**
423
- * Name of the product on-chain
424
- */
425
- name: string;
426
- /**
427
- * Domain of the product on-chain
428
- */
429
- domain: string;
430
- /**
431
- * The supported product types
432
- */
433
- productTypes: ProductTypesKey[];
434
- };
435
- /**
436
- * The max potential reward for the referrer
437
- */
438
- maxReferrer?: TokenAmountType;
439
- /**
440
- * The max potential reward for the referee
441
- */
442
- maxReferee?: TokenAmountType;
443
- /**
444
- * List of all the potentials reward arround this product
445
- */
446
- rewards: {
447
- token: Address;
448
- campaign: Address;
449
- interactionTypeKey: FullInteractionTypesKey;
450
- referrer: TokenAmountType;
451
- referee: TokenAmountType;
452
- }[];
453
- };
454
-
455
- /**
456
- * Custom i18n configuration for the modal
457
- * See [i18next json format](https://www.i18next.com/misc/json-format#i18next-json-v4)
458
- *
459
- * Available variables
460
- * - `{{ productName }}` : The name of your website (`metadata.name`)
461
- * - `{{ productOrigin }}` : The origin url of your website
462
- * - `{{ 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)
463
- *
464
- * Context of the translation [see i18n context](https://www.i18next.com/translation-function/context)
465
- * - For modal display, the key of the final action (`sharing`, `reward`, or undefined)
466
- * - For embedded wallet display, the key of the logged in action (`sharing` or undefined)
467
- *
468
- * @example
469
- * ```ts
470
- * // Multi language config
471
- * const multiI18n = {
472
- * fr: {
473
- * "sdk.modal.title": "Titre de modal",
474
- * "sdk.modal.description": "Description de modal, avec {{ estimatedReward }} de gains possible",
475
- * },
476
- * en: "https://example.com/en.json"
477
- * }
478
- *
479
- * // Single language config
480
- * const singleI18n = {
481
- * "sdk.modal.title": "Modal title",
482
- * "sdk.modal.description": "Modal description, with {{ estimatedReward }} of gains possible",
483
- * }
484
- * ```
485
- *
486
- * @category Config
487
- */
488
- declare type I18nConfig = Record<Language, LocalizedI18nConfig> | LocalizedI18nConfig;
489
-
490
- /**
491
- * RPC interface that's used for the iframe communication
492
- *
493
- * Define all the methods available within the iFrame RPC client
494
- *
495
- * @group RPC Schema
496
- *
497
- * @remarks
498
- * Here is the list of methods available:
499
- *
500
- * ### frak_listenToWalletStatus
501
- * - Params: None
502
- * - Returns: {@link WalletStatusReturnType}
503
- *
504
- * ### frak_displayModal
505
- * - Params: [{@link ModalRpcStepsInput}, name: string, metadata?: {@link ModalRpcMetadata}]
506
- * - Returns: {@link ModalRpcStepsResultType}
507
- *
508
- * ### frak_sendInteraction
509
- * - Params: [productId: Hex, interaction: {@link PreparedInteraction}, signature?: Hex]
510
- * - Returns: {@link SendInteractionReturnType}
511
- *
512
- * ### frak_sso
513
- * - Params [params: {@link OpenSsoParamsType}, name: string, customCss?: string]
514
- * - Returns: undefined
515
- *
516
- * ### frak_getProductInformation
517
- * - Params: None
518
- * - Returns: {@link GetProductInformationReturnType}
519
- *
520
- * ### frak_displayEmbeddedWallet
521
- * - Params: [{@link DisplayEmbeddedWalletParamsType}]
522
- * - Returns: {@link DisplayEmbeddedWalletResultType}
523
- */
524
- declare type IFrameRpcSchema = [
525
- /**
526
- * Method used to listen to the wallet status
527
- */
528
- {
529
- Method: "frak_listenToWalletStatus";
530
- Parameters?: undefined;
531
- ReturnType: WalletStatusReturnType;
532
- },
533
- /**
534
- * Method to display a modal with the provided steps
535
- */
536
- {
537
- Method: "frak_displayModal";
538
- Parameters: [
539
- requests: ModalRpcStepsInput,
540
- metadata: ModalRpcMetadata | undefined,
541
- configMetadata: FrakWalletSdkConfig["metadata"]
542
- ];
543
- ReturnType: ModalRpcStepsResultType;
544
- },
545
- /**
546
- * Method to transmit a user interaction
547
- */
548
- {
549
- Method: "frak_sendInteraction";
550
- Parameters: [
551
- productId: Hex,
552
- interaction: PreparedInteraction,
553
- signature?: Hex
554
- ];
555
- ReturnType: SendInteractionReturnType;
556
- },
557
- /**
558
- * Method to start a SSO
559
- * todo: Should also support direct tracking via a consumeKey
560
- */
561
- {
562
- Method: "frak_sso";
563
- Parameters: [
564
- params: OpenSsoParamsType,
565
- name: string,
566
- customCss?: string
567
- ];
568
- ReturnType: undefined;
569
- },
570
- /**
571
- * Method to get current product information's
572
- * - Is product minted?
573
- * - Does it have running campaign?
574
- * - Estimated reward on actions
575
- */
576
- {
577
- Method: "frak_getProductInformation";
578
- Parameters?: undefined;
579
- ReturnType: GetProductInformationReturnType;
580
- },
581
- /**
582
- * Method to show the embedded wallet, with potential customization
583
- */
584
- {
585
- Method: "frak_displayEmbeddedWallet";
586
- Parameters: [
587
- request: DisplayEmbeddedWalletParamsType,
588
- metadata: FrakWalletSdkConfig["metadata"]
589
- ];
590
- ReturnType: DisplayEmbeddedWalletResultType;
591
- }
592
- ];
593
-
594
- /**
595
- * IFrame transport interface
596
- */
597
- declare type IFrameTransport = {
598
- /**
599
- * Wait for the connection to be established
600
- */
601
- waitForConnection: Promise<boolean>;
602
- /**
603
- * Wait for the setup to be done
604
- */
605
- waitForSetup: Promise<void>;
606
- /**
607
- * Function used to perform a single request via the iframe transport
608
- */
609
- request: RequestFn<IFrameRpcSchema>;
610
- /**
611
- * Function used to listen to a request response via the iframe transport
612
- */
613
- listenerRequest: ListenerRequestFn<IFrameRpcSchema>;
614
- /**
615
- * Function used to destroy the iframe transport
616
- */
617
- destroy: () => Promise<void>;
618
- };
619
-
620
- /**
621
- * Each interactions types according to the product types
622
- */
623
- declare const interactionTypes: {
624
- readonly press: {
625
- readonly openArticle: "0xc0a24ffb";
626
- readonly readArticle: "0xd5bd0fbe";
627
- };
628
- readonly dapp: {
629
- readonly proofVerifiableStorageUpdate: "0x2ab2aeef";
630
- readonly callableVerifiableStorageUpdate: "0xa07da986";
631
- };
632
- readonly webshop: {
633
- readonly open: "0xb311798f";
634
- };
635
- readonly referral: {
636
- readonly referred: "0x010cc3b9";
637
- readonly createLink: "0xb2c0f17c";
638
- };
639
- readonly purchase: {
640
- readonly started: "0xd87e90c3";
641
- readonly completed: "0x8403aeb4";
642
- readonly unsafeCompleted: "0x4d5b14e0";
643
- };
644
- readonly retail: {
645
- readonly customerMeeting: "0x74489004";
646
- };
647
- };
648
-
649
- /**
650
- * All the languages available
651
- * @category Config
652
- */
653
- declare type Language = "fr" | "en";
654
-
655
- /**
656
- * Type used for a listening request
657
- * @inline
658
- */
659
- declare type ListenerRequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters, callback: (result: _ReturnType) => void) => Promise<void>;
660
-
661
- /**
662
- * A localized i18n config
663
- * @category Config
664
- */
665
- declare type LocalizedI18nConfig = `${string}.css` | {
666
- [key: string]: string;
667
- };
668
-
669
- /**
670
- * Some configuration options for the embedded view
671
- *
672
- * @group Embedded wallet
673
- */
674
- declare type LoggedInEmbeddedView = {
675
- /**
676
- * The main action to display on the logged in embedded view
677
- */
678
- action?: EmbeddedViewActionSharing | EmbeddedViewActionReferred;
679
- };
680
-
681
- /**
682
- * The view when a user is logged out
683
- * @group Embedded wallet
684
- */
685
- declare type LoggedOutEmbeddedView = {
686
- /**
687
- * Metadata option when displaying the embedded view
688
- */
689
- metadata?: {
690
- /**
691
- * The main CTA for the logged out view
692
- * - can include some variable, available ones are:
693
- * - {REWARD} -> The maximum reward a user can receive when interacting on your website
694
- * - can be formatted in markdown
695
- *
696
- * If not set, it will default to a internationalized message
697
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
698
- */
699
- text?: string;
700
- /**
701
- * The text that will be displayed on the login button
702
- *
703
- * If not set, it will default to a internationalized message
704
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
705
- */
706
- buttonText?: string;
707
- };
708
- };
709
-
710
- /**
711
- * The login step for a Modal
712
- *
713
- * **Input**: Do we allow SSO or not? Is yes then the SSO metadata
714
- * **Output**: The logged in wallet address
715
- *
716
- * @group Modal Display
717
- */
718
- declare type LoginModalStepType = GenericModalStepType<"login", LoginWithSso | LoginWithoutSso, {
719
- wallet: Address;
720
- }>;
721
-
722
- /** @inline */
723
- declare type LoginWithoutSso = {
724
- allowSso?: false;
725
- ssoMetadata?: never;
726
- };
727
-
728
- /** @inline */
729
- declare type LoginWithSso = {
730
- allowSso: true;
731
- ssoMetadata?: SsoMetadata;
732
- };
733
-
734
- /**
735
- * Represent the output type of the modal builder
736
- */
737
- export declare type ModalBuilder = ModalStepBuilder<[
738
- LoginModalStepType,
739
- OpenInteractionSessionModalStepType
740
- ]>;
741
-
742
- /**
743
- * Helper to craft Frak modal, and share a base initial config
744
- * @param client - The current Frak Client
745
- * @param args
746
- * @param args.metadata - Common modal metadata (customisation, language etc)
747
- * @param args.login - Login step parameters
748
- * @param args.openSession - Open session step parameters
749
- *
750
- * @description This function will create a modal builder with the provided metadata, login and open session parameters.
751
- *
752
- * @example
753
- * Here is an example of how to use the `modalBuilder` to create and display a sharing modal:
754
- *
755
- * ```js
756
- * // Create the modal builder
757
- * const modalBuilder = window.FrakSDK.modalBuilder(frakClient, baseModalConfig);
758
- *
759
- * // Configure the information to be shared via the sharing link
760
- * const sharingConfig = {
761
- * popupTitle: "Share this with your friends",
762
- * text: "Discover our product!",
763
- * link: window.location.href,
764
- * };
765
- *
766
- * // Display the sharing modal
767
- * function modalShare() {
768
- * modalBuilder.sharing(sharingConfig).display();
769
- * }
770
- * ```
771
- *
772
- * @see {@link ModalStepTypes} for more info about each modal step types and their parameters
773
- * @see {@link ModalRpcMetadata} for more info about the metadata that can be passed to the modal
774
- * @see {@link ModalRpcStepsResultType} for more info about the result of each modal steps
775
- * @see {@link displayModal} for more info about how the modal is displayed
776
- */
777
- export declare function modalBuilder(client: FrakClient, { metadata, login, openSession, }: {
778
- metadata?: ModalRpcMetadata;
779
- login?: LoginModalStepType["params"];
780
- openSession?: OpenInteractionSessionModalStepType["params"];
781
- }): ModalBuilder;
782
-
783
- /**
784
- * RPC metadata for the modal, used on top level modal configuration
785
- * @group Modal Display
786
- * @group RPC Schema
787
- */
788
- declare type ModalRpcMetadata = {
789
- header?: {
790
- title?: string;
791
- icon?: string;
792
- };
793
- targetInteraction?: FullInteractionTypesKey;
794
- /**
795
- * Some i18n override for the displayed modal (i.e. update the displayed text only for this modal)
796
- */
797
- i18n?: I18nConfig;
798
- } & ({
799
- isDismissible: true;
800
- /**
801
- * @deprecated Use `config.customizations.i18n` or `metadata.i18n` instead
802
- */
803
- dismissActionTxt?: string;
804
- } | {
805
- isDismissible?: false;
806
- dismissActionTxt?: never;
807
- });
808
-
809
- /**
810
- * Type for the RPC input of a modal
811
- * Just the `params` type of each `ModalStepTypes`
812
- * @typeParam T - The list of modal steps we expect to have in the modal
813
- * @group Modal Display
814
- * @group RPC Schema
815
- */
816
- declare type ModalRpcStepsInput<T extends ModalStepTypes[] = ModalStepTypes[]> = {
817
- [K in T[number]["key"]]?: Extract<T[number], {
818
- key: K;
819
- }>["params"];
820
- };
821
-
822
- /**
823
- * Type for the result of a modal request
824
- * Just the `returns` type of each `ModalStepTypes`
825
- * @typeParam T - The list of modal steps we expect to have in the modal
826
- * @group Modal Display
827
- * @group RPC Schema
828
- */
829
- declare type ModalRpcStepsResultType<T extends ModalStepTypes[] = ModalStepTypes[]> = {
830
- [K in T[number]["key"]]: Extract<T[number], {
831
- key: K;
832
- }>["returns"];
833
- };
834
-
835
- /**
836
- * Represent the type of the modal step builder
837
- */
838
- export declare type ModalStepBuilder<Steps extends ModalStepTypes[] = ModalStepTypes[]> = {
839
- /**
840
- * The current modal params
841
- */
842
- params: DisplayModalParamsType<Steps>;
843
- /**
844
- * Add a send transaction step to the modal
845
- */
846
- sendTx: (options: SendTransactionModalStepType["params"]) => ModalStepBuilder<[...Steps, SendTransactionModalStepType]>;
847
- /**
848
- * Add a final step of type reward to the modal
849
- */
850
- reward: (options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
851
- /**
852
- * Add a final step of type sharing to the modal
853
- */
854
- sharing: (sharingOptions?: Extract<FinalActionType, {
855
- key: "sharing";
856
- }>["options"], options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
857
- /**
858
- * Display the modal
859
- * @param metadataOverride - Function returning optional metadata to override the current modal metadata
860
- */
861
- display: (metadataOverride?: (current?: ModalRpcMetadata) => ModalRpcMetadata | undefined) => Promise<ModalRpcStepsResultType<Steps>>;
862
- };
863
-
864
- /**
865
- * Metadata that can be used to customize a modal step
866
- * @group Modal Display
867
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
868
- */
869
- declare type ModalStepMetadata = {
870
- metadata?: {
871
- /**
872
- * Custom title for the step
873
- * If none provided, it will use an internationalized text
874
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
875
- */
876
- title?: string;
877
- /**
878
- * Custom description for the step
879
- * If none provided, it will use an internationalized text
880
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
881
- */
882
- description?: string;
883
- /**
884
- * Custom text for the primary action of the step
885
- * If none provided, it will use an internationalized text
886
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
887
- */
888
- primaryActionText?: string;
889
- /**
890
- * Custom text for the secondary action of the step
891
- * If none provided, it will use an internationalized text
892
- * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
893
- */
894
- secondaryActionText?: string;
895
- };
896
- };
897
-
898
- /**
899
- * Generic type of steps we will display in the modal to the end user
900
- * @group Modal Display
901
- */
902
- declare type ModalStepTypes = LoginModalStepType | SiweAuthenticateModalStepType | SendTransactionModalStepType | OpenInteractionSessionModalStepType | FinalModalStepType;
903
-
904
- /**
905
- * The open interaction session step for a Modal
906
- *
907
- * **Input**: None
908
- * **Output**: The interactions session period (start and end timestamp)
909
- *
910
- * @group Modal Display
911
- */
912
- declare type OpenInteractionSessionModalStepType = GenericModalStepType<"openSession", object, OpenInteractionSessionReturnType>;
913
-
914
- /**
915
- * Return type of the open session modal step
916
- * @inline
917
- * @ignore
918
- */
919
- declare type OpenInteractionSessionReturnType = {
920
- startTimestamp: number;
921
- endTimestamp: number;
922
- };
923
-
924
- /**
925
- * Function used to open the SSO
926
- * @param client - The current Frak Client
927
- * @param args - The SSO parameters
928
- *
929
- * @description This function will open the SSO with the provided parameters.
930
- *
931
- * @example
932
- * First we build the sso metadata
933
- * ```ts
934
- * // Build the metadata
935
- * const metadata: SsoMetadata = {
936
- * logoUrl: "https://my-app.com/logo.png",
937
- * homepageLink: "https://my-app.com",
938
- * };
939
- * ```
940
- *
941
- * Then, either use it with direct exit (and so user is directly redirected to your website), or a custom redirect URL
942
- * :::code-group
943
- * ```ts [Direct exit]
944
- * // Trigger an sso opening with redirection
945
- * await openSso(frakConfig, {
946
- * directExit: true,
947
- * metadata,
948
- * });
949
- * ```
950
- * ```ts [Redirection]
951
- * // Trigger an sso opening within a popup with direct exit
952
- * await openSso(frakConfig, {
953
- * redirectUrl: "https://my-app.com/frak-sso",
954
- * metadata,
955
- * });
956
- * ```
957
- * :::
958
- */
959
- export declare function openSso(client: FrakClient, args: OpenSsoParamsType): Promise<void>;
960
-
961
- /**
962
- * Params to start a SSO
963
- * @group RPC Schema
964
- */
965
- declare type OpenSsoParamsType = {
966
- /**
967
- * Redirect URL after the SSO (optional)
968
- */
969
- redirectUrl?: string;
970
- /**
971
- * If the SSO should directly exit after completion
972
- * @defaultValue true
973
- */
974
- directExit?: boolean;
975
- /**
976
- * Language of the SSO page (optional)
977
- * It will default to the current user language (or "en" if unsupported language)
978
- */
979
- lang?: "en" | "fr";
980
- /**
981
- * Custom SSO metadata
982
- */
983
- metadata: SsoMetadata;
984
- };
985
-
986
- /**
987
- * Represent a prepared user interaction, ready to be sent on-chain via the wallet
988
- */
989
- declare type PreparedInteraction = {
990
- handlerTypeDenominator: Hex;
991
- interactionData: Hex;
992
- };
993
-
994
- /**
995
- * This function handle all the heavy lifting of the referral interaction process
996
- * 1. Check if the user has been referred or not (if not, early exit)
997
- * 2. Then check if the user is logged in or not
998
- * 2.1 If not logged in, try a soft login, if it fail, display a modal for the user to login
999
- * 3. Check if that's not a self-referral (if yes, early exit)
1000
- * 4. Check if the user has an interaction session or not
1001
- * 4.1 If not, display a modal for the user to open a session
1002
- * 5. Push the referred interaction
1003
- * 6. Update the current url with the right data
1004
- * 7. Return the resulting referral state
1005
- *
1006
- * If any error occurs during the process, the function will catch it and return an error state
1007
- *
1008
- * @param client - The current Frak Client
1009
- * @param args
1010
- * @param args.walletStatus - The current user wallet status
1011
- * @param args.frakContext - The current frak context
1012
- * @param args.modalConfig - The modal configuration to display if the user is not logged in
1013
- * @param args.productId - The product id to interact with (if not specified will be recomputed from the current domain)
1014
- * @param args.options - Some options for the referral interaction
1015
- * @returns A promise with the resulting referral state
1016
- *
1017
- * @see {@link displayModal} for more details about the displayed modal
1018
- * @see {@link sendInteraction} for more details on the interaction submission part
1019
- * @see {@link ReferralInteractionEncoder} for more details about the referred interaction
1020
- * @see {@link ModalStepTypes} for more details on each modal steps types
1021
- */
1022
- export declare function processReferral(client: FrakClient, { walletStatus, frakContext, modalConfig, productId, options, }: {
1023
- walletStatus?: WalletStatusReturnType;
1024
- frakContext?: Partial<FrakContext> | null;
1025
- modalConfig?: DisplayEmbeddedWalletParamsType;
1026
- productId?: Hex;
1027
- options?: ProcessReferralOptions;
1028
- }): Promise<ReferralState>;
1029
-
1030
- /**
1031
- * Options for the referral auto-interaction process
1032
- */
1033
- export declare type ProcessReferralOptions = {
1034
- /**
1035
- * If we want to always append the url with the frak context or not
1036
- * @defaultValue false
1037
- */
1038
- alwaysAppendUrl?: boolean;
1039
- };
1040
-
1041
- /**
1042
- * List of the product types per denominator
1043
- */
1044
- declare const productTypes: {
1045
- dapp: number;
1046
- press: number;
1047
- webshop: number;
1048
- retail: number;
1049
- referral: number;
1050
- purchase: number;
1051
- };
1052
-
1053
- /**
1054
- * The keys for each product types
1055
- * @inline
1056
- */
1057
- declare type ProductTypesKey = keyof typeof productTypes;
1058
-
1059
- /**
1060
- * Function used to display a modal
1061
- * @param client - The current Frak Client
1062
- * @param args
1063
- * @param args.productId - The product id to interact with (if not specified will be recomputed from the current domain)
1064
- * @param args.modalConfig - The modal configuration to display if the user is not logged in
1065
- * @param args.options - Some options for the referral interaction
1066
- *
1067
- * @returns A promise with the resulting referral state, or undefined in case of an error
1068
- *
1069
- * @description This function will automatically handle the referral interaction process
1070
- *
1071
- * @see {@link processReferral} for more details on the automatic referral handling process
1072
- * @see {@link ModalStepTypes} for more details on each modal steps types
1073
- */
1074
- export declare function referralInteraction(client: FrakClient, { productId, modalConfig, options, }?: {
1075
- productId?: Hex;
1076
- modalConfig?: DisplayEmbeddedWalletParamsType;
1077
- options?: ProcessReferralOptions;
1078
- }): Promise<("error" | "idle" | "processing" | "success" | "no-wallet" | "no-session" | "no-referrer" | "self-referral") | undefined>;
1079
-
1080
- /**
1081
- * The different states of the referral process
1082
- * @inline
1083
- */
1084
- declare type ReferralState = "idle" | "processing" | "success" | "no-wallet" | "no-session" | "error" | "no-referrer" | "self-referral";
1085
-
1086
- /**
1087
- * Type used for a one shot request function
1088
- * @inline
1089
- */
1090
- declare type RequestFn<TRpcSchema extends RpcSchema> = <TParameters extends ExtractedParametersFromRpc<TRpcSchema> = ExtractedParametersFromRpc<TRpcSchema>, _ReturnType = ExtractedReturnTypeFromRpc<TRpcSchema, TParameters>>(args: TParameters) => Promise<_ReturnType>;
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 rpomise 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 };