@frak-labs/nexus-sdk 0.0.14 → 0.0.15

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 (49) hide show
  1. package/README.md +4 -4
  2. package/dist/NexusContext-CSlCNW-G.d.cts +10 -0
  3. package/dist/NexusContext-CSlCNW-G.d.ts +10 -0
  4. package/dist/bundle/bundle.js +21 -0
  5. package/dist/chunk-2LAGZ6S5.js +246 -0
  6. package/dist/chunk-4ADWI2GG.cjs +243 -0
  7. package/dist/chunk-4LT3U3H4.cjs +246 -0
  8. package/dist/{chunk-5LZQXBFJ.js → chunk-ARQTOP44.js} +12 -196
  9. package/dist/chunk-C25NTD45.cjs +100 -0
  10. package/dist/chunk-DILTMQBI.cjs +51 -0
  11. package/dist/{chunk-IH3QWPWT.js → chunk-I47XQDS3.js} +44 -16
  12. package/dist/chunk-K4FOGADW.js +51 -0
  13. package/dist/chunk-KEATMEOW.cjs +207 -0
  14. package/dist/chunk-VMNURFPI.js +207 -0
  15. package/dist/{client-DJd7-ajw.d.ts → client-B3Guoe3I.d.ts} +7 -4
  16. package/dist/{client-DXITs1Kf.d.cts → client-Of9uIxuI.d.cts} +7 -4
  17. package/dist/core/actions/index.cjs +11 -3
  18. package/dist/core/actions/index.d.cts +28 -4
  19. package/dist/core/actions/index.d.ts +28 -4
  20. package/dist/core/actions/index.js +10 -2
  21. package/dist/core/index.cjs +9 -4
  22. package/dist/core/index.d.cts +66 -4
  23. package/dist/core/index.d.ts +66 -4
  24. package/dist/core/index.js +9 -4
  25. package/dist/core/interactions/index.cjs +3 -6
  26. package/dist/core/interactions/index.d.cts +19 -15
  27. package/dist/core/interactions/index.d.ts +19 -15
  28. package/dist/core/interactions/index.js +4 -7
  29. package/dist/{error-C4Zm5nQe.d.cts → error-Dflr3G5x.d.cts} +1 -1
  30. package/dist/{error-C4Zm5nQe.d.ts → error-Dflr3G5x.d.ts} +1 -1
  31. package/dist/react/index.cjs +74 -150
  32. package/dist/react/index.d.cts +4 -5
  33. package/dist/react/index.d.ts +4 -5
  34. package/dist/react/index.js +72 -148
  35. package/dist/{sendTransaction-fLvpfqaQ.d.ts → sendTransaction-3d8jO9CJ.d.ts} +1 -1
  36. package/dist/{sendTransaction-C19oCc6X.d.cts → sendTransaction-Cz6FoB9_.d.cts} +1 -1
  37. package/package.json +5 -5
  38. package/dist/chunk-22T2NHQK.js +0 -22
  39. package/dist/chunk-5SGDBU5S.cjs +0 -427
  40. package/dist/chunk-AANA3LEO.cjs +0 -22
  41. package/dist/chunk-ETV4XYOV.cjs +0 -7
  42. package/dist/chunk-PKBMQBKP.js +0 -7
  43. package/dist/chunk-PURWUKEM.cjs +0 -72
  44. package/dist/chunk-S223FMEJ.js +0 -86
  45. package/dist/chunk-UOEVM7TR.cjs +0 -86
  46. package/dist/index.cjs +0 -1
  47. package/dist/index.d.cts +0 -2
  48. package/dist/index.d.ts +0 -2
  49. package/dist/index.js +0 -0
@@ -1,26 +1,24 @@
1
1
  import {
2
- ClientNotFound,
3
- Deferred,
4
- FrakRpcError,
5
- RpcErrorCodes,
6
- baseIframeProps,
7
- compressJson,
8
- createIFrameNexusClient,
9
- decompressJson
10
- } from "../chunk-5LZQXBFJ.js";
2
+ createIFrameNexusClient
3
+ } from "../chunk-ARQTOP44.js";
11
4
  import {
12
5
  displayModal,
13
6
  openSso,
7
+ processReferral,
14
8
  sendInteraction,
15
9
  sendTransaction,
16
10
  siweAuthenticate,
17
- watchWalletStatus
18
- } from "../chunk-S223FMEJ.js";
11
+ walletStatus
12
+ } from "../chunk-VMNURFPI.js";
19
13
  import {
20
- ReferralInteractionEncoder
21
- } from "../chunk-IH3QWPWT.js";
22
- import "../chunk-22T2NHQK.js";
23
- import "../chunk-PKBMQBKP.js";
14
+ ClientNotFound,
15
+ FrakRpcError,
16
+ NexusContextManager,
17
+ RpcErrorCodes,
18
+ baseIframeProps
19
+ } from "../chunk-2LAGZ6S5.js";
20
+ import "../chunk-I47XQDS3.js";
21
+ import "../chunk-K4FOGADW.js";
24
22
 
