@formo/analytics 1.25.0 → 1.26.0
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/LICENSE +21 -0
- package/dist/cjs/src/FormoAnalytics.d.ts +24 -14
- package/dist/cjs/src/FormoAnalytics.js +195 -255
- package/dist/cjs/src/FormoAnalyticsProvider.js +71 -13
- package/dist/{esm/src/lib/consent.d.ts → cjs/src/consent/index.d.ts} +1 -1
- package/dist/cjs/src/{lib/consent.js → consent/index.js} +1 -1
- package/dist/cjs/src/constants/base.d.ts +0 -2
- package/dist/cjs/src/constants/base.js +3 -3
- package/dist/cjs/src/constants/config.js +1 -1
- package/dist/cjs/src/{lib/event → event}/EventFactory.d.ts +1 -1
- package/dist/cjs/src/{lib/event → event}/EventFactory.js +6 -6
- package/dist/cjs/src/{lib/event → event}/EventManager.d.ts +1 -1
- package/dist/cjs/src/{lib/event → event}/EventManager.js +1 -1
- package/dist/cjs/src/{lib/event → event}/type.d.ts +1 -1
- package/dist/cjs/src/{lib/event → event}/utils.d.ts +1 -1
- package/dist/cjs/src/{lib/event → event}/utils.js +1 -1
- package/dist/cjs/src/{lib/fetch.d.ts → fetch/index.d.ts} +1 -1
- package/dist/cjs/src/{lib/fetch.js → fetch/index.js} +1 -1
- package/dist/cjs/src/provider/detection.d.ts +58 -0
- package/dist/cjs/src/provider/detection.js +103 -0
- package/dist/cjs/src/provider/index.d.ts +6 -0
- package/dist/cjs/src/provider/index.js +11 -0
- package/dist/{esm/src/lib → cjs/src}/queue/EventQueue.d.ts +1 -1
- package/dist/cjs/src/{lib/queue → queue}/EventQueue.js +3 -3
- package/dist/{esm/src/lib → cjs/src}/queue/type.d.ts +1 -1
- package/dist/cjs/src/session/index.d.ts +91 -0
- package/dist/cjs/src/session/index.js +126 -0
- package/dist/cjs/src/{lib/storage → storage}/built-in/blueprint.js +1 -1
- package/dist/cjs/src/types/base.d.ts +27 -1
- package/dist/cjs/src/validators/object.js +0 -2
- package/dist/cjs/src/version.d.ts +1 -1
- package/dist/cjs/src/version.js +1 -1
- package/dist/cjs/src/wagmi/WagmiEventHandler.d.ts +69 -0
- package/dist/cjs/src/wagmi/WagmiEventHandler.js +449 -0
- package/dist/cjs/src/wagmi/index.d.ts +9 -0
- package/dist/cjs/src/wagmi/index.js +12 -0
- package/dist/cjs/src/wagmi/types.d.ts +115 -0
- package/dist/cjs/src/wagmi/types.js +10 -0
- package/dist/esm/src/FormoAnalytics.d.ts +24 -14
- package/dist/esm/src/FormoAnalytics.js +85 -145
- package/dist/esm/src/FormoAnalyticsProvider.js +68 -10
- package/dist/{cjs/src/lib/consent.d.ts → esm/src/consent/index.d.ts} +1 -1
- package/dist/esm/src/{lib/consent.js → consent/index.js} +1 -1
- package/dist/esm/src/constants/base.d.ts +0 -2
- package/dist/esm/src/constants/base.js +2 -2
- package/dist/esm/src/constants/config.js +1 -1
- package/dist/esm/src/{lib/event → event}/EventFactory.d.ts +1 -1
- package/dist/esm/src/{lib/event → event}/EventFactory.js +6 -6
- package/dist/esm/src/{lib/event → event}/EventManager.d.ts +1 -1
- package/dist/esm/src/{lib/event → event}/EventManager.js +1 -1
- package/dist/esm/src/{lib/event → event}/type.d.ts +1 -1
- package/dist/esm/src/{lib/event → event}/utils.d.ts +1 -1
- package/dist/esm/src/{lib/event → event}/utils.js +1 -1
- package/dist/esm/src/{lib/fetch.d.ts → fetch/index.d.ts} +1 -1
- package/dist/esm/src/{lib/fetch.js → fetch/index.js} +1 -1
- package/dist/esm/src/provider/detection.d.ts +58 -0
- package/dist/esm/src/provider/detection.js +98 -0
- package/dist/esm/src/provider/index.d.ts +6 -0
- package/dist/esm/src/provider/index.js +5 -0
- package/dist/{cjs/src/lib → esm/src}/queue/EventQueue.d.ts +1 -1
- package/dist/esm/src/{lib/queue → queue}/EventQueue.js +3 -3
- package/dist/{cjs/src/lib → esm/src}/queue/type.d.ts +1 -1
- package/dist/esm/src/session/index.d.ts +91 -0
- package/dist/esm/src/session/index.js +123 -0
- package/dist/esm/src/{lib/storage → storage}/built-in/blueprint.js +1 -1
- package/dist/esm/src/types/base.d.ts +27 -1
- package/dist/esm/src/validators/object.js +0 -2
- package/dist/esm/src/version.d.ts +1 -1
- package/dist/esm/src/version.js +1 -1
- package/dist/esm/src/wagmi/WagmiEventHandler.d.ts +69 -0
- package/dist/esm/src/wagmi/WagmiEventHandler.js +446 -0
- package/dist/esm/src/wagmi/index.d.ts +9 -0
- package/dist/esm/src/wagmi/index.js +8 -0
- package/dist/esm/src/wagmi/types.d.ts +115 -0
- package/dist/esm/src/wagmi/types.js +9 -0
- package/dist/index.umd.min.js +1 -1
- package/package.json +18 -3
- package/dist/cjs/src/lib/index.d.ts +0 -7
- package/dist/cjs/src/lib/index.js +0 -28
- package/dist/esm/src/lib/index.d.ts +0 -7
- package/dist/esm/src/lib/index.js +0 -7
- /package/dist/cjs/src/{lib/browser → browser}/browsers.d.ts +0 -0
- /package/dist/cjs/src/{lib/browser → browser}/browsers.js +0 -0
- /package/dist/cjs/src/{lib/event → event}/constants.d.ts +0 -0
- /package/dist/cjs/src/{lib/event → event}/constants.js +0 -0
- /package/dist/cjs/src/{lib/event → event}/index.d.ts +0 -0
- /package/dist/cjs/src/{lib/event → event}/index.js +0 -0
- /package/dist/cjs/src/{lib/event → event}/type.js +0 -0
- /package/dist/cjs/src/{lib/logger → logger}/Logger.d.ts +0 -0
- /package/dist/cjs/src/{lib/logger → logger}/Logger.js +0 -0
- /package/dist/cjs/src/{lib/logger → logger}/index.d.ts +0 -0
- /package/dist/cjs/src/{lib/logger → logger}/index.js +0 -0
- /package/dist/cjs/src/{lib/logger → logger}/type.d.ts +0 -0
- /package/dist/cjs/src/{lib/logger → logger}/type.js +0 -0
- /package/dist/cjs/src/{lib/queue → queue}/index.d.ts +0 -0
- /package/dist/cjs/src/{lib/queue → queue}/index.js +0 -0
- /package/dist/cjs/src/{lib/queue → queue}/type.js +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/internal/_curry1.d.ts +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/internal/_curry1.js +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/internal/_curry2.d.ts +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/internal/_curry2.js +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/internal/_curry3.d.ts +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/internal/_curry3.js +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/internal/_has.d.ts +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/internal/_has.js +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/internal/_isObject.d.ts +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/internal/_isObject.js +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/internal/_isPlaceholder.d.ts +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/internal/_isPlaceholder.js +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/mergeDeepRight.d.ts +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/mergeDeepRight.js +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/mergeDeepWithKey.d.ts +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/mergeDeepWithKey.js +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/mergeWithKey.d.ts +0 -0
- /package/dist/cjs/src/{lib/ramda → ramda}/mergeWithKey.js +0 -0
- /package/dist/cjs/src/{lib/storage → storage}/StorageManager.d.ts +0 -0
- /package/dist/cjs/src/{lib/storage → storage}/StorageManager.js +0 -0
- /package/dist/cjs/src/{lib/storage → storage}/built-in/blueprint.d.ts +0 -0
- /package/dist/cjs/src/{lib/storage → storage}/built-in/cookie.d.ts +0 -0
- /package/dist/cjs/src/{lib/storage → storage}/built-in/cookie.js +0 -0
- /package/dist/cjs/src/{lib/storage → storage}/built-in/memory.d.ts +0 -0
- /package/dist/cjs/src/{lib/storage → storage}/built-in/memory.js +0 -0
- /package/dist/cjs/src/{lib/storage → storage}/built-in/web.d.ts +0 -0
- /package/dist/cjs/src/{lib/storage → storage}/built-in/web.js +0 -0
- /package/dist/cjs/src/{lib/storage → storage}/constant.d.ts +0 -0
- /package/dist/cjs/src/{lib/storage → storage}/constant.js +0 -0
- /package/dist/cjs/src/{lib/storage → storage}/index.d.ts +0 -0
- /package/dist/cjs/src/{lib/storage → storage}/index.js +0 -0
- /package/dist/cjs/src/{lib/storage → storage}/type.d.ts +0 -0
- /package/dist/cjs/src/{lib/storage → storage}/type.js +0 -0
- /package/dist/esm/src/{lib/browser → browser}/browsers.d.ts +0 -0
- /package/dist/esm/src/{lib/browser → browser}/browsers.js +0 -0
- /package/dist/esm/src/{lib/event → event}/constants.d.ts +0 -0
- /package/dist/esm/src/{lib/event → event}/constants.js +0 -0
- /package/dist/esm/src/{lib/event → event}/index.d.ts +0 -0
- /package/dist/esm/src/{lib/event → event}/index.js +0 -0
- /package/dist/esm/src/{lib/event → event}/type.js +0 -0
- /package/dist/esm/src/{lib/logger → logger}/Logger.d.ts +0 -0
- /package/dist/esm/src/{lib/logger → logger}/Logger.js +0 -0
- /package/dist/esm/src/{lib/logger → logger}/index.d.ts +0 -0
- /package/dist/esm/src/{lib/logger → logger}/index.js +0 -0
- /package/dist/esm/src/{lib/logger → logger}/type.d.ts +0 -0
- /package/dist/esm/src/{lib/logger → logger}/type.js +0 -0
- /package/dist/esm/src/{lib/queue → queue}/index.d.ts +0 -0
- /package/dist/esm/src/{lib/queue → queue}/index.js +0 -0
- /package/dist/esm/src/{lib/queue → queue}/type.js +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/internal/_curry1.d.ts +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/internal/_curry1.js +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/internal/_curry2.d.ts +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/internal/_curry2.js +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/internal/_curry3.d.ts +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/internal/_curry3.js +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/internal/_has.d.ts +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/internal/_has.js +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/internal/_isObject.d.ts +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/internal/_isObject.js +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/internal/_isPlaceholder.d.ts +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/internal/_isPlaceholder.js +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/mergeDeepRight.d.ts +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/mergeDeepRight.js +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/mergeDeepWithKey.d.ts +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/mergeDeepWithKey.js +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/mergeWithKey.d.ts +0 -0
- /package/dist/esm/src/{lib/ramda → ramda}/mergeWithKey.js +0 -0
- /package/dist/esm/src/{lib/storage → storage}/StorageManager.d.ts +0 -0
- /package/dist/esm/src/{lib/storage → storage}/StorageManager.js +0 -0
- /package/dist/esm/src/{lib/storage → storage}/built-in/blueprint.d.ts +0 -0
- /package/dist/esm/src/{lib/storage → storage}/built-in/cookie.d.ts +0 -0
- /package/dist/esm/src/{lib/storage → storage}/built-in/cookie.js +0 -0
- /package/dist/esm/src/{lib/storage → storage}/built-in/memory.d.ts +0 -0
- /package/dist/esm/src/{lib/storage → storage}/built-in/memory.js +0 -0
- /package/dist/esm/src/{lib/storage → storage}/built-in/web.d.ts +0 -0
- /package/dist/esm/src/{lib/storage → storage}/built-in/web.js +0 -0
- /package/dist/esm/src/{lib/storage → storage}/constant.d.ts +0 -0
- /package/dist/esm/src/{lib/storage → storage}/constant.js +0 -0
- /package/dist/esm/src/{lib/storage → storage}/index.d.ts +0 -0
- /package/dist/esm/src/{lib/storage → storage}/index.js +0 -0
- /package/dist/esm/src/{lib/storage → storage}/type.d.ts +0 -0
- /package/dist/esm/src/{lib/storage → storage}/type.js +0 -0
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WagmiEventHandler
|
|
3
|
+
*
|
|
4
|
+
* Handles wallet event tracking by hooking into Wagmi v2's config.subscribe()
|
|
5
|
+
* and TanStack Query's MutationCache. This replaces the EIP-1193 provider
|
|
6
|
+
* wrapping approach when Wagmi mode is enabled.
|
|
7
|
+
*/
|
|
8
|
+
var __assign = (this && this.__assign) || function () {
|
|
9
|
+
__assign = Object.assign || function(t) {
|
|
10
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
11
|
+
s = arguments[i];
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
}
|
|
15
|
+
return t;
|
|
16
|
+
};
|
|
17
|
+
return __assign.apply(this, arguments);
|
|
18
|
+
};
|
|
19
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
29
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
30
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
31
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
32
|
+
function step(op) {
|
|
33
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
34
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
35
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
36
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
37
|
+
switch (op[0]) {
|
|
38
|
+
case 0: case 1: t = op; break;
|
|
39
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
40
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
41
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
42
|
+
default:
|
|
43
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
44
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
45
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
46
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
47
|
+
if (t[2]) _.ops.pop();
|
|
48
|
+
_.trys.pop(); continue;
|
|
49
|
+
}
|
|
50
|
+
op = body.call(thisArg, _);
|
|
51
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
52
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
import { SignatureStatus, TransactionStatus } from "../types/events";
|
|
56
|
+
import { logger } from "../logger";
|
|
57
|
+
var WagmiEventHandler = /** @class */ (function () {
|
|
58
|
+
function WagmiEventHandler(formoAnalytics, wagmiConfig, queryClient) {
|
|
59
|
+
this.unsubscribers = [];
|
|
60
|
+
this.trackingState = {
|
|
61
|
+
isProcessing: false,
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Track processed mutation states to prevent duplicate event emissions
|
|
65
|
+
* Key format: `${mutationId}:${status}`
|
|
66
|
+
*/
|
|
67
|
+
this.processedMutations = new Set();
|
|
68
|
+
this.formo = formoAnalytics;
|
|
69
|
+
this.wagmiConfig = wagmiConfig;
|
|
70
|
+
this.queryClient = queryClient;
|
|
71
|
+
logger.info("WagmiEventHandler: Initializing Wagmi integration");
|
|
72
|
+
// Set up connection/disconnection/chain listeners
|
|
73
|
+
this.setupConnectionListeners();
|
|
74
|
+
// Set up mutation tracking if QueryClient is provided
|
|
75
|
+
if (this.queryClient) {
|
|
76
|
+
this.setupMutationTracking();
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
logger.warn("WagmiEventHandler: QueryClient not provided, signature and transaction events will not be tracked");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Set up listeners for wallet connection, disconnection, and chain changes
|
|
84
|
+
*/
|
|
85
|
+
WagmiEventHandler.prototype.setupConnectionListeners = function () {
|
|
86
|
+
var _this = this;
|
|
87
|
+
logger.info("WagmiEventHandler: Setting up connection listeners");
|
|
88
|
+
// Subscribe to status changes (connect/disconnect)
|
|
89
|
+
var statusUnsubscribe = this.wagmiConfig.subscribe(function (state) { return state.status; }, function (status, prevStatus) {
|
|
90
|
+
_this.handleStatusChange(status, prevStatus);
|
|
91
|
+
});
|
|
92
|
+
this.unsubscribers.push(statusUnsubscribe);
|
|
93
|
+
// Subscribe to chain ID changes
|
|
94
|
+
var chainIdUnsubscribe = this.wagmiConfig.subscribe(function (state) { return state.chainId; }, function (chainId, prevChainId) {
|
|
95
|
+
_this.handleChainChange(chainId, prevChainId);
|
|
96
|
+
});
|
|
97
|
+
this.unsubscribers.push(chainIdUnsubscribe);
|
|
98
|
+
logger.info("WagmiEventHandler: Connection listeners set up successfully");
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Handle status changes (connect/disconnect)
|
|
102
|
+
*/
|
|
103
|
+
WagmiEventHandler.prototype.handleStatusChange = function (status, prevStatus) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
105
|
+
var state, address, chainId, connectorName, error_1;
|
|
106
|
+
return __generator(this, function (_a) {
|
|
107
|
+
switch (_a.label) {
|
|
108
|
+
case 0:
|
|
109
|
+
// Prevent concurrent processing
|
|
110
|
+
if (this.trackingState.isProcessing) {
|
|
111
|
+
logger.debug("WagmiEventHandler: Already processing status change, skipping");
|
|
112
|
+
return [2 /*return*/];
|
|
113
|
+
}
|
|
114
|
+
this.trackingState.isProcessing = true;
|
|
115
|
+
_a.label = 1;
|
|
116
|
+
case 1:
|
|
117
|
+
_a.trys.push([1, 7, 8, 9]);
|
|
118
|
+
state = this.getState();
|
|
119
|
+
address = this.getConnectedAddress(state);
|
|
120
|
+
chainId = state.chainId;
|
|
121
|
+
logger.info("WagmiEventHandler: Status changed", {
|
|
122
|
+
status: status,
|
|
123
|
+
prevStatus: prevStatus,
|
|
124
|
+
address: address,
|
|
125
|
+
chainId: chainId,
|
|
126
|
+
});
|
|
127
|
+
if (!(status === "disconnected" && prevStatus === "connected")) return [3 /*break*/, 4];
|
|
128
|
+
if (!this.formo.isAutocaptureEnabled("disconnect")) return [3 /*break*/, 3];
|
|
129
|
+
return [4 /*yield*/, this.formo.disconnect({
|
|
130
|
+
chainId: this.trackingState.lastChainId,
|
|
131
|
+
address: this.trackingState.lastAddress,
|
|
132
|
+
})];
|
|
133
|
+
case 2:
|
|
134
|
+
_a.sent();
|
|
135
|
+
_a.label = 3;
|
|
136
|
+
case 3:
|
|
137
|
+
this.trackingState.lastAddress = undefined;
|
|
138
|
+
this.trackingState.lastChainId = undefined;
|
|
139
|
+
_a.label = 4;
|
|
140
|
+
case 4:
|
|
141
|
+
if (!(status === "connected" && prevStatus !== "connected")) return [3 /*break*/, 6];
|
|
142
|
+
if (!(address && chainId !== undefined)) return [3 /*break*/, 6];
|
|
143
|
+
this.trackingState.lastAddress = address;
|
|
144
|
+
this.trackingState.lastChainId = chainId;
|
|
145
|
+
if (!this.formo.isAutocaptureEnabled("connect")) return [3 /*break*/, 6];
|
|
146
|
+
connectorName = this.getConnectorName(state);
|
|
147
|
+
return [4 /*yield*/, this.formo.connect({ chainId: chainId, address: address }, __assign({}, (connectorName && { providerName: connectorName })))];
|
|
148
|
+
case 5:
|
|
149
|
+
_a.sent();
|
|
150
|
+
_a.label = 6;
|
|
151
|
+
case 6:
|
|
152
|
+
this.trackingState.lastStatus = status;
|
|
153
|
+
return [3 /*break*/, 9];
|
|
154
|
+
case 7:
|
|
155
|
+
error_1 = _a.sent();
|
|
156
|
+
logger.error("WagmiEventHandler: Error handling status change:", error_1);
|
|
157
|
+
return [3 /*break*/, 9];
|
|
158
|
+
case 8:
|
|
159
|
+
this.trackingState.isProcessing = false;
|
|
160
|
+
return [7 /*endfinally*/];
|
|
161
|
+
case 9: return [2 /*return*/];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Handle chain ID changes
|
|
168
|
+
*/
|
|
169
|
+
WagmiEventHandler.prototype.handleChainChange = function (chainId, prevChainId) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
171
|
+
var state, address, error_2;
|
|
172
|
+
return __generator(this, function (_a) {
|
|
173
|
+
switch (_a.label) {
|
|
174
|
+
case 0:
|
|
175
|
+
if (chainId === prevChainId || chainId === undefined) {
|
|
176
|
+
return [2 /*return*/];
|
|
177
|
+
}
|
|
178
|
+
state = this.getState();
|
|
179
|
+
if (state.status !== "connected") {
|
|
180
|
+
return [2 /*return*/];
|
|
181
|
+
}
|
|
182
|
+
address = this.getConnectedAddress(state);
|
|
183
|
+
if (!address) {
|
|
184
|
+
logger.warn("WagmiEventHandler: Chain changed but no address found");
|
|
185
|
+
return [2 /*return*/];
|
|
186
|
+
}
|
|
187
|
+
logger.info("WagmiEventHandler: Chain changed", {
|
|
188
|
+
chainId: chainId,
|
|
189
|
+
prevChainId: prevChainId,
|
|
190
|
+
address: address,
|
|
191
|
+
});
|
|
192
|
+
this.trackingState.lastChainId = chainId;
|
|
193
|
+
if (!this.formo.isAutocaptureEnabled("chain")) return [3 /*break*/, 4];
|
|
194
|
+
_a.label = 1;
|
|
195
|
+
case 1:
|
|
196
|
+
_a.trys.push([1, 3, , 4]);
|
|
197
|
+
return [4 /*yield*/, this.formo.chain({ chainId: chainId, address: address })];
|
|
198
|
+
case 2:
|
|
199
|
+
_a.sent();
|
|
200
|
+
return [3 /*break*/, 4];
|
|
201
|
+
case 3:
|
|
202
|
+
error_2 = _a.sent();
|
|
203
|
+
logger.error("WagmiEventHandler: Error tracking chain change:", error_2);
|
|
204
|
+
return [3 /*break*/, 4];
|
|
205
|
+
case 4: return [2 /*return*/];
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Set up mutation tracking for signatures and transactions
|
|
212
|
+
*/
|
|
213
|
+
WagmiEventHandler.prototype.setupMutationTracking = function () {
|
|
214
|
+
var _this = this;
|
|
215
|
+
if (!this.queryClient) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
logger.info("WagmiEventHandler: Setting up mutation tracking");
|
|
219
|
+
var mutationCache = this.queryClient.getMutationCache();
|
|
220
|
+
var unsubscribe = mutationCache.subscribe(function (event) {
|
|
221
|
+
_this.handleMutationEvent(event);
|
|
222
|
+
});
|
|
223
|
+
this.unsubscribers.push(unsubscribe);
|
|
224
|
+
logger.info("WagmiEventHandler: Mutation tracking set up successfully");
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Handle mutation cache events (signatures, transactions)
|
|
228
|
+
*/
|
|
229
|
+
WagmiEventHandler.prototype.handleMutationEvent = function (event) {
|
|
230
|
+
if (event.type !== "updated") {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
var mutation = event.mutation;
|
|
234
|
+
var mutationKey = mutation.options.mutationKey;
|
|
235
|
+
if (!mutationKey || mutationKey.length === 0) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
var mutationType = mutationKey[0];
|
|
239
|
+
var state = mutation.state;
|
|
240
|
+
// Create a unique key for this mutation state to prevent duplicate processing
|
|
241
|
+
var mutationStateKey = "".concat(mutation.mutationId, ":").concat(state.status);
|
|
242
|
+
// Skip if we've already processed this mutation state
|
|
243
|
+
if (this.processedMutations.has(mutationStateKey)) {
|
|
244
|
+
logger.debug("WagmiEventHandler: Skipping duplicate mutation event", {
|
|
245
|
+
mutationType: mutationType,
|
|
246
|
+
mutationId: mutation.mutationId,
|
|
247
|
+
status: state.status,
|
|
248
|
+
});
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
// Mark this mutation state as processed
|
|
252
|
+
this.processedMutations.add(mutationStateKey);
|
|
253
|
+
logger.debug("WagmiEventHandler: Mutation event", {
|
|
254
|
+
mutationType: mutationType,
|
|
255
|
+
mutationId: mutation.mutationId,
|
|
256
|
+
status: state.status,
|
|
257
|
+
});
|
|
258
|
+
// Handle signature mutations
|
|
259
|
+
if (mutationType === "signMessage" || mutationType === "signTypedData") {
|
|
260
|
+
this.handleSignatureMutation(mutationType, mutation);
|
|
261
|
+
}
|
|
262
|
+
// Handle transaction mutations
|
|
263
|
+
if (mutationType === "sendTransaction" || mutationType === "writeContract") {
|
|
264
|
+
this.handleTransactionMutation(mutationType, mutation);
|
|
265
|
+
}
|
|
266
|
+
// Clean up old processed mutations to prevent memory leaks
|
|
267
|
+
// Keep only recent mutations (max 1000 entries)
|
|
268
|
+
if (this.processedMutations.size > 1000) {
|
|
269
|
+
var entries = Array.from(this.processedMutations);
|
|
270
|
+
// Remove oldest 500 entries
|
|
271
|
+
for (var i = 0; i < 500; i++) {
|
|
272
|
+
this.processedMutations.delete(entries[i]);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* Handle signature mutations (signMessage, signTypedData)
|
|
278
|
+
*/
|
|
279
|
+
WagmiEventHandler.prototype.handleSignatureMutation = function (mutationType, mutation) {
|
|
280
|
+
if (!this.formo.isAutocaptureEnabled("signature")) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
var state = mutation.state;
|
|
284
|
+
var variables = state.variables || {};
|
|
285
|
+
var chainId = this.trackingState.lastChainId;
|
|
286
|
+
var address = this.trackingState.lastAddress;
|
|
287
|
+
if (!address) {
|
|
288
|
+
logger.warn("WagmiEventHandler: Signature event but no address available");
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
try {
|
|
292
|
+
// Map Wagmi mutation status to Formo signature status
|
|
293
|
+
var status_1;
|
|
294
|
+
var signatureHash = void 0;
|
|
295
|
+
if (state.status === "pending") {
|
|
296
|
+
status_1 = SignatureStatus.REQUESTED;
|
|
297
|
+
}
|
|
298
|
+
else if (state.status === "success") {
|
|
299
|
+
status_1 = SignatureStatus.CONFIRMED;
|
|
300
|
+
signatureHash = state.data;
|
|
301
|
+
}
|
|
302
|
+
else if (state.status === "error") {
|
|
303
|
+
status_1 = SignatureStatus.REJECTED;
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
return; // Ignore idle state
|
|
307
|
+
}
|
|
308
|
+
// Extract message from variables
|
|
309
|
+
var message = void 0;
|
|
310
|
+
if (mutationType === "signMessage") {
|
|
311
|
+
message = variables.message || "";
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
// For signTypedData, stringify the typed data
|
|
315
|
+
message = JSON.stringify(variables.message || variables.types || {});
|
|
316
|
+
}
|
|
317
|
+
logger.info("WagmiEventHandler: Tracking signature event", {
|
|
318
|
+
status: status_1,
|
|
319
|
+
mutationType: mutationType,
|
|
320
|
+
address: address,
|
|
321
|
+
chainId: chainId,
|
|
322
|
+
});
|
|
323
|
+
this.formo.signature(__assign({ status: status_1, chainId: chainId, address: address, message: message }, (signatureHash && { signatureHash: signatureHash })));
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
logger.error("WagmiEventHandler: Error handling signature mutation:", error);
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
/**
|
|
330
|
+
* Handle transaction mutations (sendTransaction, writeContract)
|
|
331
|
+
*/
|
|
332
|
+
WagmiEventHandler.prototype.handleTransactionMutation = function (mutationType, mutation) {
|
|
333
|
+
var _a;
|
|
334
|
+
if (!this.formo.isAutocaptureEnabled("transaction")) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
var state = mutation.state;
|
|
338
|
+
var variables = state.variables || {};
|
|
339
|
+
var chainId = this.trackingState.lastChainId || variables.chainId;
|
|
340
|
+
var address = this.trackingState.lastAddress || variables.account || variables.address;
|
|
341
|
+
if (!address) {
|
|
342
|
+
logger.warn("WagmiEventHandler: Transaction event but no address available");
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
try {
|
|
346
|
+
// Map Wagmi mutation status to Formo transaction status
|
|
347
|
+
var status_2;
|
|
348
|
+
var transactionHash = void 0;
|
|
349
|
+
if (state.status === "pending") {
|
|
350
|
+
status_2 = TransactionStatus.STARTED;
|
|
351
|
+
}
|
|
352
|
+
else if (state.status === "success") {
|
|
353
|
+
status_2 = TransactionStatus.BROADCASTED;
|
|
354
|
+
transactionHash = state.data;
|
|
355
|
+
}
|
|
356
|
+
else if (state.status === "error") {
|
|
357
|
+
status_2 = TransactionStatus.REJECTED;
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
return; // Ignore idle state
|
|
361
|
+
}
|
|
362
|
+
// Extract transaction details from variables
|
|
363
|
+
var data = variables.data;
|
|
364
|
+
var to = variables.to || variables.address;
|
|
365
|
+
var value = (_a = variables.value) === null || _a === void 0 ? void 0 : _a.toString();
|
|
366
|
+
logger.info("WagmiEventHandler: Tracking transaction event", {
|
|
367
|
+
status: status_2,
|
|
368
|
+
mutationType: mutationType,
|
|
369
|
+
address: address,
|
|
370
|
+
chainId: chainId,
|
|
371
|
+
transactionHash: transactionHash,
|
|
372
|
+
});
|
|
373
|
+
this.formo.transaction(__assign(__assign(__assign(__assign({ status: status_2, chainId: chainId || 0, address: address }, (data && { data: data })), (to && { to: to })), (value && { value: value })), (transactionHash && { transactionHash: transactionHash })));
|
|
374
|
+
}
|
|
375
|
+
catch (error) {
|
|
376
|
+
logger.error("WagmiEventHandler: Error handling transaction mutation:", error);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
/**
|
|
380
|
+
* Get the current Wagmi state
|
|
381
|
+
* Supports both getState() method and direct state property access
|
|
382
|
+
* for compatibility with different Wagmi wrappers (RainbowKit, etc.)
|
|
383
|
+
*/
|
|
384
|
+
WagmiEventHandler.prototype.getState = function () {
|
|
385
|
+
// Try getState() method first (standard Wagmi API)
|
|
386
|
+
if (typeof this.wagmiConfig.getState === "function") {
|
|
387
|
+
return this.wagmiConfig.getState();
|
|
388
|
+
}
|
|
389
|
+
// Fall back to direct state property (RainbowKit and some Wagmi setups)
|
|
390
|
+
if (this.wagmiConfig.state) {
|
|
391
|
+
return this.wagmiConfig.state;
|
|
392
|
+
}
|
|
393
|
+
// Return a default disconnected state if neither is available
|
|
394
|
+
logger.warn("WagmiEventHandler: Unable to get state from config, returning default state");
|
|
395
|
+
return {
|
|
396
|
+
status: "disconnected",
|
|
397
|
+
connections: new Map(),
|
|
398
|
+
current: undefined,
|
|
399
|
+
chainId: undefined,
|
|
400
|
+
};
|
|
401
|
+
};
|
|
402
|
+
/**
|
|
403
|
+
* Get the currently connected address from Wagmi state
|
|
404
|
+
*/
|
|
405
|
+
WagmiEventHandler.prototype.getConnectedAddress = function (state) {
|
|
406
|
+
if (!state.current) {
|
|
407
|
+
return undefined;
|
|
408
|
+
}
|
|
409
|
+
var connection = state.connections.get(state.current);
|
|
410
|
+
if (!connection || connection.accounts.length === 0) {
|
|
411
|
+
return undefined;
|
|
412
|
+
}
|
|
413
|
+
return connection.accounts[0];
|
|
414
|
+
};
|
|
415
|
+
/**
|
|
416
|
+
* Get the connector name from Wagmi state
|
|
417
|
+
*/
|
|
418
|
+
WagmiEventHandler.prototype.getConnectorName = function (state) {
|
|
419
|
+
if (!state.current) {
|
|
420
|
+
return undefined;
|
|
421
|
+
}
|
|
422
|
+
var connection = state.connections.get(state.current);
|
|
423
|
+
return connection === null || connection === void 0 ? void 0 : connection.connector.name;
|
|
424
|
+
};
|
|
425
|
+
/**
|
|
426
|
+
* Clean up all subscriptions
|
|
427
|
+
*/
|
|
428
|
+
WagmiEventHandler.prototype.cleanup = function () {
|
|
429
|
+
logger.info("WagmiEventHandler: Cleaning up subscriptions");
|
|
430
|
+
for (var _i = 0, _a = this.unsubscribers; _i < _a.length; _i++) {
|
|
431
|
+
var unsubscribe = _a[_i];
|
|
432
|
+
try {
|
|
433
|
+
unsubscribe();
|
|
434
|
+
}
|
|
435
|
+
catch (error) {
|
|
436
|
+
logger.error("WagmiEventHandler: Error during cleanup:", error);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
this.unsubscribers = [];
|
|
440
|
+
this.processedMutations.clear();
|
|
441
|
+
logger.info("WagmiEventHandler: Cleanup complete");
|
|
442
|
+
};
|
|
443
|
+
return WagmiEventHandler;
|
|
444
|
+
}());
|
|
445
|
+
export { WagmiEventHandler };
|
|
446
|
+
//# sourceMappingURL=WagmiEventHandler.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wagmi integration module
|
|
3
|
+
*
|
|
4
|
+
* Provides integration with Wagmi v2 for wallet event tracking.
|
|
5
|
+
* This module exports the WagmiEventHandler and related types.
|
|
6
|
+
*/
|
|
7
|
+
export { WagmiEventHandler } from "./WagmiEventHandler";
|
|
8
|
+
export type { WagmiState, WagmiConnection, WagmiConnector, WagmiConfig, MutationState, Mutation, MutationCacheEvent, MutationCache, QueryClient, UnsubscribeFn, WagmiMutationKey, WagmiTrackingState, } from "./types";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wagmi integration module
|
|
3
|
+
*
|
|
4
|
+
* Provides integration with Wagmi v2 for wallet event tracking.
|
|
5
|
+
* This module exports the WagmiEventHandler and related types.
|
|
6
|
+
*/
|
|
7
|
+
export { WagmiEventHandler } from "./WagmiEventHandler";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wagmi-specific type definitions for wallet event tracking
|
|
3
|
+
*
|
|
4
|
+
* These types provide TypeScript interfaces for Wagmi v2 integration,
|
|
5
|
+
* allowing the SDK to hook into Wagmi's config.subscribe() and MutationCache
|
|
6
|
+
* to track wallet events without wrapping EIP-1193 providers.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Wagmi config state structure
|
|
10
|
+
* Based on Wagmi v2 internal state
|
|
11
|
+
*/
|
|
12
|
+
export interface WagmiState {
|
|
13
|
+
chainId?: number;
|
|
14
|
+
connections: Map<string, WagmiConnection>;
|
|
15
|
+
current?: string;
|
|
16
|
+
status: 'connected' | 'disconnected' | 'connecting' | 'reconnecting';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Wagmi connection information
|
|
20
|
+
*/
|
|
21
|
+
export interface WagmiConnection {
|
|
22
|
+
accounts: readonly string[];
|
|
23
|
+
chainId: number;
|
|
24
|
+
connector: WagmiConnector;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Wagmi connector interface
|
|
28
|
+
*/
|
|
29
|
+
export interface WagmiConnector {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
type: string;
|
|
33
|
+
uid: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Wagmi config interface
|
|
37
|
+
* This is the config object returned by createConfig() or getDefaultConfig() (RainbowKit)
|
|
38
|
+
*
|
|
39
|
+
* Note: Different Wagmi wrappers (RainbowKit, etc.) may expose state differently:
|
|
40
|
+
* - Some use getState() method
|
|
41
|
+
* - Some expose state as a direct property
|
|
42
|
+
* We support both patterns for maximum compatibility.
|
|
43
|
+
*/
|
|
44
|
+
export interface WagmiConfig {
|
|
45
|
+
subscribe<TData>(selector: (state: WagmiState) => TData, listener: (selectedState: TData, previousSelectedState: TData) => void, options?: {
|
|
46
|
+
equalityFn?: (a: TData, b: TData) => boolean;
|
|
47
|
+
fireImmediately?: boolean;
|
|
48
|
+
}): () => void;
|
|
49
|
+
/**
|
|
50
|
+
* Get state method - available in some Wagmi versions
|
|
51
|
+
*/
|
|
52
|
+
getState?(): WagmiState;
|
|
53
|
+
/**
|
|
54
|
+
* Direct state property - available in RainbowKit and some Wagmi setups
|
|
55
|
+
*/
|
|
56
|
+
state?: WagmiState;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* React Query (TanStack Query) mutation state
|
|
60
|
+
*/
|
|
61
|
+
export interface MutationState {
|
|
62
|
+
status: 'idle' | 'pending' | 'success' | 'error';
|
|
63
|
+
data?: any;
|
|
64
|
+
error?: Error | null;
|
|
65
|
+
variables?: any;
|
|
66
|
+
context?: any;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* React Query mutation object
|
|
70
|
+
*/
|
|
71
|
+
export interface Mutation {
|
|
72
|
+
state: MutationState;
|
|
73
|
+
options: {
|
|
74
|
+
mutationKey?: readonly unknown[];
|
|
75
|
+
[key: string]: any;
|
|
76
|
+
};
|
|
77
|
+
mutationId: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* React Query mutation cache event
|
|
81
|
+
*/
|
|
82
|
+
export interface MutationCacheEvent {
|
|
83
|
+
type: 'added' | 'removed' | 'updated';
|
|
84
|
+
mutation: Mutation;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* React Query MutationCache interface
|
|
88
|
+
*/
|
|
89
|
+
export interface MutationCache {
|
|
90
|
+
subscribe(listener: (event: MutationCacheEvent) => void): () => void;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* React Query QueryClient interface
|
|
94
|
+
*/
|
|
95
|
+
export interface QueryClient {
|
|
96
|
+
getMutationCache(): MutationCache;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Unsubscribe function returned by subscriptions
|
|
100
|
+
*/
|
|
101
|
+
export type UnsubscribeFn = () => void;
|
|
102
|
+
/**
|
|
103
|
+
* Wagmi mutation key types for identifying wallet operations
|
|
104
|
+
*/
|
|
105
|
+
export type WagmiMutationKey = 'signMessage' | 'signTypedData' | 'sendTransaction' | 'writeContract';
|
|
106
|
+
/**
|
|
107
|
+
* Internal tracking state for Wagmi event handler
|
|
108
|
+
*/
|
|
109
|
+
export interface WagmiTrackingState {
|
|
110
|
+
lastChainId?: number;
|
|
111
|
+
lastAddress?: string;
|
|
112
|
+
lastStatus?: WagmiState['status'];
|
|
113
|
+
isProcessing: boolean;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wagmi-specific type definitions for wallet event tracking
|
|
3
|
+
*
|
|
4
|
+
* These types provide TypeScript interfaces for Wagmi v2 integration,
|
|
5
|
+
* allowing the SDK to hook into Wagmi's config.subscribe() and MutationCache
|
|
6
|
+
* to track wallet events without wrapping EIP-1193 providers.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=types.js.map
|