@frak-labs/nexus-sdk 0.0.20 → 0.0.22

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.
Files changed (38) hide show
  1. package/dist/{client-ALy_TEwJ.d.ts → FrakContext-CDVlUN75.d.ts} +9 -1
  2. package/dist/{client-DaEox5q4.d.cts → FrakContext-DBdWC7ls.d.cts} +9 -1
  3. package/dist/bundle/bundle.js +3 -3
  4. package/dist/{chunk-QRECYKIR.cjs → chunk-4CWA7EWX.cjs} +68 -48
  5. package/dist/{chunk-A3XYA7S7.cjs → chunk-4OJ2NPAS.cjs} +15 -15
  6. package/dist/chunk-F3F4BCGV.cjs +860 -0
  7. package/dist/chunk-H3T2GAEC.js +79 -0
  8. package/dist/{chunk-TIKEZMSD.js → chunk-P4QEVLVV.js} +1 -1
  9. package/dist/{chunk-6LI5YIZB.js → chunk-Q3SIIAX2.js} +60 -40
  10. package/dist/chunk-QSXZKZJA.cjs +79 -0
  11. package/dist/{chunk-2SDBW6QC.cjs → chunk-QYOOKB34.cjs} +20 -18
  12. package/dist/{chunk-54MUKMZK.js → chunk-VVF4NKYR.js} +3 -1
  13. package/dist/chunk-ZQSA2VQ4.js +860 -0
  14. package/dist/core/actions/index.cjs +5 -5
  15. package/dist/core/actions/index.d.cts +6 -21
  16. package/dist/core/actions/index.d.ts +6 -21
  17. package/dist/core/actions/index.js +4 -4
  18. package/dist/core/index.cjs +4 -4
  19. package/dist/core/index.d.cts +8 -7
  20. package/dist/core/index.d.ts +8 -7
  21. package/dist/core/index.js +3 -3
  22. package/dist/core/interactions/index.cjs +3 -3
  23. package/dist/core/interactions/index.js +2 -2
  24. package/dist/processReferral-BWSIamn2.d.cts +53 -0
  25. package/dist/processReferral-CFyGAENf.d.ts +53 -0
  26. package/dist/react/index.cjs +31 -28
  27. package/dist/react/index.d.cts +8 -3
  28. package/dist/react/index.d.ts +8 -3
  29. package/dist/react/index.js +10 -7
  30. package/package.json +2 -11
  31. package/dist/FrakContext-LbQht1ep.d.cts +0 -10
  32. package/dist/FrakContext-LbQht1ep.d.ts +0 -10
  33. package/dist/chunk-7K4L7VQC.js +0 -288
  34. package/dist/chunk-HY6YATLS.js +0 -53
  35. package/dist/chunk-UFJ7W6CQ.cjs +0 -53
  36. package/dist/chunk-YDZBXUC4.cjs +0 -288
  37. package/dist/sendTransaction-BOd-pvXr.d.ts +0 -30
  38. package/dist/sendTransaction-MhdJPTWd.d.cts +0 -30
@@ -0,0 +1,79 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
28
+
29
+ // src/core/constants/productTypes.ts
30
+ var productTypes = {
31
+ // content type
32
+ dapp: 1,
33
+ press: 2,
34
+ webshop: 3,
35
+ // feature type
36
+ referral: 30,
37
+ purchase: 31
38
+ };
39
+ var productTypesMask = Object.entries(
40
+ productTypes
41
+ ).reduce(
42
+ (acc, [key, value]) => {
43
+ acc[key] = BigInt(1) << BigInt(value);
44
+ return acc;
45
+ },
46
+ {}
47
+ );
48
+
49
+ // src/core/constants/interactionTypes.ts
50
+ var interactionTypes = {
51
+ press: {
52
+ openArticle: "0xc0a24ffb",
53
+ readArticle: "0xd5bd0fbe"
54
+ },
55
+ dapp: {
56
+ proofVerifiableStorageUpdate: "0x2ab2aeef",
57
+ callableVerifiableStorageUpdate: "0xa07da986"
58
+ },
59
+ webshop: {
60
+ open: "0xb311798f"
61
+ },
62
+ referral: {
63
+ referred: "0x010cc3b9",
64
+ createLink: "0xb2c0f17c"
65
+ },
66
+ purchase: {
67
+ started: "0xd87e90c3",
68
+ completed: "0x8403aeb4"
69
+ }
70
+ };
71
+
72
+ export {
73
+ __commonJS,
74
+ __toESM,
75
+ __publicField,
76
+ productTypes,
77
+ productTypesMask,
78
+ interactionTypes
79
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  interactionTypes,
3
3
  productTypes
4
- } from "./chunk-HY6YATLS.js";
4
+ } from "./chunk-H3T2GAEC.js";
5
5
 
