@frak-labs/nexus-sdk 0.0.10 → 0.0.11

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 (37) hide show
  1. package/dist/chunk-5CFD5FM2.js +86 -0
  2. package/dist/chunk-7MVQQ2X6.js +381 -0
  3. package/dist/{chunk-72IEHEQX.js → chunk-GUDT2W6I.js} +32 -10
  4. package/dist/{chunk-NIFJZD3M.cjs → chunk-IQQTTKJL.cjs} +30 -8
  5. package/dist/chunk-S5FVCA2E.cjs +86 -0
  6. package/dist/chunk-V3S6RBRJ.cjs +381 -0
  7. package/dist/{client-6_BJp7Ub.d.ts → client-C7u9zGwC.d.cts} +135 -142
  8. package/dist/{client--U_6SK0l.d.cts → client-gE3fYzkD.d.ts} +135 -142
  9. package/dist/core/actions/index.cjs +2 -7
  10. package/dist/core/actions/index.d.cts +16 -35
  11. package/dist/core/actions/index.d.ts +16 -35
  12. package/dist/core/actions/index.js +5 -10
  13. package/dist/core/index.cjs +2 -4
  14. package/dist/core/index.d.cts +3 -3
  15. package/dist/core/index.d.ts +3 -3
  16. package/dist/core/index.js +2 -4
  17. package/dist/core/interactions/index.cjs +6 -2
  18. package/dist/core/interactions/index.d.cts +20 -6
  19. package/dist/core/interactions/index.d.ts +20 -6
  20. package/dist/core/interactions/index.js +7 -3
  21. package/dist/{interaction-D_CzyqRE.d.cts → interaction-D3-M3nBh.d.cts} +2 -2
  22. package/dist/{interaction-D_CzyqRE.d.ts → interaction-D3-M3nBh.d.ts} +2 -2
  23. package/dist/react/index.cjs +146 -158
  24. package/dist/react/index.d.cts +44 -51
  25. package/dist/react/index.d.ts +44 -51
  26. package/dist/react/index.js +152 -164
  27. package/dist/sendTransaction-BZW627cT.d.cts +30 -0
  28. package/dist/sendTransaction-DpJTfGJc.d.ts +30 -0
  29. package/package.json +8 -5
  30. package/dist/chunk-3T2FNW6E.cjs +0 -100
  31. package/dist/chunk-BPFJZRJ6.cjs +0 -152
  32. package/dist/chunk-HOX3RRO6.js +0 -199
  33. package/dist/chunk-SGLR6RFA.cjs +0 -199
  34. package/dist/chunk-T54VMWHQ.js +0 -100
  35. package/dist/chunk-TPC5PMRC.js +0 -152
  36. package/dist/watchUnlockStatus-CxnibdQx.d.cts +0 -43
  37. package/dist/watchUnlockStatus-g8wIxpeM.d.ts +0 -43
@@ -1,7 +1,7 @@
1
- import { Hex, Address, RpcSchema } from 'viem';
1
+ import { Address, Hex, RpcSchema } from 'viem';
2
2
  import { Prettify } from 'viem/chains';
3
3
  import { SiweMessage } from 'viem/siwe';
4
- import { P as PreparedInteraction, a as SendInteractionReturnType } from './interaction-D_CzyqRE.js';
4
+ import { P as PreparedInteraction, a as SendInteractionReturnType } from './interaction-D3-M3nBh.cjs';
5
5
 
6
6
  /**
7
7
  * Configuration for the Nexus Wallet SDK
@@ -10,21 +10,70 @@ type NexusWalletSdkConfig = Readonly<{
10
10
  walletUrl: string;
11
11
  metadata: {
12
12
  name: string;
13
+ css?: string;
13
14
  };
14
15
  domain: string;
15
16
  }>;
16
17
 
17
18
  /**
18
- * Parameters of the send transaction rpc request
19
+ * SSO Metadata
19
20
  */
20
- type SiweAuthenticationParams = Omit<SiweMessage, "address" | "chainId">;
21
+ type SsoMetadata = {
22
+ logoUrl: string;
23
+ homepageLink: string;
24
+ links?: {
25
+ confidentialityLink?: string;
26
+ helpLink?: string;
27
+ cguLink?: string;
28
+ };
29
+ };
21
30
  /**
22
- * Same stuff but in an object format for better readability
31
+ * Params to start a SSO
23
32
  */
