@frak-labs/nexus-sdk 0.0.22 → 0.0.24
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/{FrakContext-DBdWC7ls.d.cts → FrakContext-DKSVaeVb.d.cts} +62 -3
- package/dist/{FrakContext-CDVlUN75.d.ts → FrakContext-DjeuWC2U.d.ts} +62 -3
- package/dist/bundle/bundle.js +5 -5
- package/dist/{chunk-ZQSA2VQ4.js → chunk-2VNIEGOJ.js} +10 -6
- package/dist/{chunk-Q3SIIAX2.js → chunk-4MMSQL44.js} +147 -28
- package/dist/{chunk-4OJ2NPAS.cjs → chunk-4PVF24BB.cjs} +15 -15
- package/dist/{chunk-H3T2GAEC.js → chunk-BOGCLEPR.js} +2 -1
- package/dist/chunk-DE2KWQVP.cjs +351 -0
- package/dist/{chunk-P4QEVLVV.js → chunk-FETGS7X7.js} +1 -1
- package/dist/{chunk-F3F4BCGV.cjs → chunk-H4BK3CNV.cjs} +20 -16
- package/dist/{chunk-QSXZKZJA.cjs → chunk-P3J2BIUT.cjs} +2 -1
- package/dist/{chunk-QYOOKB34.cjs → chunk-QLM5NFMZ.cjs} +22 -22
- package/dist/{chunk-VVF4NKYR.js → chunk-YPQA63LW.js} +2 -2
- package/dist/core/actions/index.cjs +9 -5
- package/dist/core/actions/index.d.cts +51 -6
- package/dist/core/actions/index.d.ts +51 -6
- package/dist/core/actions/index.js +10 -6
- package/dist/core/index.cjs +4 -4
- package/dist/core/index.d.cts +13 -25
- package/dist/core/index.d.ts +13 -25
- package/dist/core/index.js +3 -3
- package/dist/core/interactions/index.cjs +3 -3
- package/dist/core/interactions/index.js +2 -2
- package/dist/{processReferral-CFyGAENf.d.ts → processReferral-CJI_Rc4K.d.ts} +1 -1
- package/dist/{processReferral-BWSIamn2.d.cts → processReferral-DUP8imQV.d.cts} +1 -1
- package/dist/react/index.cjs +52 -31
- package/dist/react/index.d.cts +20 -13
- package/dist/react/index.d.ts +20 -13
- package/dist/react/index.js +32 -11
- package/package.json +42 -19
- package/dist/chunk-4CWA7EWX.cjs +0 -232
|
@@ -3,25 +3,54 @@ import {
|
|
|
3
3
|
FrakContextManager,
|
|
4
4
|
FrakRpcError,
|
|
5
5
|
RpcErrorCodes
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-2VNIEGOJ.js";
|
|
7
7
|
import {
|
|
8
8
|
ReferralInteractionEncoder
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-FETGS7X7.js";
|
|
10
10
|
|
|
11
11
|
// src/core/actions/watchWalletStatus.ts
|
|
12
12
|
function watchWalletStatus(client, callback) {
|
|
13
|
+
if (!callback) {
|
|
14
|
+
return client.request({ method: "frak_listenToWalletStatus" }).then((result) => {
|
|
15
|
+
savePotentialToken(result.interactionToken);
|
|
16
|
+
return result;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const firstResult = new Deferred();
|
|
20
|
+
let hasResolved = false;
|
|
13
21
|
return client.listenerRequest(
|
|
14
22
|
{
|
|
15
23
|
method: "frak_listenToWalletStatus"
|
|
16
24
|
},
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
(status) => {
|
|
26
|
+
callback(status);
|
|
27
|
+
savePotentialToken(status.interactionToken);
|
|
28
|
+
if (!hasResolved) {
|
|
29
|
+
firstResult.resolve(status);
|
|
30
|
+
hasResolved = true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
).then(() => firstResult.promise);
|
|
34
|
+
}
|
|
35
|
+
function savePotentialToken(interactionToken) {
|
|
36
|
+
if (typeof window === "undefined") {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (interactionToken) {
|
|
40
|
+
window.sessionStorage.setItem(
|
|
41
|
+
"frak-wallet-interaction-token",
|
|
42
|
+
interactionToken
|
|
43
|
+
);
|
|
44
|
+
} else {
|
|
45
|
+
window.sessionStorage.removeItem("frak.interaction-token");
|
|
46
|
+
}
|
|
19
47
|
}
|
|
20
48
|
|
|
21
49
|
// src/core/utils/computeProductId.ts
|
|
22
50
|
import { keccak256, toHex } from "viem";
|
|
23
51
|
function computeProductId({ domain }) {
|
|
24
|
-
|
|
52
|
+
const effectiveDomain = domain ?? window.location.host;
|
|
53
|
+
return keccak256(toHex(effectiveDomain));
|
|
25
54
|
}
|
|
26
55
|
|
|
27
56
|
// src/core/actions/sendInteraction.ts
|
|
@@ -50,17 +79,49 @@ async function openSso(client, args) {
|
|
|
50
79
|
});
|
|
51
80
|
}
|
|
52
81
|
|
|
82
|
+
// src/core/actions/getProductInformation.ts
|
|
83
|
+
async function getProductInformation(client) {
|
|
84
|
+
return await client.request({
|
|
85
|
+
method: "frak_getProductInformation"
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/core/actions/trackPurchaseStatus.ts
|
|
90
|
+
async function trackPurchaseStatus(args) {
|
|
91
|
+
if (typeof window === "undefined") {
|
|
92
|
+
console.warn("[Frak] No window found, can't track purchase");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const interactionToken = window.sessionStorage.getItem(
|
|
96
|
+
"frak-wallet-interaction-token"
|
|
97
|
+
);
|
|
98
|
+
if (!interactionToken) {
|
|
99
|
+
console.warn("[Frak] No frak session found, skipping purchase check");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
await fetch("https://backend.frak.id/interactions/listenForPurchase", {
|
|
103
|
+
method: "POST",
|
|
104
|
+
headers: {
|
|
105
|
+
Accept: "application/json",
|
|
106
|
+
"Content-Type": "application/json",
|
|
107
|
+
"x-wallet-sdk-auth": interactionToken
|
|
108
|
+
},
|
|
109
|
+
body: JSON.stringify(args)
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
53
113
|
// src/core/actions/wrapper/siweAuthenticate.ts
|
|
54
114
|
import { generateSiweNonce } from "viem/siwe";
|
|
55
115
|
async function siweAuthenticate(client, { siwe, metadata }) {
|
|
116
|
+
const effectiveDomain = client.config?.domain ?? window.location.host;
|
|
56
117
|
const realStatement = siwe?.statement ?? `I confirm that I want to use my Frak wallet on: ${client.config.metadata.name}`;
|
|
57
118
|
const builtSiwe = {
|
|
58
119
|
...siwe,
|
|
59
120
|
statement: realStatement,
|
|
60
121
|
nonce: siwe?.nonce ?? generateSiweNonce(),
|
|
61
|
-
uri: siwe?.uri ?? `https://${
|
|
122
|
+
uri: siwe?.uri ?? `https://${effectiveDomain}`,
|
|
62
123
|
version: siwe?.version ?? "1",
|
|
63
|
-
domain:
|
|
124
|
+
domain: effectiveDomain
|
|
64
125
|
};
|
|
65
126
|
const result = await displayModal(client, {
|
|
66
127
|
metadata,
|
|
@@ -86,24 +147,80 @@ async function sendTransaction(client, { tx, metadata }) {
|
|
|
86
147
|
return result.sendTransaction;
|
|
87
148
|
}
|
|
88
149
|
|
|
89
|
-
// src/core/actions/wrapper/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
150
|
+
// src/core/actions/wrapper/modalBuilder.ts
|
|
151
|
+
function modalBuilder(client, {
|
|
152
|
+
metadata,
|
|
153
|
+
login,
|
|
154
|
+
openSession
|
|
155
|
+
}) {
|
|
156
|
+
const baseParams = {
|
|
157
|
+
steps: {
|
|
158
|
+
login: login ?? {},
|
|
159
|
+
openSession: openSession ?? {}
|
|
160
|
+
},
|
|
161
|
+
metadata
|
|
162
|
+
};
|
|
163
|
+
return modalStepsBuilder(client, baseParams);
|
|
164
|
+
}
|
|
165
|
+
function modalStepsBuilder(client, params) {
|
|
166
|
+
function sendTx(options) {
|
|
167
|
+
return modalStepsBuilder(client, {
|
|
168
|
+
...params,
|
|
169
|
+
steps: {
|
|
170
|
+
...params.steps,
|
|
171
|
+
sendTransaction: options
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function reward(options) {
|
|
176
|
+
return modalStepsBuilder(
|
|
177
|
+
client,
|
|
178
|
+
{
|
|
179
|
+
...params,
|
|
180
|
+
steps: {
|
|
181
|
+
...params.steps,
|
|
182
|
+
final: {
|
|
183
|
+
...options,
|
|
184
|
+
action: { key: "reward" }
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
function sharing(sharingOptions, options) {
|
|
191
|
+
return modalStepsBuilder(
|
|
192
|
+
client,
|
|
193
|
+
{
|
|
194
|
+
...params,
|
|
195
|
+
steps: {
|
|
196
|
+
...params.steps,
|
|
197
|
+
final: {
|
|
198
|
+
...options,
|
|
199
|
+
action: { key: "sharing", options: sharingOptions }
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
async function display() {
|
|
206
|
+
return await displayModal(client, params);
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
// Access current modal params
|
|
210
|
+
params,
|
|
211
|
+
// Function to add new steps
|
|
212
|
+
sendTx,
|
|
213
|
+
reward,
|
|
214
|
+
sharing,
|
|
215
|
+
// Display the modal
|
|
216
|
+
display
|
|
217
|
+
};
|
|
101
218
|
}
|
|
102
219
|
|
|
103
220
|
// src/core/actions/referral/processReferral.ts
|
|
104
221
|
import { isAddressEqual } from "viem";
|
|
105
222
|
async function processReferral(client, {
|
|
106
|
-
walletStatus
|
|
223
|
+
walletStatus,
|
|
107
224
|
frakContext,
|
|
108
225
|
modalConfig,
|
|
109
226
|
productId,
|
|
@@ -117,7 +234,7 @@ async function processReferral(client, {
|
|
|
117
234
|
walletRequest = true;
|
|
118
235
|
return ensureWalletConnected(client, {
|
|
119
236
|
modalConfig,
|
|
120
|
-
walletStatus
|
|
237
|
+
walletStatus
|
|
121
238
|
});
|
|
122
239
|
}
|
|
123
240
|
async function pushReferralInteraction(referrer) {
|
|
@@ -128,7 +245,7 @@ async function processReferral(client, {
|
|
|
128
245
|
}
|
|
129
246
|
try {
|
|
130
247
|
const { status, currentWallet } = await processReferralLogic({
|
|
131
|
-
initialWalletStatus:
|
|
248
|
+
initialWalletStatus: walletStatus,
|
|
132
249
|
getFreshWalletStatus,
|
|
133
250
|
pushReferralInteraction,
|
|
134
251
|
frakContext
|
|
@@ -142,7 +259,7 @@ async function processReferral(client, {
|
|
|
142
259
|
console.log("Error processing referral", { error });
|
|
143
260
|
FrakContextManager.replaceUrl({
|
|
144
261
|
url: window.location?.href,
|
|
145
|
-
context: options?.alwaysAppendUrl ? { r:
|
|
262
|
+
context: options?.alwaysAppendUrl ? { r: walletStatus?.wallet } : null
|
|
146
263
|
});
|
|
147
264
|
return mapErrorToState(error);
|
|
148
265
|
}
|
|
@@ -171,16 +288,16 @@ async function processReferralLogic({
|
|
|
171
288
|
}
|
|
172
289
|
async function ensureWalletConnected(client, {
|
|
173
290
|
modalConfig,
|
|
174
|
-
walletStatus
|
|
291
|
+
walletStatus
|
|
175
292
|
}) {
|
|
176
|
-
if (!
|
|
293
|
+
if (!walletStatus?.interactionSession) {
|
|
177
294
|
if (!modalConfig) {
|
|
178
295
|
return void 0;
|
|
179
296
|
}
|
|
180
297
|
const result = await displayModal(client, modalConfig);
|
|
181
298
|
return result?.login?.wallet ?? void 0;
|
|
182
299
|
}
|
|
183
|
-
return
|
|
300
|
+
return walletStatus.wallet ?? void 0;
|
|
184
301
|
}
|
|
185
302
|
function mapErrorToState(error) {
|
|
186
303
|
if (error instanceof FrakRpcError) {
|
|
@@ -205,7 +322,7 @@ async function referralInteraction(client, {
|
|
|
205
322
|
const frakContext = FrakContextManager.parse({
|
|
206
323
|
url: window.location.href
|
|
207
324
|
});
|
|
208
|
-
const currentWalletStatus = await
|
|
325
|
+
const currentWalletStatus = await watchWalletStatus(client);
|
|
209
326
|
try {
|
|
210
327
|
return await processReferral(client, {
|
|
211
328
|
walletStatus: currentWalletStatus,
|
|
@@ -224,9 +341,11 @@ export {
|
|
|
224
341
|
sendInteraction,
|
|
225
342
|
displayModal,
|
|
226
343
|
openSso,
|
|
344
|
+
getProductInformation,
|
|
345
|
+
trackPurchaseStatus,
|
|
227
346
|
siweAuthenticate,
|
|
228
347
|
sendTransaction,
|
|
229
|
-
|
|
348
|
+
modalBuilder,
|
|
230
349
|
processReferral,
|
|
231
350
|
referralInteraction
|
|
232
351
|
};
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkP3J2BIUTcjs = require('./chunk-P3J2BIUT.cjs');
|
|
5
5
|
|
|
6
6
|
// src/core/interactions/pressEncoder.ts
|
|
7
7
|
var _viem = require('viem');
|
|
8
8
|
function openArticle({ articleId }) {
|
|
9
9
|
const interactionData = _viem.concatHex.call(void 0, [
|
|
10
|
-
|
|
10
|
+
_chunkP3J2BIUTcjs.interactionTypes.press.openArticle,
|
|
11
11
|
_viem.pad.call(void 0, articleId, { size: 32 })
|
|
12
12
|
]);
|
|
13
13
|
return {
|
|
14
|
-
handlerTypeDenominator: _viem.toHex.call(void 0,
|
|
14
|
+
handlerTypeDenominator: _viem.toHex.call(void 0, _chunkP3J2BIUTcjs.productTypes.press),
|
|
15
15
|
interactionData
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
function readArticle({ articleId }) {
|
|
19
19
|
const interactionData = _viem.concatHex.call(void 0, [
|
|
20
|
-
|
|
20
|
+
_chunkP3J2BIUTcjs.interactionTypes.press.readArticle,
|
|
21
21
|
_viem.pad.call(void 0, articleId, { size: 32 })
|
|
22
22
|
]);
|
|
23
23
|
return {
|
|
24
|
-
handlerTypeDenominator: _viem.toHex.call(void 0,
|
|
24
|
+
handlerTypeDenominator: _viem.toHex.call(void 0, _chunkP3J2BIUTcjs.productTypes.press),
|
|
25
25
|
interactionData
|
|
26
26
|
};
|
|
27
27
|
}
|
|
@@ -34,21 +34,21 @@ var PressInteractionEncoder = {
|
|
|
34
34
|
|
|
35
35
|
function createLink() {
|
|
36
36
|
const interactionData = _viem.concatHex.call(void 0, [
|
|
37
|
-
|
|
37
|
+
_chunkP3J2BIUTcjs.interactionTypes.referral.createLink,
|
|
38
38
|
"0x"
|
|
39
39
|
]);
|
|
40
40
|
return {
|
|
41
|
-
handlerTypeDenominator: _viem.toHex.call(void 0,
|
|
41
|
+
handlerTypeDenominator: _viem.toHex.call(void 0, _chunkP3J2BIUTcjs.productTypes.referral),
|
|
42
42
|
interactionData
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
function referred({ referrer }) {
|
|
46
46
|
const interactionData = _viem.concatHex.call(void 0, [
|
|
47
|
-
|
|
47
|
+
_chunkP3J2BIUTcjs.interactionTypes.referral.referred,
|
|
48
48
|
_viem.pad.call(void 0, referrer, { size: 32 })
|
|
49
49
|
]);
|
|
50
50
|
return {
|
|
51
|
-
handlerTypeDenominator: _viem.toHex.call(void 0,
|
|
51
|
+
handlerTypeDenominator: _viem.toHex.call(void 0, _chunkP3J2BIUTcjs.productTypes.referral),
|
|
52
52
|
interactionData
|
|
53
53
|
};
|
|
54
54
|
}
|
|
@@ -63,11 +63,11 @@ function startPurchase({
|
|
|
63
63
|
purchaseId
|
|
64
64
|
}) {
|
|
65
65
|
const interactionData = _viem.concatHex.call(void 0, [
|
|
66
|
-
|
|
66
|
+
_chunkP3J2BIUTcjs.interactionTypes.purchase.started,
|
|
67
67
|
_viem.pad.call(void 0, purchaseId, { size: 32 })
|
|
68
68
|
]);
|
|
69
69
|
return {
|
|
70
|
-
handlerTypeDenominator: _viem.toHex.call(void 0,
|
|
70
|
+
handlerTypeDenominator: _viem.toHex.call(void 0, _chunkP3J2BIUTcjs.productTypes.purchase),
|
|
71
71
|
interactionData
|
|
72
72
|
};
|
|
73
73
|
}
|
|
@@ -80,11 +80,11 @@ function completedPurchase({
|
|
|
80
80
|
[BigInt(purchaseId), proof]
|
|
81
81
|
);
|
|
82
82
|
const interactionData = _viem.concatHex.call(void 0, [
|
|
83
|
-
|
|
83
|
+
_chunkP3J2BIUTcjs.interactionTypes.purchase.completed,
|
|
84
84
|
innerData
|
|
85
85
|
]);
|
|
86
86
|
return {
|
|
87
|
-
handlerTypeDenominator: _viem.toHex.call(void 0,
|
|
87
|
+
handlerTypeDenominator: _viem.toHex.call(void 0, _chunkP3J2BIUTcjs.productTypes.purchase),
|
|
88
88
|
interactionData
|
|
89
89
|
};
|
|
90
90
|
}
|
|
@@ -96,9 +96,9 @@ var PurchaseInteractionEncoder = {
|
|
|
96
96
|
// src/core/interactions/webshopEncoder.ts
|
|
97
97
|
|
|
98
98
|
function open() {
|
|
99
|
-
const interactionData = _viem.concatHex.call(void 0, [
|
|
99
|
+
const interactionData = _viem.concatHex.call(void 0, [_chunkP3J2BIUTcjs.interactionTypes.webshop.open, "0x"]);
|
|
100
100
|
return {
|
|
101
|
-
handlerTypeDenominator: _viem.toHex.call(void 0,
|
|
101
|
+
handlerTypeDenominator: _viem.toHex.call(void 0, _chunkP3J2BIUTcjs.productTypes.webshop),
|
|
102
102
|
interactionData
|
|
103
103
|
};
|
|
104
104
|
}
|