@frak-labs/core-sdk 0.0.7 → 0.0.8

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.
@@ -1,501 +0,0 @@
1
- import { a as FrakClient, W as WalletStatusReturnType, M as ModalStepTypes, j as DisplayModalParamsType, l as ModalRpcStepsResultType, D as DisplayEmbededWalletParamsType, O as OpenSsoParamsType, G as GetProductInformationReturnType, q as SiweAuthenticationParams, h as ModalRpcMetadata, r as SiweAuthenticateReturnType, t as SendTransactionModalStepType, u as SendTransactionReturnType, n as LoginModalStepType, w as OpenInteractionSessionModalStepType, x as FinalModalStepType, y as FinalActionType, b as FrakContext } from '../context-rDsQbSgB.js';
2
- import { S as SendInteractionParamsType, a as SendInteractionReturnType } from '../interaction-CTQ5-kqe.js';
3
- import { Hex } from 'viem';
4
- import 'viem/chains';
5
- import 'viem/siwe';
6
-
7
- /**
8
- * Function used to watch the current frak wallet status
9
- * @param client - The current Frak Client
10
- * @param callback - The callback that will receive any wallet status change
11
- * @returns A rpomise resolving with the initial wallet status
12
- *
13
- * @description This function will return the current wallet status, and will listen to any change in the wallet status.
14
- *
15
- * @example
16
- * await watchWalletStatus(frakConfig, (status: WalletStatusReturnType) => {
17
- * if (status.key === "connected") {
18
- * console.log("Wallet connected:", status.wallet);
19
- * console.log("Current interaction session:", status.interactionSession);
20
- * } else {
21
- * console.log("Wallet not connected");
22
- * }
23
- * });
24
- */
25
- declare function watchWalletStatus(client: FrakClient, callback?: (status: WalletStatusReturnType) => void): Promise<WalletStatusReturnType>;
26
-
27
- /**
28
- * Function used to send an interaction
29
- * @param client - The current Frak Client
30
- * @param args
31
- *
32
- * @example
33
- * const interaction = PressInteractionEncoder.openArticle({
34
- * articleId: keccak256(toHex("article-slug")),
35
- * });
36
- * const { delegationId } = await sendInteraction(frakConfig, {
37
- * interaction,
38
- * });
39
- * console.log("Delegated interaction id", delegationId);
40
- */
41
- declare function sendInteraction(client: FrakClient, { productId, interaction, validation }: SendInteractionParamsType): Promise<SendInteractionReturnType>;
42
-
43
- /**
44
- * Function used to display a modal
45
- * @param client - The current Frak Client
46
- * @param args
47
- * @param args.steps - The different steps of the modal
48
- * @param args.metadata - The metadata for the modal (customisation, language etc)
49
- * @returns The result of each modal steps
50
- *
51
- * @description This function will display a modal to the user with the provided steps and metadata.
52
- *
53
- * @remarks
54
- * - The UI of the displayed modal can be configured with the `customCss` property in the `metadata.css` field of the top-level config.
55
- * - 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.
56
- * - Steps are automatically reordered in the following sequence:
57
- * 1. `login` (if needed)
58
- * 2. `openSession` (if needed)
59
- * 3. All other steps in the order specified
60
- * 4. `success` (if included, always last)
61
- *
62
- * @example
63
- * Simple sharing modal with steps:
64
- * 1. Login (Skipped if already logged in)
65
- * 2. Open a session (Skipped if already opened)
66
- * 3. Display a success message with sharing link option
67
- *
68
- * ```ts
69
- * const results = await displayModal(frakConfig, {
70
- * steps: {
71
- * // Simple login with no SSO, nor customisation
72
- * login: { allowSso: false },
73
- * // Simple session opening, with no customisation
74
- * openSession: {},
75
- * // Success message
76
- * final: {
77
- * action: { key: "reward" },
78
- * // Skip this step, it will be only displayed in the stepper within the modal
79
- * autoSkip: true,
80
- * },
81
- * },
82
- * });
83
- *
84
- * console.log("Login step - wallet", results.login.wallet);
85
- * console.log("Open session step - start + end", {
86
- * start: results.openSession.startTimestamp,
87
- * end: results.openSession.endTimestamp,
88
- * });
89
- * ```
90
- *
91
- * @example
92
- * A full modal example, with a few customisation options, with the steps:
93
- * 1. Login (Skipped if already logged in)
94
- * 2. Open a session (Skipped if already opened)
95
- * 3. Authenticate via SIWE
96
- * 4. Send a transaction
97
- * 5. Display a success message with sharing link options
98
- *
99
- * ```ts
100
- * const results = await displayModal(frakConfig, {
101
- * steps: {
102
- * // Login step
103
- * login: {
104
- * allowSso: true,
105
- * ssoMetadata: {
106
- * logoUrl: "https://my-app.com/logo.png",
107
- * homepageLink: "https://my-app.com",
108
- * },
109
- * metadata: {
110
- * // Modal title on desktop
111
- * title: "Login on My-App",
112
- * // Modal description (and yep it accept markdown)
113
- * description: "## Please login to continue",
114
- * // Primary button text
115
- * primaryActionText: "Register",
116
- * // Secondary button text
117
- * secondaryActionText: "Login",
118
- * },
119
- * },
120
- * // Simple session opening, with no customisation
121
- * openSession: {},
122
- * // Siwe authentication
123
- * siweAuthenticate: {
124
- * siwe: {
125
- * domain: "my-app.com",
126
- * uri: "https://my-app.com/",
127
- * nonce: generateSiweNonce(),
128
- * version: "1",
129
- * },
130
- * metadata: {
131
- * title: "Authenticate with SIWE",
132
- * description: "Please authenticate with SIWE to continue",
133
- * primaryActionText: "Authenticate",
134
- * },
135
- * },
136
- * // Send batched transaction
137
- * sendTransaction: {
138
- * tx: [
139
- * { to: "0xdeadbeef", data: "0xdeadbeef" },
140
- * { to: "0xdeadbeef", data: "0xdeadbeef" },
141
- * ],
142
- * metadata: {
143
- * title: "Send a transaction",
144
- * description: "Please send a transaction to continue",
145
- * },
146
- * },
147
- * // Success message with sharing options
148
- * final: {
149
- * action: {
150
- * key: "sharing",
151
- * options: {
152
- * popupTitle: "Share the app",
153
- * text: "Discover my super app website",
154
- * link: "https://my-app.com",
155
- * },
156
- * },
157
- * dismissedMetadata: {
158
- * title: "Dismiss",
159
- * description: "You won't be rewarded for this sharing action",
160
- * },
161
- * },
162
- * },
163
- * metadata: {
164
- * // Header of desktop modals
165
- * header: {
166
- * title: "My-App",
167
- * icon: "https://my-app.com/logo.png",
168
- * },
169
- * // Context that will be present in every modal steps
170
- * context: "My-app overkill flow",
171
- * // Language of the modal
172
- * lang: "fr",
173
- * },
174
- * });
175
- * ```
176
- */
177
- declare function displayModal<T extends ModalStepTypes[] = ModalStepTypes[]>(client: FrakClient, { steps, metadata }: DisplayModalParamsType<T>): Promise<ModalRpcStepsResultType<T>>;
178
-
179
- /**
180
- * Function used to display the Frak embeded wallet popup
181
- * @param client - The current Frak Client
182
- * @param params - The parameter used to customise the embeded wallet
183
- */
184
- declare function displayEmbededWallet(client: FrakClient, params: DisplayEmbededWalletParamsType): Promise<void>;
185
-
186
- /**
187
- * Function used to open the SSO
188
- * @param client - The current Frak Client
189
- * @param args - The SSO parameters
190
- *
191
- * @description This function will open the SSO with the provided parameters.
192
- *
193
- * @example
194
- * First we build the sso metadata
195
- * ```ts
196
- * // Build the metadata
197
- * const metadata: SsoMetadata = {
198
- * logoUrl: "https://my-app.com/logo.png",
199
- * homepageLink: "https://my-app.com",
200
- * };
201
- * ```
202
- *
203
- * Then, either use it with direct exit (and so user is directly redirected to your website), or a custom redirect URL
204
- * :::code-group
205
- * ```ts [Direct exit]
206
- * // Trigger an sso opening with redirection
207
- * await openSso(frakConfig, {
208
- * directExit: true,
209
- * metadata,
210
- * });
211
- * ```
212
- * ```ts [Redirection]
213
- * // Trigger an sso opening within a popup with direct exit
214
- * await openSso(frakConfig, {
215
- * redirectUrl: "https://my-app.com/nexus-sso",
216
- * metadata,
217
- * });
218
- * ```
219
- * :::
220
- */
221
- declare function openSso(client: FrakClient, args: OpenSsoParamsType): Promise<void>;
222
-
223
- /**
224
- * Function used to get the current product information
225
- * @param client - The current Frak Client
226
- * @returns The product information in a promise
227
- */
228
- declare function getProductInformation(client: FrakClient): Promise<GetProductInformationReturnType>;
229
-
230
- /**
231
- * Function used to track the status of a purchase
232
- * when a purchase is tracked, the `purchaseCompleted` interactions will be automatically send for the user when we receive the purchase confirmation via webhook.
233
- *
234
- * @param args.customerId - The customer id that made the purchase (on your side)
235
- * @param args.orderId - The order id of the purchase (on your side)
236
- * @param args.token - The token of the purchase
237
- *
238
- * @description This function will send a request to the backend to listen for the purchase status.
239
- *
240
- * @example
241
- * async function trackPurchase(checkout) {
242
- * const payload = {
243
- * customerId: checkout.order.customer.id,
244
- * orderId: checkout.order.id,
245
- * token: checkout.token,
246
- * };
247
- *
248
- * await trackPurchaseStatus(payload);
249
- * }
250
- *
251
- * @remarks
252
- * - The `trackPurchaseStatus` function requires the `frak-wallet-interaction-token` stored in the session storage to authenticate the request.
253
- * - This function will print a warning if used in a non-browser environment or if the wallet interaction token is not available.
254
- */
255
- declare function trackPurchaseStatus(args: {
256
- customerId: string | number;
257
- orderId: string | number;
258
- token: string;
259
- }): Promise<void>;
260
-
261
- /**
262
- * Parameter used to directly show a modal used to authenticate with SIWE
263
- * @inline
264
- */
265
- type SiweAuthenticateModalParams = {
266
- /**
267
- * Partial SIWE params, since we can rebuild them from the SDK if they are empty
268
- *
269
- * If no parameters provider, some fields will be recomputed from the current configuration and environment.
270
- * - `statement` will be set to a default value
271
- * - `nonce` will be generated
272
- * - `uri` will be set to the current domain
273
- * - `version` will be set to "1"
274
- * - `domain` will be set to the current window domain
275
- *
276
- * @default {}
277
- */
278
- siwe?: Partial<SiweAuthenticationParams>;
279
- /**
280
- * Custom metadata to be passed to the modal
281
- */
282
- metadata?: ModalRpcMetadata;
283
- };
284
- /**
285
- * Function used to launch a siwe authentication
286
- * @param client - The current Frak Client
287
- * @param args - The parameters
288
- * @returns The SIWE authentication result (message + signature) in a promise
289
- *
290
- * @description This function will display a modal to the user with the provided SIWE parameters and metadata.
291
- *
292
- * @example
293
- * import { siweAuthenticate } from "@frak-labs/core-sdk/actions";
294
- * import { parseSiweMessage } from "viem/siwe";
295
- *
296
- * const { signature, message } = await siweAuthenticate(frakConfig, {
297
- * siwe: {
298
- * statement: "Sign in to My App",
299
- * domain: "my-app.com",
300
- * expirationTimeTimestamp: Date.now() + 1000 * 60 * 5,
301
- * },
302
- * metadata: {
303
- * header: {
304
- * title: "Sign in",
305
- * },
306
- * context: "Sign in to My App",
307
- * },
308
- * });
309
- * console.log("Parsed final message:", parseSiweMessage(message));
310
- * console.log("Siwe signature:", signature);
311
- */
312
- declare function siweAuthenticate(client: FrakClient, { siwe, metadata }: SiweAuthenticateModalParams): Promise<SiweAuthenticateReturnType>;
313
-
314
- /**
315
- * Parameters to directly show a modal used to send a transaction
316
- * @inline
317
- */
318
- type SendTransactionParams = {
319
- /**
320
- * The transaction to be sent (either a single tx or multiple ones)
321
- */
322
- tx: SendTransactionModalStepType["params"]["tx"];
323
- /**
324
- * Custom metadata to be passed to the modal
325
- */
326
- metadata?: ModalRpcMetadata;
327
- };
328
- /**
329
- * Function used to send a user transaction, simple wrapper around the displayModal function to ease the send transaction process
330
- * @param client - The current Frak Client
331
- * @param args - The parameters
332
- * @returns The hash of the transaction that was sent in a promise
333
- *
334
- * @description This function will display a modal to the user with the provided transaction and metadata.
335
- *
336
- * @example
337
- * const { hash } = await sendTransaction(frakConfig, {
338
- * tx: {
339
- * to: "0xdeadbeef",
340
- * value: toHex(100n),
341
- * },
342
- * metadata: {
343
- * header: {
344
- * title: "Sending eth",
345
- * },
346
- * context: "Send 100wei to 0xdeadbeef",
347
- * },
348
- * });
349
- * console.log("Transaction hash:", hash);
350
- */
351
- declare function sendTransaction(client: FrakClient, { tx, metadata }: SendTransactionParams): Promise<SendTransactionReturnType>;
352
-
353
- /**
354
- * Represent the type of the modal step builder
355
- */
356
- type ModalStepBuilder<Steps extends ModalStepTypes[] = ModalStepTypes[]> = {
357
- /**
358
- * The current modal params
359
- */
360
- params: DisplayModalParamsType<Steps>;
361
- /**
362
- * Add a send transaction step to the modal
363
- */
364
- sendTx: (options: SendTransactionModalStepType["params"]) => ModalStepBuilder<[...Steps, SendTransactionModalStepType]>;
365
- /**
366
- * Add a final step of type reward to the modal
367
- */
368
- reward: (options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
369
- /**
370
- * Add a final step of type sharing to the modal
371
- */
372
- sharing: (sharingOptions?: Extract<FinalActionType, {
373
- key: "sharing";
374
- }>["options"], options?: Omit<FinalModalStepType["params"], "action">) => ModalStepBuilder<[...Steps, FinalModalStepType]>;
375
- /**
376
- * Display the modal
377
- * @param metadataOverride - Function returning optional metadata to override the current modal metadata
378
- */
379
- display: (metadataOverride?: (current?: ModalRpcMetadata) => ModalRpcMetadata | undefined) => Promise<ModalRpcStepsResultType<Steps>>;
380
- };
381
- /**
382
- * Represent the output type of the modal builder
383
- */
384
- type ModalBuilder = ModalStepBuilder<[
385
- LoginModalStepType,
386
- OpenInteractionSessionModalStepType
387
- ]>;
388
- /**
389
- * Helper to craft Frak modal, and share a base initial config
390
- * @param client - The current Frak Client
391
- * @param args
392
- * @param args.metadata - Common modal metadata (customisation, language etc)
393
- * @param args.login - Login step parameters
394
- * @param args.openSession - Open session step parameters
395
- *
396
- * @description This function will create a modal builder with the provided metadata, login and open session parameters.
397
- *
398
- * @example
399
- * Here is an example of how to use the `modalBuilder` to create and display a sharing modal:
400
- *
401
- * ```js
402
- * // Create the modal builder
403
- * const modalBuilder = window.FrakSDK.modalBuilder(frakClient, baseModalConfig);
404
- *
405
- * // Configure the information to be shared via the sharing link
406
- * const sharingConfig = {
407
- * popupTitle: "Share this with your friends",
408
- * text: "Discover our product!",
409
- * link: window.location.href,
410
- * };
411
- *
412
- * // Display the sharing modal
413
- * function modalShare() {
414
- * modalBuilder.sharing(sharingConfig).display();
415
- * }
416
- * ```
417
- *
418
- * @see {@link ModalStepTypes} for more info about each modal step types and their parameters
419
- * @see {@link ModalRpcMetadata} for more info about the metadata that can be passed to the modal
420
- * @see {@link ModalRpcStepsResultType} for more info about the result of each modal steps
421
- * @see {@link displayModal} for more info about how the modal is displayed
422
- */
423
- declare function modalBuilder(client: FrakClient, { metadata, login, openSession, }: {
424
- metadata?: ModalRpcMetadata;
425
- login?: LoginModalStepType["params"];
426
- openSession?: OpenInteractionSessionModalStepType["params"];
427
- }): ModalBuilder;
428
-
429
- /**
430
- * The different states of the referral process
431
- * @inline
432
- */
433
- type ReferralState = "idle" | "processing" | "success" | "no-wallet" | "no-session" | "error" | "no-referrer" | "self-referral";
434
- /**
435
- * Options for the referral auto-interaction process
436
- */
437
- type ProcessReferralOptions = {
438
- /**
439
- * If we want to always append the url with the frak context or not
440
- * @defaultValue false
441
- */
442
- alwaysAppendUrl?: boolean;
443
- };
444
- /**
445
- * This function handle all the heavy lifting of the referral interaction process
446
- * 1. Check if the user has been referred or not (if not, early exit)
447
- * 2. Then check if the user is logged in or not
448
- * 2.1 If not logged in, try a soft login, if it fail, display a modal for the user to login
449
- * 3. Check if that's not a self-referral (if yes, early exit)
450
- * 4. Check if the user has an interaction session or not
451
- * 4.1 If not, display a modal for the user to open a session
452
- * 5. Push the referred interaction
453
- * 6. Update the current url with the right data
454
- * 7. Return the resulting referral state
455
- *
456
- * If any error occurs during the process, the function will catch it and return an error state
457
- *
458
- * @param client - The current Frak Client
459
- * @param args
460
- * @param args.walletStatus - The current user wallet status
461
- * @param args.frakContext - The current frak context
462
- * @param args.modalConfig - The modal configuration to display if the user is not logged in
463
- * @param args.productId - The product id to interact with (if not specified will be recomputed from the current domain)
464
- * @param args.options - Some options for the referral interaction
465
- * @returns A promise with the resulting referral state
466
- *
467
- * @see {@link displayModal} for more details about the displayed modal
468
- * @see {@link sendInteraction} for more details on the interaction submission part
469
- * @see {@link ReferralInteractionEncoder} for more details about the referred interaction
470
- * @see {@link ModalStepTypes} for more details on each modal steps types
471
- */
472
- declare function processReferral(client: FrakClient, { walletStatus, frakContext, modalConfig, productId, options, }: {
473
- walletStatus?: WalletStatusReturnType;
474
- frakContext?: Partial<FrakContext> | null;
475
- modalConfig?: DisplayModalParamsType<ModalStepTypes[]>;
476
- productId?: Hex;
477
- options?: ProcessReferralOptions;
478
- }): Promise<ReferralState>;
479
-
480
- /**
481
- * Function used to display a modal
482
- * @param client - The current Frak Client
483
- * @param args
484
- * @param args.productId - The product id to interact with (if not specified will be recomputed from the current domain)
485
- * @param args.modalConfig - The modal configuration to display if the user is not logged in
486
- * @param args.options - Some options for the referral interaction
487
- *
488
- * @returns A promise with the resulting referral state, or undefined in case of an error
489
- *
490
- * @description This function will automatically handle the referral interaction process
491
- *
492
- * @see {@link processReferral} for more details on the automatic referral handling process
493
- * @see {@link ModalStepTypes} for more details on each modal steps types
494
- */
495
- declare function referralInteraction(client: FrakClient, { productId, modalConfig, options, }?: {
496
- productId?: Hex;
497
- modalConfig?: DisplayModalParamsType<ModalStepTypes[]>;
498
- options?: ProcessReferralOptions;
499
- }): Promise<("error" | "idle" | "processing" | "success" | "no-wallet" | "no-session" | "no-referrer" | "self-referral") | undefined>;
500
-
501
- export { type ModalBuilder, type ModalStepBuilder, type ProcessReferralOptions, type SendTransactionParams, type SiweAuthenticateModalParams, displayEmbededWallet, displayModal, getProductInformation, modalBuilder, openSso, processReferral, referralInteraction, sendInteraction, sendTransaction, siweAuthenticate, trackPurchaseStatus, watchWalletStatus };