@frak-labs/nexus-sdk 0.0.13 → 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.
- package/README.md +4 -4
- package/dist/NexusContext-CSlCNW-G.d.cts +10 -0
- package/dist/NexusContext-CSlCNW-G.d.ts +10 -0
- package/dist/bundle/bundle.js +21 -0
- package/dist/chunk-2LAGZ6S5.js +246 -0
- package/dist/chunk-4ADWI2GG.cjs +243 -0
- package/dist/chunk-4LT3U3H4.cjs +246 -0
- package/dist/{chunk-FF32LTPI.js → chunk-ARQTOP44.js} +13 -197
- package/dist/chunk-C25NTD45.cjs +100 -0
- package/dist/chunk-DILTMQBI.cjs +51 -0
- package/dist/chunk-I47XQDS3.js +100 -0
- package/dist/chunk-K4FOGADW.js +51 -0
- package/dist/chunk-KEATMEOW.cjs +207 -0
- package/dist/chunk-VMNURFPI.js +207 -0
- package/dist/{client-B6_BIGc3.d.ts → client-B3Guoe3I.d.ts} +13 -7
- package/dist/{client-Oily5ph8.d.cts → client-Of9uIxuI.d.cts} +13 -7
- package/dist/core/actions/index.cjs +11 -3
- package/dist/core/actions/index.d.cts +33 -9
- package/dist/core/actions/index.d.ts +33 -9
- package/dist/core/actions/index.js +10 -2
- package/dist/core/index.cjs +14 -3
- package/dist/core/index.d.cts +84 -5
- package/dist/core/index.d.ts +84 -5
- package/dist/core/index.js +15 -4
- package/dist/core/interactions/index.cjs +3 -5
- package/dist/core/interactions/index.d.cts +20 -16
- package/dist/core/interactions/index.d.ts +20 -16
- package/dist/core/interactions/index.js +4 -6
- package/dist/{error-C4Zm5nQe.d.cts → error-Dflr3G5x.d.cts} +1 -1
- package/dist/{error-C4Zm5nQe.d.ts → error-Dflr3G5x.d.ts} +1 -1
- package/dist/{interaction-D3-M3nBh.d.ts → interaction-BngPoHA0.d.cts} +1 -1
- package/dist/{interaction-D3-M3nBh.d.cts → interaction-BngPoHA0.d.ts} +1 -1
- package/dist/react/index.cjs +75 -150
- package/dist/react/index.d.cts +8 -9
- package/dist/react/index.d.ts +8 -9
- package/dist/react/index.js +73 -148
- package/dist/{sendTransaction-BHqCq_9X.d.ts → sendTransaction-3d8jO9CJ.d.ts} +1 -1
- package/dist/{sendTransaction-BKKYEt8p.d.cts → sendTransaction-Cz6FoB9_.d.cts} +1 -1
- package/package.json +5 -5
- package/dist/chunk-2SGRLI7T.cjs +0 -427
- package/dist/chunk-5CFD5FM2.js +0 -86
- package/dist/chunk-ETV4XYOV.cjs +0 -7
- package/dist/chunk-GUDT2W6I.js +0 -70
- package/dist/chunk-IQQTTKJL.cjs +0 -70
- package/dist/chunk-PKBMQBKP.js +0 -7
- package/dist/chunk-S5FVCA2E.cjs +0 -86
- package/dist/index.cjs +0 -1
- package/dist/index.d.cts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -0
package/dist/react/index.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
FrakRpcError,
|
|
5
|
-
RpcErrorCodes,
|
|
6
|
-
baseIframeProps,
|
|
7
|
-
compressJson,
|
|
8
|
-
createIFrameNexusClient,
|
|
9
|
-
decompressJson
|
|
10
|
-
} from "../chunk-FF32LTPI.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
|
-
|
|
18
|
-
} from "../chunk-
|
|
11
|
+
walletStatus
|
|
12
|
+
} from "../chunk-VMNURFPI.js";
|
|
19
13
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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";
|
|
23
22
|
|
|
24
23
|
// src/react/provider/NexusConfigProvider.ts
|
|
25
24
|
import { createContext, createElement } from "react";
|
|
@@ -87,16 +86,7 @@ function useWalletStatus() {
|
|
|
87
86
|
if (!client) {
|
|
88
87
|
throw new ClientNotFound();
|
|
89
88
|
}
|
|
90
|
-
|
|
91
|
-
let hasResolved = false;
|
|
92
|
-
await watchWalletStatus(client, (status) => {
|
|
93
|
-
newStatusUpdated(status);
|
|
94
|
-
if (!hasResolved) {
|
|
95
|
-
firstResult.resolve(status);
|
|
96
|
-
hasResolved = true;
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
return firstResult.promise;
|
|
89
|
+
return walletStatus(client, newStatusUpdated);
|
|
100
90
|
},
|
|
101
91
|
enabled: !!client
|
|
102
92
|
});
|
|
@@ -144,47 +134,10 @@ function useSiweAuthenticate({
|
|
|
144
134
|
|
|
145
135
|
// src/react/hook/helper/useReferralInteraction.ts
|
|
146
136
|
import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
147
|
-
import {
|
|
148
|
-
import { isAddressEqual } from "viem";
|
|
149
|
-
|
|
150
|
-
// src/react/hook/useDisplayModal.ts
|
|
151
|
-
import { useMutation as useMutation3 } from "@tanstack/react-query";
|
|
152
|
-
function useDisplayModal({
|
|
153
|
-
mutations
|
|
154
|
-
} = {}) {
|
|
155
|
-
const client = useNexusClient();
|
|
156
|
-
return useMutation3({
|
|
157
|
-
...mutations,
|
|
158
|
-
mutationKey: ["nexus-sdk", "display-modal"],
|
|
159
|
-
mutationFn: async (args) => {
|
|
160
|
-
if (!client) {
|
|
161
|
-
throw new ClientNotFound();
|
|
162
|
-
}
|
|
163
|
-
return displayModal(client, args);
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// src/react/hook/useSendInteraction.ts
|
|
169
|
-
import { useMutation as useMutation4 } from "@tanstack/react-query";
|
|
170
|
-
function useSendInteraction({
|
|
171
|
-
mutations
|
|
172
|
-
} = {}) {
|
|
173
|
-
const client = useNexusClient();
|
|
174
|
-
return useMutation4({
|
|
175
|
-
...mutations,
|
|
176
|
-
mutationKey: ["nexus-sdk", "send-interaction"],
|
|
177
|
-
mutationFn: async (params) => {
|
|
178
|
-
if (!client) {
|
|
179
|
-
throw new ClientNotFound();
|
|
180
|
-
}
|
|
181
|
-
return sendInteraction(client, params);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
137
|
+
import { useMemo as useMemo2 } from "react";
|
|
185
138
|
|
|
186
139
|
// src/react/hook/utils/useNexusContext.ts
|
|
187
|
-
import { useMutation as
|
|
140
|
+
import { useMutation as useMutation3, useQuery as useQuery2 } from "@tanstack/react-query";
|
|
188
141
|
|
|
189
142
|
// src/react/hook/utils/useWindowLocation.ts
|
|
190
143
|
import { useEffect as useEffect2, useMemo, useState as useState2 } from "react";
|
|
@@ -223,32 +176,24 @@ function useWindowLocation() {
|
|
|
223
176
|
}
|
|
224
177
|
|
|
225
178
|
// src/react/hook/utils/useNexusContext.ts
|
|
226
|
-
var contextKey = "nCtx";
|
|
227
179
|
function useNexusContext() {
|
|
228
180
|
const { location } = useWindowLocation();
|
|
229
181
|
const { data: nexusContext } = useQuery2({
|
|
230
182
|
queryKey: ["nexus-sdk", "context", location?.href ?? "no-href"],
|
|
231
183
|
queryFn: async () => {
|
|
232
184
|
if (!location?.href) return null;
|
|
233
|
-
|
|
234
|
-
const nexusContext2 = url.searchParams.get(contextKey);
|
|
235
|
-
if (!nexusContext2) return null;
|
|
236
|
-
const parsedContext = await decompressJson(nexusContext2);
|
|
237
|
-
if (!parsedContext) return null;
|
|
238
|
-
return parsedContext;
|
|
185
|
+
return NexusContextManager.parse({ url: location.href });
|
|
239
186
|
},
|
|
240
187
|
enabled: !!location?.href
|
|
241
188
|
});
|
|
242
|
-
const { mutate: updateContext, mutateAsync: updateContextAsync } =
|
|
189
|
+
const { mutate: updateContext, mutateAsync: updateContextAsync } = useMutation3({
|
|
243
190
|
mutationKey: ["nexus-sdk", "update-context"],
|
|
244
191
|
mutationFn: async (newContext) => {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
url.searchParams.set(contextKey, compressedContext);
|
|
251
|
-
window.history.replaceState(null, "", url.toString());
|
|
192
|
+
console.log("Updating context", { newContext });
|
|
193
|
+
await NexusContextManager.replaceUrl({
|
|
194
|
+
url: location?.href,
|
|
195
|
+
context: newContext
|
|
196
|
+
});
|
|
252
197
|
}
|
|
253
198
|
});
|
|
254
199
|
return {
|
|
@@ -260,50 +205,12 @@ function useNexusContext() {
|
|
|
260
205
|
|
|
261
206
|
// src/react/hook/helper/useReferralInteraction.ts
|
|
262
207
|
function useReferralInteraction({
|
|
263
|
-
|
|
208
|
+
productId,
|
|
264
209
|
modalConfig
|
|
265
210
|
} = {}) {
|
|
266
|
-
const
|
|
267
|
-
const {
|
|
268
|
-
const {
|
|
269
|
-
const ensureWalletConnected = useEnsureWalletConnected({
|
|
270
|
-
modalConfig,
|
|
271
|
-
walletStatus
|
|
272
|
-
});
|
|
273
|
-
const processReferral = useCallback2(async () => {
|
|
274
|
-
try {
|
|
275
|
-
let currentWallet = walletStatus?.key === "connected" ? walletStatus.wallet : void 0;
|
|
276
|
-
if (!nexusContext?.r) {
|
|
277
|
-
if (currentWallet) {
|
|
278
|
-
await updateContextAsync({ r: currentWallet });
|
|
279
|
-
}
|
|
280
|
-
return "no-referrer";
|
|
281
|
-
}
|
|
282
|
-
if (!currentWallet) {
|
|
283
|
-
currentWallet = await ensureWalletConnected();
|
|
284
|
-
}
|
|
285
|
-
if (currentWallet && isAddressEqual(nexusContext.r, currentWallet)) {
|
|
286
|
-
return "self-referral";
|
|
287
|
-
}
|
|
288
|
-
const interaction = ReferralInteractionEncoder.referred({
|
|
289
|
-
referrer: nexusContext.r
|
|
290
|
-
});
|
|
291
|
-
await sendInteraction2({ contentId, interaction });
|
|
292
|
-
if (currentWallet) {
|
|
293
|
-
await updateContextAsync({ r: currentWallet });
|
|
294
|
-
}
|
|
295
|
-
return "success";
|
|
296
|
-
} catch (error2) {
|
|
297
|
-
return mapErrorToState(error2);
|
|
298
|
-
}
|
|
299
|
-
}, [
|
|
300
|
-
nexusContext,
|
|
301
|
-
contentId,
|
|
302
|
-
ensureWalletConnected,
|
|
303
|
-
sendInteraction2,
|
|
304
|
-
updateContextAsync,
|
|
305
|
-
walletStatus
|
|
306
|
-
]);
|
|
211
|
+
const client = useNexusClient();
|
|
212
|
+
const { nexusContext } = useNexusContext();
|
|
213
|
+
const { data: walletStatus2 } = useWalletStatus();
|
|
307
214
|
const {
|
|
308
215
|
data: referralState,
|
|
309
216
|
error,
|
|
@@ -315,45 +222,63 @@ function useReferralInteraction({
|
|
|
315
222
|
"nexus-sdk",
|
|
316
223
|
"auto-referral-interaction",
|
|
317
224
|
nexusContext?.r ?? "no-referrer",
|
|
318
|
-
|
|
225
|
+
walletStatus2?.key ?? "no-wallet-status",
|
|
226
|
+
productId ?? "no-product-id"
|
|
319
227
|
],
|
|
320
|
-
queryFn:
|
|
321
|
-
|
|
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
|
|
322
240
|
});
|
|
323
241
|
return useMemo2(() => {
|
|
324
242
|
if (status === "pending") return "processing";
|
|
325
|
-
if (status === "error") return
|
|
243
|
+
if (status === "error") return error;
|
|
326
244
|
return referralState || "idle";
|
|
327
245
|
}, [referralState, status, error]);
|
|
328
246
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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();
|
|
338
260
|
}
|
|
339
|
-
|
|
340
|
-
return result?.login?.wallet ?? void 0;
|
|
261
|
+
return sendInteraction(client, params);
|
|
341
262
|
}
|
|
342
|
-
|
|
343
|
-
}, [walletStatus, modalConfig, displayModal2]);
|
|
263
|
+
});
|
|
344
264
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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);
|
|
354
280
|
}
|
|
355
|
-
}
|
|
356
|
-
return "error";
|
|
281
|
+
});
|
|
357
282
|
}
|
|
358
283
|
|
|
359
284
|
// src/react/hook/useOpenSso.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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.
|
|
15
|
-
"description": "
|
|
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
|
|
72
|
-
"build:watch": "tsup --watch
|
|
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.
|
|
84
|
+
"@tanstack/react-query": ">=5.56.2",
|
|
85
85
|
"@types/node": "^22",
|
|
86
86
|
"tsup": "^8.2.4",
|
|
87
87
|
"typescript": "^5"
|