@frak-labs/nexus-sdk 0.0.21 → 0.0.23
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-p0Jtv9gl.d.ts → FrakContext-CDVlUN75.d.ts} +1 -0
- package/dist/{FrakContext-BsezWx2F.d.cts → FrakContext-DBdWC7ls.d.cts} +1 -0
- package/dist/bundle/bundle.js +4 -4
- package/dist/{chunk-A3XYA7S7.cjs → chunk-4OJ2NPAS.cjs} +15 -15
- package/dist/{chunk-MDGMJ6EQ.js → chunk-4Q2OHGWX.js} +134 -25
- package/dist/{chunk-BSCR57ZI.cjs → chunk-BHZDDGW6.cjs} +148 -39
- package/dist/chunk-F3F4BCGV.cjs +860 -0
- package/dist/chunk-H3T2GAEC.js +79 -0
- package/dist/{chunk-TIKEZMSD.js → chunk-P4QEVLVV.js} +1 -1
- package/dist/chunk-QSXZKZJA.cjs +79 -0
- package/dist/{chunk-WXNW7ZMU.cjs → chunk-QYOOKB34.cjs} +20 -18
- package/dist/{chunk-ZZ7LUFNV.js → chunk-VVF4NKYR.js} +3 -1
- package/dist/chunk-ZQSA2VQ4.js +860 -0
- package/dist/core/actions/index.cjs +7 -5
- package/dist/core/actions/index.d.cts +45 -6
- package/dist/core/actions/index.d.ts +45 -6
- package/dist/core/actions/index.js +8 -6
- package/dist/core/index.cjs +4 -4
- package/dist/core/index.d.cts +5 -3
- package/dist/core/index.d.ts +5 -3
- 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-YbCg90hu.d.cts → processReferral-BWSIamn2.d.cts} +1 -1
- package/dist/{processReferral-t3gUNwJu.d.ts → processReferral-CFyGAENf.d.ts} +1 -1
- package/dist/react/index.cjs +30 -30
- package/dist/react/index.d.cts +5 -2
- package/dist/react/index.d.ts +5 -2
- package/dist/react/index.js +11 -11
- package/package.json +2 -11
- package/dist/chunk-E527CMMJ.cjs +0 -294
- package/dist/chunk-HY6YATLS.js +0 -53
- package/dist/chunk-UFJ7W6CQ.cjs +0 -53
- package/dist/chunk-ZRPCX25Q.js +0 -294
|
@@ -3,19 +3,47 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkF3F4BCGVcjs = require('./chunk-F3F4BCGV.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunk4OJ2NPAScjs = require('./chunk-4OJ2NPAS.cjs');
|
|
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 (0, _chunkF3F4BCGVcjs.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
|
|
@@ -50,6 +78,30 @@ async function openSso(client, args) {
|
|
|
50
78
|
});
|
|
51
79
|
}
|
|
52
80
|
|
|
81
|
+
// src/core/actions/trackPurchaseStatus.ts
|
|
82
|
+
async function trackPurchaseStatus(args) {
|
|
83
|
+
if (typeof window === "undefined") {
|
|
84
|
+
console.warn("[Frak] No window found, can't track purchase");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const interactionToken = window.sessionStorage.getItem(
|
|
88
|
+
"frak-wallet-interaction-token"
|
|
89
|
+
);
|
|
90
|
+
if (!interactionToken) {
|
|
91
|
+
console.warn("[Frak] No frak session found, skipping purchase check");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
await fetch("https://backend.frak.id/interactions/listenForPurchase", {
|
|
95
|
+
method: "POST",
|
|
96
|
+
headers: {
|
|
97
|
+
Accept: "application/json",
|
|
98
|
+
"Content-Type": "application/json",
|
|
99
|
+
"x-wallet-sdk-auth": interactionToken
|
|
100
|
+
},
|
|
101
|
+
body: JSON.stringify(args)
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
53
105
|
// src/core/actions/wrapper/siweAuthenticate.ts
|
|
54
106
|
var _siwe = require('viem/siwe');
|
|
55
107
|
async function siweAuthenticate(client, { siwe, metadata }) {
|
|
@@ -86,24 +138,80 @@ async function sendTransaction(client, { tx, metadata }) {
|
|
|
86
138
|
return result.sendTransaction;
|
|
87
139
|
}
|
|
88
140
|
|
|
89
|
-
// src/core/actions/wrapper/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
141
|
+
// src/core/actions/wrapper/modalBuilder.ts
|
|
142
|
+
function modalBuilder(client, {
|
|
143
|
+
metadata,
|
|
144
|
+
login,
|
|
145
|
+
openSession
|
|
146
|
+
}) {
|
|
147
|
+
const baseParams = {
|
|
148
|
+
steps: {
|
|
149
|
+
login: _nullishCoalesce(login, () => ( {})),
|
|
150
|
+
openSession: _nullishCoalesce(openSession, () => ( {}))
|
|
151
|
+
},
|
|
152
|
+
metadata
|
|
153
|
+
};
|
|
154
|
+
return modalStepsBuilder(client, baseParams);
|
|
155
|
+
}
|
|
156
|
+
function modalStepsBuilder(client, params) {
|
|
157
|
+
function sendTx(options) {
|
|
158
|
+
return modalStepsBuilder(client, {
|
|
159
|
+
...params,
|
|
160
|
+
steps: {
|
|
161
|
+
...params.steps,
|
|
162
|
+
sendTransaction: options
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function reward(options) {
|
|
167
|
+
return modalStepsBuilder(
|
|
168
|
+
client,
|
|
169
|
+
{
|
|
170
|
+
...params,
|
|
171
|
+
steps: {
|
|
172
|
+
...params.steps,
|
|
173
|
+
final: {
|
|
174
|
+
...options,
|
|
175
|
+
action: { key: "reward" }
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
function sharing(sharingOptions, options) {
|
|
182
|
+
return modalStepsBuilder(
|
|
183
|
+
client,
|
|
184
|
+
{
|
|
185
|
+
...params,
|
|
186
|
+
steps: {
|
|
187
|
+
...params.steps,
|
|
188
|
+
final: {
|
|
189
|
+
...options,
|
|
190
|
+
action: { key: "sharing", options: sharingOptions }
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
async function display() {
|
|
197
|
+
return await displayModal(client, params);
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
// Access current modal params
|
|
201
|
+
params,
|
|
202
|
+
// Function to add new steps
|
|
203
|
+
sendTx,
|
|
204
|
+
reward,
|
|
205
|
+
sharing,
|
|
206
|
+
// Display the modal
|
|
207
|
+
display
|
|
208
|
+
};
|
|
101
209
|
}
|
|
102
210
|
|
|
103
211
|
// src/core/actions/referral/processReferral.ts
|
|
104
212
|
|
|
105
213
|
async function processReferral(client, {
|
|
106
|
-
walletStatus
|
|
214
|
+
walletStatus,
|
|
107
215
|
frakContext,
|
|
108
216
|
modalConfig,
|
|
109
217
|
productId,
|
|
@@ -117,32 +225,32 @@ async function processReferral(client, {
|
|
|
117
225
|
walletRequest = true;
|
|
118
226
|
return ensureWalletConnected(client, {
|
|
119
227
|
modalConfig,
|
|
120
|
-
walletStatus
|
|
228
|
+
walletStatus
|
|
121
229
|
});
|
|
122
230
|
}
|
|
123
231
|
async function pushReferralInteraction(referrer) {
|
|
124
|
-
const interaction =
|
|
232
|
+
const interaction = _chunk4OJ2NPAScjs.ReferralInteractionEncoder.referred({
|
|
125
233
|
referrer
|
|
126
234
|
});
|
|
127
235
|
await sendInteraction(client, { productId, interaction });
|
|
128
236
|
}
|
|
129
237
|
try {
|
|
130
238
|
const { status, currentWallet } = await processReferralLogic({
|
|
131
|
-
initialWalletStatus:
|
|
239
|
+
initialWalletStatus: walletStatus,
|
|
132
240
|
getFreshWalletStatus,
|
|
133
241
|
pushReferralInteraction,
|
|
134
242
|
frakContext
|
|
135
243
|
});
|
|
136
|
-
|
|
137
|
-
url: _optionalChain([window, 'access',
|
|
138
|
-
context: _optionalChain([options, 'optionalAccess',
|
|
244
|
+
_chunkF3F4BCGVcjs.FrakContextManager.replaceUrl({
|
|
245
|
+
url: _optionalChain([window, 'access', _5 => _5.location, 'optionalAccess', _6 => _6.href]),
|
|
246
|
+
context: _optionalChain([options, 'optionalAccess', _7 => _7.alwaysAppendUrl]) ? { r: currentWallet } : null
|
|
139
247
|
});
|
|
140
248
|
return status;
|
|
141
249
|
} catch (error) {
|
|
142
250
|
console.log("Error processing referral", { error });
|
|
143
|
-
|
|
144
|
-
url: _optionalChain([window, 'access',
|
|
145
|
-
context: _optionalChain([options, 'optionalAccess',
|
|
251
|
+
_chunkF3F4BCGVcjs.FrakContextManager.replaceUrl({
|
|
252
|
+
url: _optionalChain([window, 'access', _8 => _8.location, 'optionalAccess', _9 => _9.href]),
|
|
253
|
+
context: _optionalChain([options, 'optionalAccess', _10 => _10.alwaysAppendUrl]) ? { r: _optionalChain([walletStatus, 'optionalAccess', _11 => _11.wallet]) } : null
|
|
146
254
|
});
|
|
147
255
|
return mapErrorToState(error);
|
|
148
256
|
}
|
|
@@ -153,8 +261,8 @@ async function processReferralLogic({
|
|
|
153
261
|
pushReferralInteraction,
|
|
154
262
|
frakContext
|
|
155
263
|
}) {
|
|
156
|
-
let currentWallet = _optionalChain([initialWalletStatus, 'optionalAccess',
|
|
157
|
-
if (!_optionalChain([frakContext, 'optionalAccess',
|
|
264
|
+
let currentWallet = _optionalChain([initialWalletStatus, 'optionalAccess', _12 => _12.wallet]);
|
|
265
|
+
if (!_optionalChain([frakContext, 'optionalAccess', _13 => _13.r])) {
|
|
158
266
|
return { status: "no-referrer", currentWallet };
|
|
159
267
|
}
|
|
160
268
|
if (!currentWallet) {
|
|
@@ -163,7 +271,7 @@ async function processReferralLogic({
|
|
|
163
271
|
if (currentWallet && _viem.isAddressEqual.call(void 0, frakContext.r, currentWallet)) {
|
|
164
272
|
return { status: "self-referral", currentWallet };
|
|
165
273
|
}
|
|
166
|
-
if (!_optionalChain([initialWalletStatus, 'optionalAccess',
|
|
274
|
+
if (!_optionalChain([initialWalletStatus, 'optionalAccess', _14 => _14.interactionSession])) {
|
|
167
275
|
currentWallet = await getFreshWalletStatus();
|
|
168
276
|
}
|
|
169
277
|
await pushReferralInteraction(frakContext.r);
|
|
@@ -171,23 +279,23 @@ async function processReferralLogic({
|
|
|
171
279
|
}
|
|
172
280
|
async function ensureWalletConnected(client, {
|
|
173
281
|
modalConfig,
|
|
174
|
-
walletStatus
|
|
282
|
+
walletStatus
|
|
175
283
|
}) {
|
|
176
|
-
if (!_optionalChain([
|
|
284
|
+
if (!_optionalChain([walletStatus, 'optionalAccess', _15 => _15.interactionSession])) {
|
|
177
285
|
if (!modalConfig) {
|
|
178
286
|
return void 0;
|
|
179
287
|
}
|
|
180
288
|
const result = await displayModal(client, modalConfig);
|
|
181
|
-
return _nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
289
|
+
return _nullishCoalesce(_optionalChain([result, 'optionalAccess', _16 => _16.login, 'optionalAccess', _17 => _17.wallet]), () => ( void 0));
|
|
182
290
|
}
|
|
183
|
-
return _nullishCoalesce(
|
|
291
|
+
return _nullishCoalesce(walletStatus.wallet, () => ( void 0));
|
|
184
292
|
}
|
|
185
293
|
function mapErrorToState(error) {
|
|
186
|
-
if (error instanceof
|
|
294
|
+
if (error instanceof _chunkF3F4BCGVcjs.FrakRpcError) {
|
|
187
295
|
switch (error.code) {
|
|
188
|
-
case
|
|
296
|
+
case _chunkF3F4BCGVcjs.RpcErrorCodes.walletNotConnected:
|
|
189
297
|
return "no-wallet";
|
|
190
|
-
case
|
|
298
|
+
case _chunkF3F4BCGVcjs.RpcErrorCodes.serverErrorForInteractionDelegation:
|
|
191
299
|
return "no-session";
|
|
192
300
|
default:
|
|
193
301
|
return "error";
|
|
@@ -202,10 +310,10 @@ async function referralInteraction(client, {
|
|
|
202
310
|
modalConfig,
|
|
203
311
|
options
|
|
204
312
|
} = {}) {
|
|
205
|
-
const frakContext =
|
|
313
|
+
const frakContext = _chunkF3F4BCGVcjs.FrakContextManager.parse({
|
|
206
314
|
url: window.location.href
|
|
207
315
|
});
|
|
208
|
-
const currentWalletStatus = await
|
|
316
|
+
const currentWalletStatus = await watchWalletStatus(client);
|
|
209
317
|
try {
|
|
210
318
|
return await processReferral(client, {
|
|
211
319
|
walletStatus: currentWalletStatus,
|
|
@@ -229,4 +337,5 @@ async function referralInteraction(client, {
|
|
|
229
337
|
|
|
230
338
|
|
|
231
339
|
|
|
232
|
-
|
|
340
|
+
|
|
341
|
+
exports.watchWalletStatus = watchWalletStatus; exports.sendInteraction = sendInteraction; exports.displayModal = displayModal; exports.openSso = openSso; exports.trackPurchaseStatus = trackPurchaseStatus; exports.siweAuthenticate = siweAuthenticate; exports.sendTransaction = sendTransaction; exports.modalBuilder = modalBuilder; exports.processReferral = processReferral; exports.referralInteraction = referralInteraction;
|