@frak-labs/core-sdk 0.0.9 → 0.0.10

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.
package/dist/index.d.cts CHANGED
@@ -4,6 +4,20 @@ import type { Prettify } from 'viem/chains';
4
4
  import type { RpcSchema } from 'viem';
5
5
  import type { SiweMessage } from 'viem/siwe';
6
6
 
7
+ /**
8
+ * Decode a base64url encoded string
9
+ * @param value The value to decode
10
+ * @returns The decoded value
11
+ */
12
+ export declare function base64urlDecode(value: string): Uint8Array;
13
+
14
+ /**
15
+ * Encode a buffer to a base64url encoded string
16
+ * @param buffer The buffer to encode
17
+ * @returns The encoded string
18
+ */
19
+ export declare function base64urlEncode(buffer: Uint8Array): string;
20
+
7
21
  /**
8
22
  * Base props for the iframe
9
23
  * @ignore
@@ -27,7 +41,7 @@ export declare const baseIframeProps: {
27
41
  * Event related to the iframe lifecycle
28
42
  * @ignore
29
43
  */
30
- export declare type ClientLifecycleEvent = CustomCssEvent | RestoreBackupEvent | HearbeatEvent | HandshakeResponse;
44
+ export declare type ClientLifecycleEvent = CustomCssEvent | CustomI18nEvent | RestoreBackupEvent | HearbeatEvent | HandshakeResponse;
31
45
 
32
46
  /** @ignore */
33
47
  export declare class ClientNotFound extends FrakRpcError {
@@ -46,17 +60,21 @@ declare function compress(context?: Partial<FrakContext>): string | undefined;
46
60
  * -> The encoded should contain a HashProtectedData once decoded
47
61
  * @ignore
48
62
  */
49
- export declare type CompressedData = Readonly<{
50
- compressed: string;
51
- compressedHash: string;
52
- }>;
63
+ export declare type CompressedData = Uint8Array;
64
+
65
+ /**
66
+ * Compress json data
67
+ * @param data
68
+ * @ignore
69
+ */
70
+ export declare function compressJson(data: unknown): Uint8Array;
53
71
 
54
72
  /**
55
73
  * Compress json data
56
74
  * @param data
57
75
  * @ignore
58
76
  */
59
- export declare function compressJson(data: unknown): Promise<string>;
77
+ export declare function compressJsonToB64(data: unknown): string;
60
78
 
61
79
  /**
62
80
  * Create the Frak iframe
@@ -92,6 +110,7 @@ export declare function createIFrameFrakClient({ config, iframe, }: {
92
110
 
93
111
  /**
94
112
  * All the currencies available
113
+ * @category Config
95
114
  */
96
115
  export declare type Currency = "eur" | "usd" | "gbp";
97
116
 
@@ -102,6 +121,13 @@ declare type CustomCssEvent = {
102
121
  };
103
122
  };
104
123
 
124
+ declare type CustomI18nEvent = {
125
+ clientLifecycle: "modal-i18n";
126
+ data: {
127
+ i18n: I18nConfig;
128
+ };
129
+ };
130
+
105
131
  /** @ignore */