24
- type SiweAuthenticateActionParamsType = Readonly<{
25
- siwe?: Partial<SiweAuthenticationParams>;
26
- context?: string;
33
+ type OpenSsoParamsType = {
34
+ redirectUrl?: string;
35
+ directExit?: boolean;
36
+ metadata: SsoMetadata;
37
+ };
38
+
39
+ /**
40
+ * Represent a generic modal step type
41
+ */
42
+ type GenericModalStepType<TKey, TParams, TReturns> = {
43
+ key: TKey;
44
+ params: TParams extends never ? ModalStepMetadata : ModalStepMetadata & TParams;
45
+ returns: TReturns;
46
+ };
47
+ type ModalStepMetadata = {
48
+ metadata?: {
49
+ title?: string;
50
+ description?: string;
51
+ primaryActionText?: string;
52
+ secondaryActionText?: string;
53
+ };
54
+ };
55
+
56
+ type LoginWithSso = {
57
+ allowSso: true;
58
+ ssoMetadata: SsoMetadata;
59
+ };
60
+ type LoginWithoutSso = {
61
+ allowSso?: false;
62
+ ssoMetadata?: never;
63
+ };
64
+ /**
65
+ * Generic type of modal we will display to the end user
66
+ */
67
+ type LoginModalStepType = GenericModalStepType<"login", {
68
+ articleUrl?: string;
69
+ } & (LoginWithSso | LoginWithoutSso), {
70
+ wallet: Address;
27
71
  }>;
72
+
73
+ /**
74
+ * Parameters of the send transaction rpc request
75
+ */
76
+ type SiweAuthenticationParams = Omit<SiweMessage, "address" | "chainId">;
28
77
  /**
29
78
  * Return type of the send transaction rpc request
30
79
  */
@@ -32,25 +81,21 @@ type SiweAuthenticateReturnType = Readonly<{
32
81
  signature: Hex;
33
82
  message: string;
34
83
  }>;
35
-
36
84
  /**
37
- * Parameters of the send transaction rpc request
85
+ * Generic type of modal we will display to the end user
38
86
  */
39
- type SendTransactionRpcParamsType = [
40
- tx: SendTransactionTxType | SendTransactionTxType[],
41
- context?: string
42
- ];
87
+ type SiweAuthenticateModalStepType = GenericModalStepType<"siweAuthenticate", {
88
+ siwe: SiweAuthenticationParams;
89
+ }, SiweAuthenticateReturnType>;
90
+
43
91
  /**
44
- * Same stuff but in an object format for better readability
92
+ * Generic format representing a tx to be sent
93
+ * todo: exploit the EIP-5792 here? https://eips.ethereum.org/EIPS/eip-5792
45
94
  */
46
- type SendTransactionActionParamsType = Readonly<{
47
- tx: SendTransactionTxType | SendTransactionTxType[];
48
- context?: string;
49
- }>;
50
95
  type SendTransactionTxType = Readonly<{
51
96
  to: Address;
52
- data: Hex;
53
- value: Hex;
97
+ data?: Hex;
98
+ value?: Hex;
54
99
  }>;
55
100
  /**
56
101
  * Return type of the send transaction rpc request
@@ -58,114 +103,79 @@ type SendTransactionTxType = Readonly<{
58
103
  type SendTransactionReturnType = Readonly<{
59
104
  hash: Hex;
60
105
  }>;
61
-
62
- type PaidArticleUnlockPrice = Readonly<{
63
- index: number;
64
- unlockDurationInSec: number;
65
- frkAmount: Hex;
66
- }>;
106
+ type SendTransactionModalStepType = GenericModalStepType<"sendTransaction", {
107
+ tx: SendTransactionTxType | SendTransactionTxType[];
108
+ }, SendTransactionReturnType>;
67
109
 
68
110
  /**
69
- * Request to unlock a paid article
111
+ * Return type of the send transaction rpc request
70
112
  */
71
- type StartArticleUnlockParams = Readonly<{
72
- articleId: Hex;
73
- contentId: Hex;
74
- imageUrl: string;
75
- articleTitle: string;
76
- contentTitle: string;
77
- price: PaidArticleUnlockPrice;
78
- articleUrl: string;
79
- redirectUrl: string;
80
- previewUrl?: string;
81
- provider: "le-monde" | "wired" | "l-equipe";
113
+ type OpenInteractionSessionReturnType = Readonly<{
114
+ startTimestamp: number;
115
+ endTimestamp: number;
82
116
  }>;
83
117
  /**
84
- * Return type of the unlock request
118
+ * Generic type of modal we will display to the end user
85
119
  */
86
- type StartArticleUnlockReturnType = UnlockSuccess | AlreadyUnlocked | UnlockError;
87
- type UnlockSuccess = {
88
- key: "success";
89
- status: "in-progress";
90
- user: Address;
91
- userOpHash: Hex;
92
- };
93
- type AlreadyUnlocked = {
94
- key: "already-unlocked";
95
- status: "unlocked";
96
- user: Address;
97
- };
98
- type UnlockError = {
99
- key: "error" | "cancelled";
100
- status: "locked";
101
- user?: Address;
102
- reason?: string;
103
- };
120
+ type OpenInteractionSessionModalStepType = GenericModalStepType<"openSession", object, OpenInteractionSessionReturnType>;
104
121
 
105
122
  /**
106
- * The response to the get unlock options response
123
+ * Generic type of modal we will display to the end user
107
124
  */
108
- type UnlockOptionsReturnType = Readonly<{
109
- frkBalanceAsHex?: Hex;
110
- prices: {
111
- index: number;
112
- unlockDurationInSec: number;
113
- frkAmount: Hex;
114
- isUserAccessible: boolean | null;
115
- }[];
116
- }>;
125
+ type SuccessModalStepType = GenericModalStepType<"success", {
126
+ sharing?: {
127
+ popupTitle?: string;
128
+ text?: string;
129
+ link?: string;
130
+ };
131
+ }, object>;
117
132
 
118
133
  /**
119
- * The different types of response for the current unlock status
134
+ * Generic type of steps we will display in the modal to the end user
120
135
  */
121
- type ArticleUnlockStatusReturnType = Readonly<UnlockStatusLocked | UnlockStatusProcessing | UnlockStatusValid | UnlockStatusError>;
136
+ type ModalStepTypes = LoginModalStepType | SiweAuthenticateModalStepType | SendTransactionModalStepType | OpenInteractionSessionModalStepType | SuccessModalStepType;
122
137
  /**
123
- * When the content unlocked was expired or not unlocked
138
+ * Type for the result of a modal request
124
139
  */
125
- type UnlockStatusLocked = {
126
- key: "expired";
127
- status: "locked";
128
- expiredAt: number;
129
- } | {
130
- key: "not-unlocked";
131
- status: "locked";
140
+ type ModalRpcStepsResultType<T extends ModalStepTypes[] = ModalStepTypes[]> = {
141
+ [K in T[number]["key"]]: Extract<T[number], {
142
+ key: K;
143
+ }>["returns"];
132
144
  };
133
145
  /**
134
- * When the content unlock is in progress
146
+ * Type for the RPC input of a modal
135
147
  */
136
- type UnlockStatusProcessing = {
137
- status: "in-progress";
138
- } & ({
139
- key: "preparing" | "waiting-user-validation";
140
- } | {
141
- key: "waiting-transaction-bundling";
142
- userOpHash: Hex;
143
- } | {
144
- key: "waiting-transaction-confirmation";
145
- userOpHash: Hex;
146
- txHash: Hex;
147
- });
148
+ type ModalRpcStepsInput<T extends ModalStepTypes[] = ModalStepTypes[]> = {
149
+ [K in T[number]["key"]]?: Extract<T[number], {
150
+ key: K;
151
+ }>["params"];
152
+ };
148
153
  /**
149
- * When the content is unlocked
154
+ * RPC metadata for the modal
150
155
  */
151
- type UnlockStatusValid = {
152
- key: "valid";
153
- status: "unlocked";
154
- allowedUntil: number;
155
- };
156
+ type ModalRpcMetadata = Readonly<{
157
+ header?: {
158
+ title?: string;
159
+ icon?: string;
160
+ };
161
+ context?: string;
162
+ }>;
156
163
  /**
157
- * When the unlock content is in error
164
+ * Generic params used to display modals
158
165
  */
159
- type UnlockStatusError = {
160
- key: "error";
161
- status: "locked";
162
- reason: string;
166
+ type DisplayModalParamsType<T extends ModalStepTypes[]> = {
167
+ steps: ModalRpcStepsInput<T>;
168
+ metadata?: ModalRpcMetadata;
163
169
  };
164
170
 
165
171
  type WalletStatusReturnType = Readonly<WalletConnected | WalletNotConnected>;
166
172
  type WalletConnected = {
167
173
  key: "connected";
168
174
  wallet: Address;
175
+ interactionSession?: {
176
+ startTimestamp: number;
177
+ endTimestamp: number;
178
+ };
169
179
  };
170
180
  type WalletNotConnected = {
171
181
  key: "not-connected";
@@ -175,14 +185,6 @@ type WalletNotConnected = {
175
185
  * RPC interface that's used for the iframe communication
176
186
  */
177
187
  type IFrameRpcSchema = [
178
- /**
179
- * Method used to fetch an article unlock options
180
- */
181
- {
182
- Method: "frak_getArticleUnlockOptions";
183
- Parameters: [contentId: Hex, articleId: Hex];
184
- ReturnType: UnlockOptionsReturnType;
185
- },
186
188
  /**
187
189
  * Method used to listen to the wallet status
188
190
  */
@@ -192,28 +194,16 @@ type IFrameRpcSchema = [
192
194
  ReturnType: WalletStatusReturnType;
193
195
  },
194
196
  /**
195
- * Method used to listen to an article unlock status
196
- */
197
- {
198
- Method: "frak_listenToArticleUnlockStatus";
199
- Parameters: [contentId: Hex, articleId: Hex];
200
- ReturnType: ArticleUnlockStatusReturnType;
201
- },
202
- /**
203
- * Method to ask the user to send a transaction
204
- */
205
- {
206
- Method: "frak_sendTransaction";
207
- Parameters: SendTransactionRpcParamsType;
208
- ReturnType: SendTransactionReturnType;
209
- },
210
- /**
211
- * Method to ask the user for a strong authentication
197
+ * Method to transmit a user interaction
212
198
  */
213
199
  {
214
- Method: "frak_siweAuthenticate";
215
- Parameters: [request: SiweAuthenticationParams, context?: string];
216
- ReturnType: SiweAuthenticateReturnType;
200
+ Method: "frak_displayModal";
201
+ Parameters: [
202
+ requests: ModalRpcStepsInput,
203
+ name: string,
204
+ metadata?: ModalRpcMetadata
205
+ ];
206
+ ReturnType: ModalRpcStepsResultType;
217
207
  },
218
208
  /**
219
209
  * Method to transmit a user interaction
@@ -226,20 +216,18 @@ type IFrameRpcSchema = [
226
216
  signature?: Hex
227
217
  ];
228
218
  ReturnType: SendInteractionReturnType;
229
- }
230
- ];
231
- /**
232
- * RPC interface that's used for the redirection communication
233
- */
234
- type RedirectRpcSchema = [
219
+ },
235
220
  /**
236
- * Method used to start the unlock of an article
221
+ * Method to start a SSO
237
222
  */
238
223
  {
239
- Method: "frak_startArticleUnlock";
240
- Path: "/paywall";
241
- Parameters: StartArticleUnlockParams;
242
- ReturnType: StartArticleUnlockReturnType;
224
+ Method: "frak_sso";
225
+ Parameters: [
226
+ params: OpenSsoParamsType,
227
+ name: string,
228
+ customCss?: string
229
+ ];
230
+ ReturnType: undefined;
243
231
  }
244
232
  ];
245
233
 
@@ -327,6 +315,11 @@ type IFrameRpcEvent = {
327
315
  };
328
316
  type IFrameLifecycleEvent = {
329
317
  lifecycle: "connected" | "show" | "hide";
318
+ data: never;
319
+ } | LifecycleEventCSS;
320
+ type LifecycleEventCSS = {
321
+ lifecycle: "modal-css";
322
+ data: string;
330
323
  };
331
324
 
332
325
  /**
@@ -336,4 +329,4 @@ type NexusClient = {
336
329
  config: NexusWalletSdkConfig;
337
330
  } & IFrameTransport;
338
331
 
339
- export type { ArticleUnlockStatusReturnType as A, ExtractedParametersFromRpc as E, IFrameRpcSchema as I, NexusClient as N, PaidArticleUnlockPrice as P, RedirectRpcSchema as R, StartArticleUnlockParams as S, UnlockOptionsReturnType as U, WalletStatusReturnType as W, NexusWalletSdkConfig as a, StartArticleUnlockReturnType as b, SendTransactionActionParamsType as c, SendTransactionReturnType as d, SendTransactionTxType as e, SiweAuthenticateReturnType as f, SiweAuthenticateActionParamsType as g, SiweAuthenticationParams as h, RpcResponse as i, IFrameTransport as j, IFrameRpcEvent as k, IFrameEvent as l, ExtractedReturnTypeFromRpc as m };
332
+ export type { DisplayModalParamsType as D, ExtractedParametersFromRpc as E, IFrameRpcSchema as I, LoginModalStepType as L, ModalRpcMetadata as M, NexusClient as N, OpenSsoParamsType as O, RpcResponse as R, SiweAuthenticationParams as S, WalletStatusReturnType as W, SiweAuthenticateReturnType as a, SendTransactionModalStepType as b, SendTransactionReturnType as c, ModalStepTypes as d, ModalRpcStepsResultType as e, NexusWalletSdkConfig as f, SuccessModalStepType as g, SsoMetadata as h, ModalRpcStepsInput as i, ModalStepMetadata as j, SiweAuthenticateModalStepType as k, SendTransactionTxType as l, OpenInteractionSessionReturnType as m, OpenInteractionSessionModalStepType as n, IFrameTransport as o, IFrameRpcEvent as p, IFrameEvent as q, ExtractedReturnTypeFromRpc as r };