@frak-labs/core-sdk 0.0.7 → 0.0.9
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/cdn/bundle.js +17 -31
- package/cdn/bundle.js.LICENSE.txt +10 -0
- package/dist/actions.cjs +1 -0
- package/dist/actions.d.cts +1300 -0
- package/dist/actions.d.ts +1300 -0
- package/dist/actions.js +1 -0
- package/dist/index.cjs +11 -487
- package/dist/index.d.cts +1207 -255
- package/dist/index.d.ts +1207 -255
- package/dist/index.js +11 -428
- package/dist/interactions.cjs +1 -0
- package/dist/{interactions/index.d.ts → interactions.d.cts} +182 -174
- package/dist/{interactions/index.d.cts → interactions.d.ts} +182 -174
- package/dist/interactions.js +1 -0
- package/package.json +15 -15
- package/dist/actions/index.cjs +0 -350
- package/dist/actions/index.d.cts +0 -501
- package/dist/actions/index.d.ts +0 -501
- package/dist/actions/index.js +0 -337
- package/dist/chunk-665P7NO4.cjs +0 -81
- package/dist/chunk-7YDJDVXY.cjs +0 -833
- package/dist/chunk-GTBCSNLF.js +0 -819
- package/dist/chunk-PHVGCFDX.cjs +0 -155
- package/dist/chunk-U2NTN5QZ.js +0 -75
- package/dist/chunk-VE6URIIJ.js +0 -149
- package/dist/context-D7aZDKLT.d.cts +0 -813
- package/dist/context-rDsQbSgB.d.ts +0 -813
- package/dist/interaction-CTQ5-kqe.d.cts +0 -43
- package/dist/interaction-CTQ5-kqe.d.ts +0 -43
- package/dist/interactions/index.cjs +0 -26
- package/dist/interactions/index.js +0 -1
package/dist/actions/index.js
DELETED
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
import { Deferred, FrakContextManager, FrakRpcError, RpcErrorCodes } from '../chunk-GTBCSNLF.js';
|
|
2
|
-
import { ReferralInteractionEncoder } from '../chunk-VE6URIIJ.js';
|
|
3
|
-
import { isAddressEqual, keccak256, toHex } from 'viem';
|
|
4
|
-
import { generateSiweNonce } from 'viem/siwe';
|
|
5
|
-
|
|
6
|
-
// src/actions/watchWalletStatus.ts
|
|
7
|
-
function watchWalletStatus(client, callback) {
|
|
8
|
-
if (!callback) {
|
|
9
|
-
return client.request({ method: "frak_listenToWalletStatus" }).then((result) => {
|
|
10
|
-
savePotentialToken(result.interactionToken);
|
|
11
|
-
return result;
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
const firstResult = new Deferred();
|
|
15
|
-
let hasResolved = false;
|
|
16
|
-
return client.listenerRequest(
|
|
17
|
-
{
|
|
18
|
-
method: "frak_listenToWalletStatus"
|
|
19
|
-
},
|
|
20
|
-
(status) => {
|
|
21
|
-
callback(status);
|
|
22
|
-
savePotentialToken(status.interactionToken);
|
|
23
|
-
if (!hasResolved) {
|
|
24
|
-
firstResult.resolve(status);
|
|
25
|
-
hasResolved = true;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
).then(() => firstResult.promise);
|
|
29
|
-
}
|
|
30
|
-
function savePotentialToken(interactionToken) {
|
|
31
|
-
if (typeof window === "undefined") {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (interactionToken) {
|
|
35
|
-
window.sessionStorage.setItem(
|
|
36
|
-
"frak-wallet-interaction-token",
|
|
37
|
-
interactionToken
|
|
38
|
-
);
|
|
39
|
-
} else {
|
|
40
|
-
window.sessionStorage.removeItem("frak.interaction-token");
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function computeProductId({ domain }) {
|
|
44
|
-
const effectiveDomain = domain ?? window.location.host;
|
|
45
|
-
return keccak256(toHex(effectiveDomain));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// src/actions/sendInteraction.ts
|
|
49
|
-
async function sendInteraction(client, { productId, interaction, validation }) {
|
|
50
|
-
const pId = productId ?? computeProductId(client.config);
|
|
51
|
-
return await client.request({
|
|
52
|
-
method: "frak_sendInteraction",
|
|
53
|
-
params: [pId, interaction, validation]
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// src/actions/displayModal.ts
|
|
58
|
-
async function displayModal(client, { steps, metadata }) {
|
|
59
|
-
return await client.request({
|
|
60
|
-
method: "frak_displayModal",
|
|
61
|
-
params: [steps, client.config.metadata.name, metadata]
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// src/actions/displayEmbededWallet.ts
|
|
66
|
-
async function displayEmbededWallet(client, params) {
|
|
67
|
-
await client.request({
|
|
68
|
-
method: "frak_displayEmbededWallet",
|
|
69
|
-
params: [params, client.config.metadata.name]
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// src/actions/openSso.ts
|
|
74
|
-
async function openSso(client, args) {
|
|
75
|
-
const { metadata } = client.config;
|
|
76
|
-
await client.request({
|
|
77
|
-
method: "frak_sso",
|
|
78
|
-
params: [args, metadata.name, metadata.css]
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// src/actions/getProductInformation.ts
|
|
83
|
-
async function getProductInformation(client) {
|
|
84
|
-
return await client.request({
|
|
85
|
-
method: "frak_getProductInformation"
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// src/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
|
-
async function siweAuthenticate(client, { siwe, metadata }) {
|
|
113
|
-
const effectiveDomain = client.config?.domain ?? window.location.host;
|
|
114
|
-
const realStatement = siwe?.statement ?? `I confirm that I want to use my Frak wallet on: ${client.config.metadata.name}`;
|
|
115
|
-
const builtSiwe = {
|
|
116
|
-
...siwe,
|
|
117
|
-
statement: realStatement,
|
|
118
|
-
nonce: siwe?.nonce ?? generateSiweNonce(),
|
|
119
|
-
uri: siwe?.uri ?? `https://${effectiveDomain}`,
|
|
120
|
-
version: siwe?.version ?? "1",
|
|
121
|
-
domain: effectiveDomain
|
|
122
|
-
};
|
|
123
|
-
const result = await displayModal(client, {
|
|
124
|
-
metadata,
|
|
125
|
-
steps: {
|
|
126
|
-
login: {},
|
|
127
|
-
siweAuthenticate: {
|
|
128
|
-
siwe: builtSiwe
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
return result.siweAuthenticate;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// src/actions/wrapper/sendTransaction.ts
|
|
136
|
-
async function sendTransaction(client, { tx, metadata }) {
|
|
137
|
-
const result = await displayModal(client, {
|
|
138
|
-
metadata,
|
|
139
|
-
steps: {
|
|
140
|
-
login: {},
|
|
141
|
-
sendTransaction: { tx }
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
return result.sendTransaction;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// src/actions/wrapper/modalBuilder.ts
|
|
148
|
-
function modalBuilder(client, {
|
|
149
|
-
metadata,
|
|
150
|
-
login,
|
|
151
|
-
openSession
|
|
152
|
-
}) {
|
|
153
|
-
const baseParams = {
|
|
154
|
-
steps: {
|
|
155
|
-
login: login ?? {},
|
|
156
|
-
openSession: openSession ?? {}
|
|
157
|
-
},
|
|
158
|
-
metadata
|
|
159
|
-
};
|
|
160
|
-
return modalStepsBuilder(client, baseParams);
|
|
161
|
-
}
|
|
162
|
-
function modalStepsBuilder(client, params) {
|
|
163
|
-
function sendTx(options) {
|
|
164
|
-
return modalStepsBuilder(client, {
|
|
165
|
-
...params,
|
|
166
|
-
steps: {
|
|
167
|
-
...params.steps,
|
|
168
|
-
sendTransaction: options
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
function reward(options) {
|
|
173
|
-
return modalStepsBuilder(
|
|
174
|
-
client,
|
|
175
|
-
{
|
|
176
|
-
...params,
|
|
177
|
-
steps: {
|
|
178
|
-
...params.steps,
|
|
179
|
-
final: {
|
|
180
|
-
...options,
|
|
181
|
-
action: { key: "reward" }
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
function sharing(sharingOptions, options) {
|
|
188
|
-
return modalStepsBuilder(
|
|
189
|
-
client,
|
|
190
|
-
{
|
|
191
|
-
...params,
|
|
192
|
-
steps: {
|
|
193
|
-
...params.steps,
|
|
194
|
-
final: {
|
|
195
|
-
...options,
|
|
196
|
-
action: { key: "sharing", options: sharingOptions }
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
async function display(metadataOverride) {
|
|
203
|
-
if (metadataOverride) {
|
|
204
|
-
params.metadata = metadataOverride(params.metadata ?? {});
|
|
205
|
-
}
|
|
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
|
-
};
|
|
218
|
-
}
|
|
219
|
-
async function processReferral(client, {
|
|
220
|
-
walletStatus,
|
|
221
|
-
frakContext,
|
|
222
|
-
modalConfig,
|
|
223
|
-
productId,
|
|
224
|
-
options
|
|
225
|
-
}) {
|
|
226
|
-
let walletRequest = false;
|
|
227
|
-
async function getFreshWalletStatus() {
|
|
228
|
-
if (walletRequest) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
walletRequest = true;
|
|
232
|
-
return ensureWalletConnected(client, {
|
|
233
|
-
modalConfig,
|
|
234
|
-
walletStatus
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
async function pushReferralInteraction(referrer) {
|
|
238
|
-
const interaction = ReferralInteractionEncoder.referred({
|
|
239
|
-
referrer
|
|
240
|
-
});
|
|
241
|
-
await sendInteraction(client, { productId, interaction });
|
|
242
|
-
}
|
|
243
|
-
try {
|
|
244
|
-
const { status, currentWallet } = await processReferralLogic({
|
|
245
|
-
initialWalletStatus: walletStatus,
|
|
246
|
-
getFreshWalletStatus,
|
|
247
|
-
pushReferralInteraction,
|
|
248
|
-
frakContext
|
|
249
|
-
});
|
|
250
|
-
FrakContextManager.replaceUrl({
|
|
251
|
-
url: window.location?.href,
|
|
252
|
-
context: options?.alwaysAppendUrl ? { r: currentWallet } : null
|
|
253
|
-
});
|
|
254
|
-
return status;
|
|
255
|
-
} catch (error) {
|
|
256
|
-
console.log("Error processing referral", { error });
|
|
257
|
-
FrakContextManager.replaceUrl({
|
|
258
|
-
url: window.location?.href,
|
|
259
|
-
context: options?.alwaysAppendUrl ? { r: walletStatus?.wallet } : null
|
|
260
|
-
});
|
|
261
|
-
return mapErrorToState(error);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
async function processReferralLogic({
|
|
265
|
-
initialWalletStatus,
|
|
266
|
-
getFreshWalletStatus,
|
|
267
|
-
pushReferralInteraction,
|
|
268
|
-
frakContext
|
|
269
|
-
}) {
|
|
270
|
-
let currentWallet = initialWalletStatus?.wallet;
|
|
271
|
-
if (!frakContext?.r) {
|
|
272
|
-
return { status: "no-referrer", currentWallet };
|
|
273
|
-
}
|
|
274
|
-
if (!currentWallet) {
|
|
275
|
-
currentWallet = await getFreshWalletStatus();
|
|
276
|
-
}
|
|
277
|
-
if (currentWallet && isAddressEqual(frakContext.r, currentWallet)) {
|
|
278
|
-
return { status: "self-referral", currentWallet };
|
|
279
|
-
}
|
|
280
|
-
if (!initialWalletStatus?.interactionSession) {
|
|
281
|
-
currentWallet = await getFreshWalletStatus();
|
|
282
|
-
}
|
|
283
|
-
await pushReferralInteraction(frakContext.r);
|
|
284
|
-
return { status: "success", currentWallet };
|
|
285
|
-
}
|
|
286
|
-
async function ensureWalletConnected(client, {
|
|
287
|
-
modalConfig,
|
|
288
|
-
walletStatus
|
|
289
|
-
}) {
|
|
290
|
-
if (!walletStatus?.interactionSession) {
|
|
291
|
-
if (!modalConfig) {
|
|
292
|
-
return undefined;
|
|
293
|
-
}
|
|
294
|
-
const result = await displayModal(client, modalConfig);
|
|
295
|
-
return result?.login?.wallet ?? undefined;
|
|
296
|
-
}
|
|
297
|
-
return walletStatus.wallet ?? undefined;
|
|
298
|
-
}
|
|
299
|
-
function mapErrorToState(error) {
|
|
300
|
-
if (error instanceof FrakRpcError) {
|
|
301
|
-
switch (error.code) {
|
|
302
|
-
case RpcErrorCodes.walletNotConnected:
|
|
303
|
-
return "no-wallet";
|
|
304
|
-
case RpcErrorCodes.serverErrorForInteractionDelegation:
|
|
305
|
-
return "no-session";
|
|
306
|
-
default:
|
|
307
|
-
return "error";
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
return "error";
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// src/actions/referral/referralInteraction.ts
|
|
314
|
-
async function referralInteraction(client, {
|
|
315
|
-
productId,
|
|
316
|
-
modalConfig,
|
|
317
|
-
options
|
|
318
|
-
} = {}) {
|
|
319
|
-
const frakContext = FrakContextManager.parse({
|
|
320
|
-
url: window.location.href
|
|
321
|
-
});
|
|
322
|
-
const currentWalletStatus = await watchWalletStatus(client);
|
|
323
|
-
try {
|
|
324
|
-
return await processReferral(client, {
|
|
325
|
-
walletStatus: currentWalletStatus,
|
|
326
|
-
frakContext,
|
|
327
|
-
modalConfig,
|
|
328
|
-
productId,
|
|
329
|
-
options
|
|
330
|
-
});
|
|
331
|
-
} catch (error) {
|
|
332
|
-
console.warn("Error processing referral", { error });
|
|
333
|
-
}
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
export { displayEmbededWallet, displayModal, getProductInformation, modalBuilder, openSso, processReferral, referralInteraction, sendInteraction, sendTransaction, siweAuthenticate, trackPurchaseStatus, watchWalletStatus };
|
package/dist/chunk-665P7NO4.cjs
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
|
|
29
|
-
// src/constants/productTypes.ts
|
|
30
|
-
var productTypes = {
|
|
31
|
-
// content type
|
|
32
|
-
dapp: 1,
|
|
33
|
-
press: 2,
|
|
34
|
-
webshop: 3,
|
|
35
|
-
retail: 4,
|
|
36
|
-
// feature type
|
|
37
|
-
referral: 30,
|
|
38
|
-
purchase: 31
|
|
39
|
-
};
|
|
40
|
-
var productTypesMask = Object.entries(
|
|
41
|
-
productTypes
|
|
42
|
-
).reduce(
|
|
43
|
-
(acc, [key, value]) => {
|
|
44
|
-
acc[key] = BigInt(1) << BigInt(value);
|
|
45
|
-
return acc;
|
|
46
|
-
},
|
|
47
|
-
{}
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
// src/constants/interactionTypes.ts
|
|
51
|
-
var interactionTypes = {
|
|
52
|
-
press: {
|
|
53
|
-
openArticle: "0xc0a24ffb",
|
|
54
|
-
readArticle: "0xd5bd0fbe"
|
|
55
|
-
},
|
|
56
|
-
dapp: {
|
|
57
|
-
proofVerifiableStorageUpdate: "0x2ab2aeef",
|
|
58
|
-
callableVerifiableStorageUpdate: "0xa07da986"
|
|
59
|
-
},
|
|
60
|
-
webshop: {
|
|
61
|
-
open: "0xb311798f"
|
|
62
|
-
},
|
|
63
|
-
referral: {
|
|
64
|
-
referred: "0x010cc3b9",
|
|
65
|
-
createLink: "0xb2c0f17c"
|
|
66
|
-
},
|
|
67
|
-
purchase: {
|
|
68
|
-
started: "0xd87e90c3",
|
|
69
|
-
completed: "0x8403aeb4",
|
|
70
|
-
unsafeCompleted: "0x4d5b14e0"
|
|
71
|
-
},
|
|
72
|
-
retail: {
|
|
73
|
-
customerMeeting: "0x74489004"
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
exports.__commonJS = __commonJS;
|
|
78
|
-
exports.__toESM = __toESM;
|
|
79
|
-
exports.interactionTypes = interactionTypes;
|
|
80
|
-
exports.productTypes = productTypes;
|
|
81
|
-
exports.productTypesMask = productTypesMask;
|