106
132
  export declare class DebugInfoGatherer {
107
133
  private config?;
@@ -139,14 +165,21 @@ declare function decompress(context?: string): FrakContext | undefined;
139
165
  * @param compressedData The params to encode
140
166
  * @ignore
141
167
  */
142
- export declare function decompressDataAndCheckHash<T>(compressedData: CompressedData): Promise<HashProtectedData<T>>;
168
+ export declare function decompressDataAndCheckHash<T>(compressedData: CompressedData): HashProtectedData<T>;
169
+
170
+ /**
171
+ * Decompress json data
172
+ * @param data
173
+ * @ignore
174
+ */
175
+ export declare function decompressJson<T>(data: Uint8Array): T | null;
143
176
 
144
177
  /**
145
178
  * Decompress json data
146
179
  * @param data
147
180
  * @ignore
148
181
  */
149
- export declare function decompressJson<T>(data: string): Promise<T | null>;
182
+ export declare function decompressJsonFromB64<T>(data: string): T | null;
150
183
 
151
184
  /**
152
185
  * Simple deferred promise wrapper
@@ -163,31 +196,31 @@ export declare class Deferred<T> {
163
196
  }
164
197
 
165
198
  /**
166
- * The params used to display the embeded wallet
199
+ * The params used to display the embedded wallet
167
200
  *
168
- * @group Embeded wallet
201
+ * @group Embedded wallet
169
202
  */
170
203
  export declare type DisplayEmbededWalletParamsType = {
171
204
  /**
172
- * The embeded view to display once the user is logged in
205
+ * The embedded view to display once the user is logged in
173
206
  */
174
207
  loggedIn?: LoggedInEmbededView;
175
208
  /**
176
- * The embeded view to display once the user is logged out
209
+ * The embedded view to display once the user is logged out
177
210
  */
178
211
  loggedOut?: LoggedOutEmbededView;
179
212
  /**
180
- * Some metadata to customise the embeded view
213
+ * Some metadata to customize the embedded view
181
214
  */
182
215
  metadata?: {
183
216
  /**
184
- * The logo to display on the embeded wallet
217
+ * The logo to display on the embedded wallet
185
218
  * If undefined, will default to no logo displayed
186
219
  */
187
220
  logo?: string;
188
221
  /**
189
222
  * Link to the homepage of the calling website
190
- * If unedfined, will default to the domain of the calling website
223
+ * If undefined, will default to the domain of the calling website
191
224
  */
192
225
  homepageLink?: string;
193
226
  /**
@@ -198,6 +231,10 @@ export declare type DisplayEmbededWalletParamsType = {
198
231
  * The position of the component
199
232
  */
200
233
  position?: "left" | "right";
234
+ /**
235
+ * Some i18n override for the displayed modal (i.e. update the displayed text only for this modal)
236
+ */
237
+ i18n?: I18nConfig;
201
238
  };
202
239
  };
203
240
 
@@ -219,9 +256,9 @@ declare type DoBackupEvent = {
219
256
  };
220
257
 
221
258
  /**
222
- * The different type of action we can have on the embeded view (once the user is logged in)
259
+ * The different type of action we can have on the embedded view (once the user is logged in)
223
260
  *
224
- * @group Embeded wallet
261
+ * @group Embedded wallet
225
262
  */
226
263
  export declare type EmbededViewAction = {
227
264
  key: "sharing";
@@ -231,11 +268,13 @@ export declare type EmbededViewAction = {
231
268
  options?: {
232
269
  /**
233
270
  * The title that will be displayed on the system popup once the system sharing window is open
271
+ * @deprecated Use the top level `config.metadata.i18n` instead
234
272
  */
235
273
  popupTitle?: string;
236
274
  /**
237
275
  * The text that will be shared alongside the link.
238
276
  * Can contain the variable {LINK} to specify where the link is placed, otherwise it will be added at the end
277
+ * @deprecated Use the top level `config.metadata.i18n` instead
239
278
  */
240
279
  text?: string;
241
280
  /**
@@ -280,7 +319,13 @@ export declare type ExtractedReturnTypeFromRpc<TRpcSchema extends RpcSchema, TPa
280
319
  export declare type FinalActionType = {
281
320
  key: "sharing";
282
321
  options?: {
322
+ /**
323
+ * @deprecated Use the top level `config.metadata.i18n` instead
324
+ */
283
325
  popupTitle?: string;
326
+ /**
327
+ * @deprecated Use the top level `config.metadata.i18n` instead
328
+ */
284
329
  text?: string;
285
330
  link?: string;
286
331
  };
@@ -319,6 +364,8 @@ export declare type FrakClient = {
319
364
  * The current Frak Context
320
365
  *
321
366
  * For now, only contain a referrer address.
367
+ *
368
+ * @ignore
322
369
  */
323
370
  export declare type FrakContext = {
324
371
  r: Address;
@@ -347,7 +394,8 @@ export declare class FrakRpcError<T = undefined> extends Error {
347
394
  }
348
395
 
349
396
  /**
350
- * Configuration for the Nexus Wallet SDK
397
+ * Configuration for the Frak Wallet SDK
398
+ * @category Config
351
399
  */
352
400
  export declare type FrakWalletSdkConfig = {
353
401
  /**
@@ -363,20 +411,37 @@ export declare type FrakWalletSdkConfig = {
363
411
  * Your application name (will be displayed in a few modals and in SSO)
364
412
  */
365
413
  name: string;
366
- /**
367
- * Custom CSS styles to apply to the modals and components
368
- */
369
- css?: string;
370
414
  /**
371
415
  * Language to display in the modal
372
416
  * If undefined, will default to the browser language
373
417
  */
374
- lang?: "fr" | "en";
418
+ lang?: Language;
375
419
  /**
376
420
  * The currency to display in the modal
377
421
  * @defaultValue `"eur"`
378
422
  */
379
423
  currency?: Currency;
424
+ /**
425
+ * The logo URL that will be displayed in a few components
426
+ */
427
+ logoUrl?: string;
428
+ /**
429
+ * The homepage link that could be displayed in a few components
430
+ */
431
+ homepageLink?: string;
432
+ };
433
+ /**
434
+ * Some customization for the modal
435
+ */
436
+ customizations?: {
437
+ /**
438
+ * Custom CSS styles to apply to the modals and components
439
+ */
440
+ css?: `${string}.css`;
441
+ /**
442
+ * Custom i18n configuration for the modal
443
+ */
444
+ i18n?: I18nConfig;
380
445
  };
381
446
  /**
382
447
  * The domain name of your application
@@ -491,7 +556,7 @@ declare type HandshakeResponse = {
491
556
  * @param data The params to encode
492
557
  * @ignore
493
558
  */
494
- export declare function hashAndCompressData<T>(data: T): Promise<CompressedData>;
559
+ export declare function hashAndCompressData<T>(data: T): CompressedData;
495
560
 
496
561
  /**
497
562
  * The encoded data to send to a client / received by a client
@@ -505,6 +570,41 @@ declare type HearbeatEvent = {
505
570
  clientLifecycle: "heartbeat";
506
571
  };
507
572
 
573
+ /**
574
+ * Custom i18n configuration for the modal
575
+ * See [i18next json format](https://www.i18next.com/misc/json-format#i18next-json-v4)
576
+ *
577
+ * Available variables
578
+ * - `{{ productName }}` : The name of your website (`metadata.name`)
579
+ * - `{{ productOrigin }}` : The origin url of your website
580
+ * - `{{ 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)
581
+ *
582
+ * Context of the translation [see i18n context](https://www.i18next.com/translation-function/context)
583
+ * - For modal display, the key of the final action (`sharing`, `reward`, or undefined)
584
+ * - For embedded wallet display, the key of the logged in action (`sharing` or undefined)
585
+ *
586
+ * @example
587
+ * ```ts
588
+ * // Multi language config
589
+ * const multiI18n = {
590
+ * fr: {
591
+ * "sdk.modal.title": "Titre de modal",
592
+ * "sdk.modal.description": "Description de modal, avec {{ estimatedReward }} de gains possible",
593
+ * },
594
+ * en: "https://example.com/en.json"
595
+ * }
596
+ *
597
+ * // Single language config
598
+ * const singleI18n = {
599
+ * "sdk.modal.title": "Modal title",
600
+ * "sdk.modal.description": "Modal description, with {{ estimatedReward }} of gains possible",
601
+ * }
602
+ * ```
603
+ *
604
+ * @category Config
605
+ */
606
+ export declare type I18nConfig = Record<Language, LocalizedI18nConfig> | LocalizedI18nConfig;
607
+
508
608
  /**
509
609
  * Represent an iframe event
510
610
  */
@@ -525,10 +625,7 @@ export declare type IFrameLifecycleEvent = {
525
625
  export declare type IFrameRpcEvent = {
526
626
  id: string;
527
627
  topic: ExtractedParametersFromRpc<IFrameRpcSchema>["method"];
528
- data: {
529
- compressed: string;
530
- compressedHash: string;
531
- };
628
+ data: CompressedData;
532
629
  };
533
630
 
534
631
  /**
@@ -581,7 +678,8 @@ export declare type IFrameRpcSchema = [
581
678
  Method: "frak_displayModal";
582
679
  Parameters: [
583
680
  requests: ModalRpcStepsInput,
584
- metadata: FrakWalletSdkConfig["metadata"] & ModalRpcMetadata
681
+ metadata: ModalRpcMetadata | undefined,
682
+ configMetadata: FrakWalletSdkConfig["metadata"]
585
683
  ];
586
684
  ReturnType: ModalRpcStepsResultType;
587
685
  },
@@ -622,12 +720,12 @@ export declare type IFrameRpcSchema = [
622
720
  ReturnType: GetProductInformationReturnType;
623
721
  },
624
722
  /**
625
- * Method to show the embeded wallet, with potential customisation
723
+ * Method to show the embedded wallet, with potential customization
626
724
  */
627
725
  {
628
726
  Method: "frak_displayEmbededWallet";
629
727
  Parameters: [
630
- DisplayEmbededWalletParamsType,
728
+ request: DisplayEmbededWalletParamsType,
631
729
  metadata: FrakWalletSdkConfig["metadata"]
632
730
  ];
633
731
  ReturnType: undefined;
@@ -703,6 +801,12 @@ export declare type InteractionTypesKey = {
703
801
  */
704
802
  export declare type KeyProvider<DataType> = (value: DataType) => string[];
705
803
 
804
+ /**
805
+ * All the languages available
806
+ * @category Config
807
+ */
808
+ export declare type Language = "fr" | "en";
809
+
706
810
  /**
707
811
  * Type used for a listening request
708
812
  * @inline
@@ -725,13 +829,21 @@ export declare const locales: {
725
829
  export declare type LocalesKey = keyof typeof locales;
726
830
 
727
831
  /**
728
- * Some configuration options for the embeded view
832
+ * A localized i18n config
833
+ * @category Config
834
+ */
835
+ export declare type LocalizedI18nConfig = `${string}.css` | {
836
+ [key: string]: string;
837
+ };
838
+
839
+ /**
840
+ * Some configuration options for the embedded view
729
841
  *
730
- * @group Embeded wallet
842
+ * @group Embedded wallet
731
843
  */
732
844
  export declare type LoggedInEmbededView = {
733
845
  /**
734
- * The main action to display on the logged in embeded view
846
+ * The main action to display on the logged in embedded view
735
847
  * If none specified, the user will see his wallet with the activation button
736
848
  */
737
849
  action?: EmbededViewAction;
@@ -739,26 +851,28 @@ export declare type LoggedInEmbededView = {
739
851
 
740
852
  /**
741
853
  * The view when a user is logged out
742
- * @group Embeded wallet
854
+ * @group Embedded wallet
743
855
  */
744
856
  export declare type LoggedOutEmbededView = {
745
857
  /**
746
- * Metadata option when displaying the embeded view
858
+ * Metadata option when displaying the embedded view
747
859
  */
748
860
  metadata?: {
749
861
  /**
750
862
  * The main CTA for the logged out view
751
863
  * - can include some variable, available ones are:
752
- * - {REWARD} -> The maximum reward a user can receive when itneracting on your website
864
+ * - {REWARD} -> The maximum reward a user can receive when interacting on your website
753
865
  * - can be formatted in markdown
754
866
  *
755
- * If not sert, it will default to a internalised message
867
+ * If not set, it will default to a internationalized message
868
+ * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
756
869
  */
757
870
  text?: string;
758
871
  /**
759
872
  * The text that will be displayed on the login button
760
873
  *
761
- * If not set, it will default to a internalised message
874
+ * If not set, it will default to a internationalized message
875
+ * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
762
876
  */
763
877
  buttonText?: string;
764
878
  };
@@ -785,7 +899,7 @@ declare type LoginWithoutSso = {
785
899
  /** @inline */
786
900
  declare type LoginWithSso = {
787
901
  allowSso: true;
788
- ssoMetadata: SsoMetadata;
902
+ ssoMetadata?: SsoMetadata;
789
903
  };
790
904
 
791
905
  /**
@@ -798,10 +912,16 @@ export declare type ModalRpcMetadata = {
798
912
  title?: string;
799
913
  icon?: string;
800
914
  };
801
- context?: string;
802
915
  targetInteraction?: FullInteractionTypesKey;
916
+ /**
917
+ * Some i18n override for the displayed modal (i.e. update the displayed text only for this modal)
918
+ */
919
+ i18n?: I18nConfig;
803
920
  } & ({
804
921
  isDismissible: true;
922
+ /**
923
+ * @deprecated Use `config.customizations.i18n` or `metadata.i18n` instead
924
+ */
805
925
  dismissActionTxt?: string;
806
926
  } | {
807
927
  isDismissible?: false;
@@ -835,29 +955,34 @@ export declare type ModalRpcStepsResultType<T extends ModalStepTypes[] = ModalSt
835
955
  };
836
956
 
837
957
  /**
838
- * Metadata that can be used to customise a modal step
958
+ * Metadata that can be used to customize a modal step
839
959
  * @group Modal Display
960
+ * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
840
961
  */
841
962
  export declare type ModalStepMetadata = {
842
963
  metadata?: {
843
964
  /**
844
965
  * Custom title for the step
845
- * If none provided, it will use an internationalised text
966
+ * If none provided, it will use an internationalized text
967
+ * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
846
968
  */
847
969
  title?: string;
848
970
  /**
849
971
  * Custom description for the step
850
- * If none provided, it will use an internationalised text
972
+ * If none provided, it will use an internationalized text
973
+ * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
851
974
  */
852
975
  description?: string;
853
976
  /**
854
977
  * Custom text for the primary action of the step
855
- * If none provided, it will use an internationalised text
978
+ * If none provided, it will use an internationalized text
979
+ * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
856
980
  */
857
981
  primaryActionText?: string;
858
982
  /**
859
983
  * Custom text for the secondary action of the step
860
- * If none provided, it will use an internationalised text
984
+ * If none provided, it will use an internationalized text
985
+ * @deprecated Use the top level `config.customizations.i18n`, or `metadata.i18n` instead
861
986
  */
862
987
  secondaryActionText?: string;
863
988
  };