25
23
  // src/react/provider/NexusConfigProvider.ts
26
24
  import { createContext, createElement } from "react";
@@ -88,16 +86,7 @@ function useWalletStatus() {
88
86
  if (!client) {
89
87
  throw new ClientNotFound();
90
88
  }
91
- const firstResult = new Deferred();
92
- let hasResolved = false;
93
- await watchWalletStatus(client, (status) => {
94
- newStatusUpdated(status);
95
- if (!hasResolved) {
96
- firstResult.resolve(status);
97
- hasResolved = true;
98
- }
99
- });
100
- return firstResult.promise;
89
+ return walletStatus(client, newStatusUpdated);
101
90
  },
102
91
  enabled: !!client
103
92
  });
@@ -145,47 +134,10 @@ function useSiweAuthenticate({
145
134
 
146
135
  // src/react/hook/helper/useReferralInteraction.ts
147
136
  import { useQuery as useQuery3 } from "@tanstack/react-query";
148
- import { useCallback as useCallback2, useMemo as useMemo2 } from "react";
149
- import { isAddressEqual } from "viem";
150
-
151
- // src/react/hook/useDisplayModal.ts
152
- import { useMutation as useMutation3 } from "@tanstack/react-query";
153
- function useDisplayModal({
154
- mutations
155
- } = {}) {
156
- const client = useNexusClient();
157
- return useMutation3({
158
- ...mutations,
159
- mutationKey: ["nexus-sdk", "display-modal"],
160
- mutationFn: async (args) => {
161
- if (!client) {
162
- throw new ClientNotFound();
163
- }
164
- return displayModal(client, args);
165
- }
166
- });
167
- }
168
-
169
- // src/react/hook/useSendInteraction.ts
170
- import { useMutation as useMutation4 } from "@tanstack/react-query";
171
- function useSendInteraction({
172
- mutations
173
- } = {}) {
174
- const client = useNexusClient();
175
- return useMutation4({
176
- ...mutations,
177
- mutationKey: ["nexus-sdk", "send-interaction"],
178
- mutationFn: async (params) => {
179
- if (!client) {
180
- throw new ClientNotFound();
181
- }
182
- return sendInteraction(client, params);
183
- }
184
- });
185
- }
137
+ import { useMemo as useMemo2 } from "react";
186
138
 
187
139
  // src/react/hook/utils/useNexusContext.ts
188
- import { useMutation as useMutation5, useQuery as useQuery2 } from "@tanstack/react-query";
140
+ import { useMutation as useMutation3, useQuery as useQuery2 } from "@tanstack/react-query";
189
141
 
190
142
  // src/react/hook/utils/useWindowLocation.ts
191
143
  import { useEffect as useEffect2, useMemo, useState as useState2 } from "react";
@@ -224,32 +176,24 @@ function useWindowLocation() {
224
176
  }
225
177
 
226
178
  // src/react/hook/utils/useNexusContext.ts
227
- var contextKey = "nCtx";
228
179
  function useNexusContext() {
229
180
  const { location } = useWindowLocation();
230
181
  const { data: nexusContext } = useQuery2({
231
182
  queryKey: ["nexus-sdk", "context", location?.href ?? "no-href"],
232
183
  queryFn: async () => {
233
184
  if (!location?.href) return null;
234
- const url = new URL(location.href);
235
- const nexusContext2 = url.searchParams.get(contextKey);
236
- if (!nexusContext2) return null;
237
- const parsedContext = await decompressJson(nexusContext2);
238
- if (!parsedContext) return null;
239
- return parsedContext;
185
+ return NexusContextManager.parse({ url: location.href });
240
186
  },
241
187
  enabled: !!location?.href
242
188
  });
243
- const { mutate: updateContext, mutateAsync: updateContextAsync } = useMutation5({
189
+ const { mutate: updateContext, mutateAsync: updateContextAsync } = useMutation3({
244
190
  mutationKey: ["nexus-sdk", "update-context"],
245
191
  mutationFn: async (newContext) => {
246
- if (!location || typeof window === "undefined") return;
247
- const fullNewContext = nexusContext ? { ...nexusContext, ...newContext } : newContext;
248
- const compressedContext = await compressJson(fullNewContext);
249
- if (!compressedContext) return;
250
- const url = new URL(location.href);
251
- url.searchParams.set(contextKey, compressedContext);
252
- window.history.replaceState(null, "", url.toString());
192
+ console.log("Updating context", { newContext });
193
+ await NexusContextManager.replaceUrl({
194
+ url: location?.href,
195
+ context: newContext
196
+ });
253
197
  }
254
198
  });
255
199
  return {
@@ -264,47 +208,9 @@ function useReferralInteraction({
264
208
  productId,
265
209
  modalConfig
266
210
  } = {}) {
267
- const { nexusContext, updateContextAsync } = useNexusContext();
268
- const { data: walletStatus } = useWalletStatus();
269
- const { mutateAsync: sendInteraction2 } = useSendInteraction();
270
- const ensureWalletConnected = useEnsureWalletConnected({
271
- modalConfig,
272
- walletStatus
273
- });
274
- const processReferral = useCallback2(async () => {
275
- try {
276
- let currentWallet = walletStatus?.key === "connected" ? walletStatus.wallet : void 0;
277
- if (!nexusContext?.r) {
278
- if (currentWallet) {
279
- await updateContextAsync({ r: currentWallet });
280
- }
281
- return "no-referrer";
282
- }
283
- if (!currentWallet) {
284
- currentWallet = await ensureWalletConnected();
285
- }
286
- if (currentWallet && isAddressEqual(nexusContext.r, currentWallet)) {
287
- return "self-referral";
288
- }
289
- const interaction = ReferralInteractionEncoder.referred({
290
- referrer: nexusContext.r
291
- });
292
- await sendInteraction2({ productId, interaction });
293
- if (currentWallet) {
294
- await updateContextAsync({ r: currentWallet });
295
- }
296
- return "success";
297
- } catch (error2) {
298
- return mapErrorToState(error2);
299
- }
300
- }, [
301
- nexusContext,
302
- productId,
303
- ensureWalletConnected,
304
- sendInteraction2,
305
- updateContextAsync,
306
- walletStatus
307
- ]);
211
+ const client = useNexusClient();
212
+ const { nexusContext } = useNexusContext();
213
+ const { data: walletStatus2 } = useWalletStatus();
308
214
  const {
309
215
  data: referralState,
310
216
  error,
@@ -316,45 +222,63 @@ function useReferralInteraction({
316
222
  "nexus-sdk",
317
223
  "auto-referral-interaction",
318
224
  nexusContext?.r ?? "no-referrer",
319
- walletStatus?.key ?? "no-wallet-status"
225
+ walletStatus2?.key ?? "no-wallet-status",
226
+ productId ?? "no-product-id"
320
227
  ],
321
- queryFn: processReferral,
322
- enabled: !!walletStatus
228
+ queryFn: () => {
229
+ if (!client) {
230
+ throw new ClientNotFound();
231
+ }
232
+ return processReferral(client, {
233
+ walletStatus: walletStatus2,
234
+ nexusContext,
235
+ modalConfig,
236
+ productId
237
+ });
238
+ },
239
+ enabled: !!walletStatus2
323
240
  });
324
241
  return useMemo2(() => {
325
242
  if (status === "pending") return "processing";
326
- if (status === "error") return mapErrorToState(error);
243
+ if (status === "error") return error;
327
244
  return referralState || "idle";
328
245
  }, [referralState, status, error]);
329
246
  }
330
- function useEnsureWalletConnected({
331
- modalConfig,
332
- walletStatus
333
- }) {
334
- const { mutateAsync: displayModal2 } = useDisplayModal();
335
- return useCallback2(async () => {
336
- if (walletStatus?.key !== "connected" || !walletStatus.interactionSession) {
337
- if (!modalConfig) {
338
- return void 0;
247
+
248
+ // src/react/hook/useSendInteraction.ts
249
+ import { useMutation as useMutation4 } from "@tanstack/react-query";
250
+ function useSendInteraction({
251
+ mutations
252
+ } = {}) {
253
+ const client = useNexusClient();
254
+ return useMutation4({
255
+ ...mutations,
256
+ mutationKey: ["nexus-sdk", "send-interaction"],
257
+ mutationFn: async (params) => {
258
+ if (!client) {
259
+ throw new ClientNotFound();
339
260
  }
340
- const result = await displayModal2(modalConfig);
341
- return result?.login?.wallet ?? void 0;
261
+ return sendInteraction(client, params);
342
262
  }
343
- return walletStatus.wallet ?? void 0;
344
- }, [walletStatus, modalConfig, displayModal2]);
263
+ });
345
264
  }
346
- function mapErrorToState(error) {
347
- if (error instanceof FrakRpcError) {
348
- switch (error.code) {
349
- case RpcErrorCodes.walletNotConnected:
350
- return "no-wallet";
351
- case RpcErrorCodes.noInteractionSession:
352
- return "no-session";
353
- default:
354
- return "error";
265
+
266
+ // src/react/hook/useDisplayModal.ts
267
+ import { useMutation as useMutation5 } from "@tanstack/react-query";
268
+ function useDisplayModal({
269
+ mutations
270
+ } = {}) {
271
+ const client = useNexusClient();
272
+ return useMutation5({
273
+ ...mutations,
274
+ mutationKey: ["nexus-sdk", "display-modal"],
275
+ mutationFn: async (args) => {
276
+ if (!client) {
277
+ throw new ClientNotFound();
278
+ }
279
+ return displayModal(client, args);
355
280
  }
356
- }
357
- return "error";
281
+ });
358
282
  }
359
283
 
360
284
  // src/react/hook/useOpenSso.ts
@@ -1,4 +1,4 @@
1
- import { S as SiweAuthenticationParams, M as ModalRpcMetadata, N as NexusClient, a as SiweAuthenticateReturnType, b as SendTransactionModalStepType, c as SendTransactionReturnType } from './client-DJd7-ajw.js';
1
+ import { h as SiweAuthenticationParams, c as ModalRpcMetadata, a as NexusClient, i as SiweAuthenticateReturnType, k as SendTransactionModalStepType, l as SendTransactionReturnType } from './client-B3Guoe3I.js';
2
2
 
3
3
  /**
4
4
  * Partial SIWE params, since we can rebuild them from the SDK if they are empty
@@ -1,4 +1,4 @@
1
- import { S as SiweAuthenticationParams, M as ModalRpcMetadata, N as NexusClient, a as SiweAuthenticateReturnType, b as SendTransactionModalStepType, c as SendTransactionReturnType } from './client-DXITs1Kf.cjs';
1
+ import { h as SiweAuthenticationParams, c as ModalRpcMetadata, a as NexusClient, i as SiweAuthenticateReturnType, k as SendTransactionModalStepType, l as SendTransactionReturnType } from './client-Of9uIxuI.cjs';
2
2
 
3
3
  /**
4
4
  * Partial SIWE params, since we can rebuild them from the SDK if they are empty
package/package.json CHANGED
@@ -11,8 +11,8 @@
11
11
  "url": "https://twitter.com/QNivelais"
12
12
  }
13
13
  ],
14
- "version": "0.0.14",
15
- "description": "Nexus Wallet client SDK, helping any person to interact with the Frak wallet, and require the unlock of a premium article within the Frak ecosystem.",
14
+ "version": "0.0.15",
15
+ "description": "Frak Wallet client SDK, helping any person to interact with the Frak wallet, and require the unlock of a premium article within the Frak ecosystem.",
16
16
  "repository": {
17
17
  "url": "https://github.com/frak-id/wallet",
18
18
  "directory": "packages/sdk"
@@ -68,8 +68,8 @@
68
68
  "format:check": "biome check .",
69
69
  "format": "biome check --write .",
70
70
  "clean": "rimraf dist",
71
- "build": "tsup --splitting",
72
- "build:watch": "tsup --watch --splitting --format esm"
71
+ "build": "tsup",
72
+ "build:watch": "tsup --watch"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "viem": "^2.x",
@@ -81,7 +81,7 @@
81
81
  "js-sha256": "^0.11.0"
82
82
  },
83
83
  "devDependencies": {
84
- "@tanstack/react-query": ">=5.53.3",
84
+ "@tanstack/react-query": ">=5.56.2",
85
85
  "@types/node": "^22",
86
86
  "tsup": "^8.2.4",
87
87
  "typescript": "^5"
@@ -1,22 +0,0 @@
1
- // src/core/constants/productTypes.ts
2
- var productTypes = {
3
- // content type
4
- dapp: 1,
5
- press: 2,
6
- // feature type
7
- referral: 30
8
- };
9
- var productTypesMask = Object.entries(
10
- productTypes
11
- ).reduce(
12
- (acc, [key, value]) => {
13
- acc[key] = BigInt(1) << BigInt(value);
14
- return acc;
15
- },
16
- {}
17
- );
18
-
19
- export {
20
- productTypes,
21
- productTypesMask
22
- };