6
6
  // src/core/interactions/pressEncoder.ts
7
7
  import { concatHex, pad, toHex } from "viem";
@@ -3,10 +3,10 @@ import {
3
3
  FrakContextManager,
4
4
  FrakRpcError,
5
5
  RpcErrorCodes
6
- } from "./chunk-7K4L7VQC.js";
6
+ } from "./chunk-ZQSA2VQ4.js";
7
7
  import {
8
8
  ReferralInteractionEncoder
9
- } from "./chunk-TIKEZMSD.js";
9
+ } from "./chunk-P4QEVLVV.js";
10
10
 
11
11
  // src/core/actions/watchWalletStatus.ts
12
12
  function watchWalletStatus(client, callback) {
@@ -106,51 +106,69 @@ async function processReferral(client, {
106
106
  walletStatus: walletStatus2,
107
107
  frakContext,
108
108
  modalConfig,
109
- productId
109
+ productId,
110
+ options
110
111
  }) {
111
- try {
112
- let currentWallet = walletStatus2?.wallet;
113
- if (!frakContext?.r) {
114
- if (currentWallet) {
115
- FrakContextManager.replaceUrl({
116
- url: window.location?.href,
117
- context: { r: currentWallet }
118
- });
119
- }
120
- return "no-referrer";
121
- }
122
- let walletRequested = false;
123
- if (!currentWallet) {
124
- currentWallet = await ensureWalletConnected(client, {
125
- modalConfig,
126
- walletStatus: walletStatus2
127
- });
128
- walletRequested = true;
129
- }
130
- if (currentWallet && isAddressEqual(frakContext.r, currentWallet)) {
131
- return "self-referral";
132
- }
133
- if (!(walletStatus2?.interactionSession || walletRequested)) {
134
- currentWallet = await ensureWalletConnected(client, {
135
- modalConfig,
136
- walletStatus: walletStatus2
137
- });
138
- }
139
- if (currentWallet) {
140
- FrakContextManager.replaceUrl({
141
- url: window.location?.href,
142
- context: { r: currentWallet }
143
- });
112
+ let walletRequest = false;
113
+ async function getFreshWalletStatus() {
114
+ if (walletRequest) {
115
+ return;
144
116
  }
117
+ walletRequest = true;
118
+ return ensureWalletConnected(client, {
119
+ modalConfig,
120
+ walletStatus: walletStatus2
121
+ });
122
+ }
123
+ async function pushReferralInteraction(referrer) {
145
124
  const interaction = ReferralInteractionEncoder.referred({
146
- referrer: frakContext.r
125
+ referrer
147
126
  });
148
127
  await sendInteraction(client, { productId, interaction });
149
- return "success";
128
+ }
129
+ try {
130
+ const { status, currentWallet } = await processReferralLogic({
131
+ initialWalletStatus: walletStatus2,
132
+ getFreshWalletStatus,
133
+ pushReferralInteraction,
134
+ frakContext
135
+ });
136
+ FrakContextManager.replaceUrl({
137
+ url: window.location?.href,
138
+ context: options?.alwaysAppendUrl ? { r: currentWallet } : null
139
+ });
140
+ return status;
150
141
  } catch (error) {
142
+ console.log("Error processing referral", { error });
143
+ FrakContextManager.replaceUrl({
144
+ url: window.location?.href,
145
+ context: options?.alwaysAppendUrl ? { r: walletStatus2?.wallet } : null
146
+ });
151
147
  return mapErrorToState(error);
152
148
  }
153
149
  }
150
+ async function processReferralLogic({
151
+ initialWalletStatus,
152
+ getFreshWalletStatus,
153
+ pushReferralInteraction,
154
+ frakContext
155
+ }) {
156
+ let currentWallet = initialWalletStatus?.wallet;
157
+ if (!frakContext?.r) {
158
+ return { status: "no-referrer", currentWallet };
159
+ }
160
+ if (!currentWallet) {
161
+ currentWallet = await getFreshWalletStatus();
162
+ }
163
+ if (currentWallet && isAddressEqual(frakContext.r, currentWallet)) {
164
+ return { status: "self-referral", currentWallet };
165
+ }
166
+ if (!initialWalletStatus?.interactionSession) {
167
+ currentWallet = await getFreshWalletStatus();
168
+ }
169
+ await pushReferralInteraction(frakContext.r);
170
+ return { status: "success", currentWallet };
171
+ }
154
172
  async function ensureWalletConnected(client, {
155
173
  modalConfig,
156
174
  walletStatus: walletStatus2
@@ -181,7 +199,8 @@ function mapErrorToState(error) {
181
199
  // src/core/actions/referral/referralInteraction.ts
182
200
  async function referralInteraction(client, {
183
201
  productId,
184
- modalConfig
202
+ modalConfig,
203
+ options
185
204
  } = {}) {
186
205
  const frakContext = FrakContextManager.parse({
187
206
  url: window.location.href
@@ -192,7 +211,8 @@ async function referralInteraction(client, {
192
211
  walletStatus: currentWalletStatus,
193
212
  frakContext,
194
213
  modalConfig,
195
- productId
214
+ productId,
215
+ options
196
216
  });
197
217
  } catch (error) {
198
218
  return error;
@@ -0,0 +1,79 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
28
+
29
+ // src/core/constants/productTypes.ts
30
+ var productTypes = {
31
+ // content type
32
+ dapp: 1,
33
+ press: 2,
34
+ webshop: 3,
35
+ // feature type
36
+ referral: 30,
37
+ purchase: 31
38
+ };
39
+ var productTypesMask = Object.entries(
40
+ productTypes
41
+ ).reduce(
42
+ (acc, [key, value]) => {
43
+ acc[key] = BigInt(1) << BigInt(value);
44
+ return acc;
45
+ },
46
+ {}
47
+ );
48
+
49
+ // src/core/constants/interactionTypes.ts
50
+ var interactionTypes = {
51
+ press: {
52
+ openArticle: "0xc0a24ffb",
53
+ readArticle: "0xd5bd0fbe"
54
+ },
55
+ dapp: {
56
+ proofVerifiableStorageUpdate: "0x2ab2aeef",
57
+ callableVerifiableStorageUpdate: "0xa07da986"
58
+ },
59
+ webshop: {
60
+ open: "0xb311798f"
61
+ },
62
+ referral: {
63
+ referred: "0x010cc3b9",
64
+ createLink: "0xb2c0f17c"
65
+ },
66
+ purchase: {
67
+ started: "0xd87e90c3",
68
+ completed: "0x8403aeb4"
69
+ }
70
+ };
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+ exports.__commonJS = __commonJS; exports.__toESM = __toESM; exports.__publicField = __publicField; exports.productTypes = productTypes; exports.productTypesMask = productTypesMask; exports.interactionTypes = interactionTypes;
@@ -6,7 +6,8 @@
6
6
 
7
7
 
8
8
 
9
- var _chunkYDZBXUC4cjs = require('./chunk-YDZBXUC4.cjs');
9
+
10
+ var _chunkF3F4BCGVcjs = require('./chunk-F3F4BCGV.cjs');
10
11
 
11
12
  // src/core/utils/constants.ts
12
13
  var BACKUP_KEY = "nexus-wallet-backup";
@@ -31,7 +32,7 @@ function createIFrameChannelManager() {
31
32
  function createIFrameLifecycleManager({
32
33
  iframe
33
34
  }) {
34
- const isConnectedDeferred = new (0, _chunkYDZBXUC4cjs.Deferred)();
35
+ const isConnectedDeferred = new (0, _chunkF3F4BCGVcjs.Deferred)();
35
36
  const handler = async (messageEvent) => {
36
37
  switch (messageEvent.iframeLifecycle) {
37
38
  // Resolve the isConnected promise
@@ -53,7 +54,7 @@ function createIFrameLifecycleManager({
53
54
  // Change iframe visibility
54
55
  case "show":
55
56
  case "hide":
56
- _chunkYDZBXUC4cjs.changeIframeVisibility.call(void 0, {
57
+ _chunkF3F4BCGVcjs.changeIframeVisibility.call(void 0, {
57
58
  iframe,
58
59
  isVisible: messageEvent.iframeLifecycle === "show"
59
60
  });
@@ -74,14 +75,14 @@ function createIFrameMessageHandler({
74
75
  iframeLifecycleManager
75
76
  }) {
76
77
  if (typeof window === "undefined") {
77
- throw new (0, _chunkYDZBXUC4cjs.FrakRpcError)(
78
- _chunkYDZBXUC4cjs.RpcErrorCodes.configError,
78
+ throw new (0, _chunkF3F4BCGVcjs.FrakRpcError)(
79
+ _chunkF3F4BCGVcjs.RpcErrorCodes.configError,
79
80
  "iframe client should be used in the browser"
80
81
  );
81
82
  }
82
83
  if (!iframe.contentWindow) {
83
- throw new (0, _chunkYDZBXUC4cjs.FrakRpcError)(
84
- _chunkYDZBXUC4cjs.RpcErrorCodes.configError,
84
+ throw new (0, _chunkF3F4BCGVcjs.FrakRpcError)(
85
+ _chunkF3F4BCGVcjs.RpcErrorCodes.configError,
85
86
  "The iframe does not have a product window"
86
87
  );
87
88
  }
@@ -141,17 +142,17 @@ function createIFrameNexusClient({
141
142
  const request = async (args) => {
142
143
  const isConnected = await lifecycleManager.isConnected;
143
144
  if (!isConnected) {
144
- throw new (0, _chunkYDZBXUC4cjs.FrakRpcError)(
145
- _chunkYDZBXUC4cjs.RpcErrorCodes.clientNotConnected,
145
+ throw new (0, _chunkF3F4BCGVcjs.FrakRpcError)(
146
+ _chunkF3F4BCGVcjs.RpcErrorCodes.clientNotConnected,
146
147
  "The iframe provider isn't connected yet"
147
148
  );
148
149
  }
149
- const result = new (0, _chunkYDZBXUC4cjs.Deferred)();
150
+ const result = new (0, _chunkF3F4BCGVcjs.Deferred)();
150
151
  const channelId = channelManager.createChannel(async (message) => {
151
- const decompressed = await _chunkYDZBXUC4cjs.decompressDataAndCheckHash.call(void 0, message.data);
152
+ const decompressed = await _chunkF3F4BCGVcjs.decompressDataAndCheckHash.call(void 0, message.data);
152
153
  if (decompressed.error) {
153
154
  result.reject(
154
- new (0, _chunkYDZBXUC4cjs.FrakRpcError)(
155
+ new (0, _chunkF3F4BCGVcjs.FrakRpcError)(
155
156
  decompressed.error.code,
156
157
  decompressed.error.message,
157
158
  _optionalChain([decompressed, 'access', _ => _.error, 'optionalAccess', _2 => _2.data])
@@ -162,7 +163,7 @@ function createIFrameNexusClient({
162
163
  }
163
164
  channelManager.removeChannel(channelId);
164
165
  });
165
- const compressedMessage = await _chunkYDZBXUC4cjs.hashAndCompressData.call(void 0, args);
166
+ const compressedMessage = await _chunkF3F4BCGVcjs.hashAndCompressData.call(void 0, args);
166
167
  messageHandler.sendEvent({
167
168
  id: channelId,
168
169
  topic: args.method,
@@ -173,20 +174,20 @@ function createIFrameNexusClient({
173
174
  const listenerRequest = async (args, callback) => {
174
175
  const isConnected = await lifecycleManager.isConnected;
175
176
  if (!isConnected) {
176
- throw new (0, _chunkYDZBXUC4cjs.FrakRpcError)(
177
- _chunkYDZBXUC4cjs.RpcErrorCodes.clientNotConnected,
177
+ throw new (0, _chunkF3F4BCGVcjs.FrakRpcError)(
178
+ _chunkF3F4BCGVcjs.RpcErrorCodes.clientNotConnected,
178
179
  "The iframe provider isn't connected yet"
179
180
  );
180
181
  }
181
182
  const channelId = channelManager.createChannel(async (message) => {
182
- const decompressed = await _chunkYDZBXUC4cjs.decompressDataAndCheckHash.call(void 0, message.data);
183
+ const decompressed = await _chunkF3F4BCGVcjs.decompressDataAndCheckHash.call(void 0, message.data);
183
184
  if (decompressed.result) {
184
185
  callback(decompressed.result);
185
186
  } else {
186
- throw new (0, _chunkYDZBXUC4cjs.InternalError)("No valid result in the response");
187
+ throw new (0, _chunkF3F4BCGVcjs.InternalError)("No valid result in the response");
187
188
  }
188
189
  });
189
- const compressedMessage = await _chunkYDZBXUC4cjs.hashAndCompressData.call(void 0, args);
190
+ const compressedMessage = await _chunkF3F4BCGVcjs.hashAndCompressData.call(void 0, args);
190
191
  messageHandler.sendEvent({
191
192
  id: channelId,
192
193
  topic: args.method,
@@ -218,6 +219,7 @@ async function postConnectionSetup({
218
219
  lifecycleManager
219
220
  }) {
220
221
  await lifecycleManager.isConnected;
222
+ _chunkF3F4BCGVcjs.enableButtonShare.call(void 0, config);
221
223
  const pushCss = async () => {
222
224
  const cssLink = config.metadata.css;
223
225
  if (!cssLink) return;
@@ -5,8 +5,9 @@ import {
5
5
  RpcErrorCodes,
6
6
  changeIframeVisibility,
7
7
  decompressDataAndCheckHash,
8
+ enableButtonShare,
8
9
  hashAndCompressData
9
- } from "./chunk-7K4L7VQC.js";
10
+ } from "./chunk-ZQSA2VQ4.js";
10
11
 
11
12
  // src/core/utils/constants.ts
12
13
  var BACKUP_KEY = "nexus-wallet-backup";
@@ -218,6 +219,7 @@ async function postConnectionSetup({
218
219
  lifecycleManager
219
220
  }) {
220
221
  await lifecycleManager.isConnected;
222
+ enableButtonShare(config);
221
223
  const pushCss = async () => {
222
224
  const cssLink = config.metadata.css;
223
225
  if (!cssLink) return;