@frak-labs/nexus-sdk 0.0.14 → 0.0.16
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/FrakContext-LbQht1ep.d.cts +10 -0
- package/dist/FrakContext-LbQht1ep.d.ts +10 -0
- package/dist/bundle/bundle.js +21 -0
- package/dist/chunk-A3XYA7S7.cjs +114 -0
- package/dist/{chunk-5LZQXBFJ.js → chunk-AHUMDUJC.js} +12 -196
- package/dist/chunk-D77BTQYS.js +210 -0
- package/dist/chunk-DAGCBEBQ.cjs +243 -0
- package/dist/chunk-FO2GFD5C.cjs +210 -0
- package/dist/chunk-FYMOOHMT.js +254 -0
- package/dist/chunk-HY6YATLS.js +53 -0
- package/dist/chunk-J655X6YR.cjs +254 -0
- package/dist/chunk-TIKEZMSD.js +114 -0
- package/dist/chunk-UFJ7W6CQ.cjs +53 -0
- package/dist/{client-DJd7-ajw.d.ts → client-ALy_TEwJ.d.ts} +34 -11
- package/dist/{client-DXITs1Kf.d.cts → client-DaEox5q4.d.cts} +34 -11
- package/dist/core/actions/index.cjs +11 -3
- package/dist/core/actions/index.d.cts +28 -5
- package/dist/core/actions/index.d.ts +28 -5
- package/dist/core/actions/index.js +10 -2
- package/dist/core/index.cjs +15 -4
- package/dist/core/index.d.cts +98 -4
- package/dist/core/index.d.ts +98 -4
- package/dist/core/index.js +15 -4
- package/dist/core/interactions/index.cjs +3 -4
- package/dist/core/interactions/index.d.cts +27 -15
- package/dist/core/interactions/index.d.ts +27 -15
- package/dist/core/interactions/index.js +8 -9
- 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/react/index.cjs +79 -155
- package/dist/react/index.d.cts +4 -5
- package/dist/react/index.d.ts +4 -5
- package/dist/react/index.js +78 -154
- package/dist/{sendTransaction-fLvpfqaQ.d.ts → sendTransaction-BOd-pvXr.d.ts} +2 -2
- package/dist/{sendTransaction-C19oCc6X.d.cts → sendTransaction-MhdJPTWd.d.cts} +2 -2
- package/package.json +6 -6
- package/dist/chunk-22T2NHQK.js +0 -22
- package/dist/chunk-5SGDBU5S.cjs +0 -427
- package/dist/chunk-AANA3LEO.cjs +0 -22
- package/dist/chunk-ETV4XYOV.cjs +0 -7
- package/dist/chunk-IH3QWPWT.js +0 -72
- package/dist/chunk-PKBMQBKP.js +0 -7
- package/dist/chunk-PURWUKEM.cjs +0 -72
- package/dist/chunk-S223FMEJ.js +0 -86
- package/dist/chunk-UOEVM7TR.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,26 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
FrakRpcError,
|
|
5
|
-
RpcErrorCodes,
|
|
6
|
-
baseIframeProps,
|
|
7
|
-
compressJson,
|
|
8
|
-
createIFrameNexusClient,
|
|
9
|
-
decompressJson
|
|
10
|
-
} from "../chunk-5LZQXBFJ.js";
|
|
2
|
+
createIFrameNexusClient
|
|
3
|
+
} from "../chunk-AHUMDUJC.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-D77BTQYS.js";
|
|
19
13
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
ClientNotFound,
|
|
15
|
+
FrakContextManager,
|
|
16
|
+
FrakRpcError,
|
|
17
|
+
RpcErrorCodes,
|
|
18
|
+
baseIframeProps
|
|
19
|
+
} from "../chunk-FYMOOHMT.js";
|
|
20
|
+
import "../chunk-TIKEZMSD.js";
|
|
21
|
+
import "../chunk-HY6YATLS.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
|
-
|
|
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 {
|
|
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
|
-
// src/react/hook/utils/
|
|
188
|
-
import { useMutation as
|
|
139
|
+
// src/react/hook/utils/useFrakContext.ts
|
|
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";
|
|
@@ -223,37 +175,29 @@ function useWindowLocation() {
|
|
|
223
175
|
return { location, href };
|
|
224
176
|
}
|
|
225
177
|
|
|
226
|
-
// src/react/hook/utils/
|
|
227
|
-
|
|
228
|
-
function useNexusContext() {
|
|
178
|
+
// src/react/hook/utils/useFrakContext.ts
|
|
179
|
+
function useFrakContext() {
|
|
229
180
|
const { location } = useWindowLocation();
|
|
230
|
-
const { data:
|
|
181
|
+
const { data: frakContext } = useQuery2({
|
|
231
182
|
queryKey: ["nexus-sdk", "context", location?.href ?? "no-href"],
|
|
232
183
|
queryFn: async () => {
|
|
233
184
|
if (!location?.href) return null;
|
|
234
|
-
|
|
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 FrakContextManager.parse({ url: location.href });
|
|
240
186
|
},
|
|
241
187
|
enabled: !!location?.href
|
|
242
188
|
});
|
|
243
|
-
const { mutate: updateContext, mutateAsync: updateContextAsync } =
|
|
189
|
+
const { mutate: updateContext, mutateAsync: updateContextAsync } = useMutation3({
|
|
244
190
|
mutationKey: ["nexus-sdk", "update-context"],
|
|
245
191
|
mutationFn: async (newContext) => {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
url.searchParams.set(contextKey, compressedContext);
|
|
252
|
-
window.history.replaceState(null, "", url.toString());
|
|
192
|
+
console.log("Updating context", { newContext });
|
|
193
|
+
await FrakContextManager.replaceUrl({
|
|
194
|
+
url: location?.href,
|
|
195
|
+
context: newContext
|
|
196
|
+
});
|
|
253
197
|
}
|
|
254
198
|
});
|
|
255
199
|
return {
|
|
256
|
-
|
|
200
|
+
frakContext,
|
|
257
201
|
updateContext,
|
|
258
202
|
updateContextAsync
|
|
259
203
|
};
|
|
@@ -264,47 +208,9 @@ function useReferralInteraction({
|
|
|
264
208
|
productId,
|
|
265
209
|
modalConfig
|
|
266
210
|
} = {}) {
|
|
267
|
-
const
|
|
268
|
-
const {
|
|
269
|
-
const {
|
|
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 { frakContext } = useFrakContext();
|
|
213
|
+
const { data: walletStatus2 } = useWalletStatus();
|
|
308
214
|
const {
|
|
309
215
|
data: referralState,
|
|
310
216
|
error,
|
|
@@ -315,46 +221,64 @@ function useReferralInteraction({
|
|
|
315
221
|
queryKey: [
|
|
316
222
|
"nexus-sdk",
|
|
317
223
|
"auto-referral-interaction",
|
|
318
|
-
|
|
319
|
-
|
|
224
|
+
frakContext?.r ?? "no-referrer",
|
|
225
|
+
walletStatus2?.key ?? "no-wallet-status",
|
|
226
|
+
productId ?? "no-product-id"
|
|
320
227
|
],
|
|
321
|
-
queryFn:
|
|
322
|
-
|
|
228
|
+
queryFn: () => {
|
|
229
|
+
if (!client) {
|
|
230
|
+
throw new ClientNotFound();
|
|
231
|
+
}
|
|
232
|
+
return processReferral(client, {
|
|
233
|
+
walletStatus: walletStatus2,
|
|
234
|
+
frakContext,
|
|
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
|
|
243
|
+
if (status === "error") return error;
|
|
327
244
|
return referralState || "idle";
|
|
328
245
|
}, [referralState, status, error]);
|
|
329
246
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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
|
-
|
|
341
|
-
return result?.login?.wallet ?? void 0;
|
|
261
|
+
return sendInteraction(client, params);
|
|
342
262
|
}
|
|
343
|
-
|
|
344
|
-
}, [walletStatus, modalConfig, displayModal2]);
|
|
263
|
+
});
|
|
345
264
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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 {
|
|
1
|
+
import { g as SiweAuthenticationParams, b as ModalRpcMetadata, a as NexusClient, h as SiweAuthenticateReturnType, j as SendTransactionModalStepType, k as SendTransactionReturnType } from './client-ALy_TEwJ.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Partial SIWE params, since we can rebuild them from the SDK if they are empty
|
|
@@ -27,4 +27,4 @@ type SendTransactionParams = {
|
|
|
27
27
|
*/
|
|
28
28
|
declare function sendTransaction(client: NexusClient, { tx, metadata }: SendTransactionParams): Promise<SendTransactionReturnType>;
|
|
29
29
|
|
|
30
|
-
export { type
|
|
30
|
+
export { type SendTransactionParams as S, type SiweAuthenticateModalParams as a, sendTransaction as b, siweAuthenticate as s };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { g as SiweAuthenticationParams, b as ModalRpcMetadata, a as NexusClient, h as SiweAuthenticateReturnType, j as SendTransactionModalStepType, k as SendTransactionReturnType } from './client-DaEox5q4.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Partial SIWE params, since we can rebuild them from the SDK if they are empty
|
|
@@ -27,4 +27,4 @@ type SendTransactionParams = {
|
|
|
27
27
|
*/
|
|
28
28
|
declare function sendTransaction(client: NexusClient, { tx, metadata }: SendTransactionParams): Promise<SendTransactionReturnType>;
|
|
29
29
|
|
|
30
|
-
export { type
|
|
30
|
+
export { type SendTransactionParams as S, type SiweAuthenticateModalParams as a, sendTransaction as b, siweAuthenticate as s };
|
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.16",
|
|
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,9 +81,9 @@
|
|
|
81
81
|
"js-sha256": "^0.11.0"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
|
-
"@tanstack/react-query": ">=5.
|
|
84
|
+
"@tanstack/react-query": ">=5.59.15",
|
|
85
85
|
"@types/node": "^22",
|
|
86
|
-
"tsup": "^8.
|
|
86
|
+
"tsup": "^8.3.0",
|
|
87
87
|
"typescript": "^5"
|
|
88
88
|
}
|
|
89
89
|
}
|
package/dist/chunk-22T2NHQK.js
DELETED
|
@@ -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
|
-
};
|