@formo/analytics 1.35.2 → 1.37.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/dist/cjs/src/FormoAnalytics.d.ts +79 -363
- package/dist/cjs/src/FormoAnalytics.js +368 -2234
- package/dist/cjs/src/event/EventManager.d.ts +3 -1
- package/dist/cjs/src/event/EventManager.js +5 -1
- package/dist/cjs/src/event/type.d.ts +1 -0
- package/dist/cjs/src/evm/EvmEventTracker.d.ts +175 -0
- package/dist/cjs/src/evm/EvmEventTracker.js +1030 -0
- package/dist/cjs/src/evm/EvmProviderRegistry.d.ts +132 -0
- package/dist/cjs/src/evm/EvmProviderRegistry.js +348 -0
- package/dist/cjs/src/evm/EvmRequestTracker.d.ts +98 -0
- package/dist/cjs/src/evm/EvmRequestTracker.js +713 -0
- package/dist/cjs/src/evm/batch.d.ts +94 -0
- package/dist/cjs/src/evm/batch.js +130 -0
- package/dist/cjs/src/queue/EventQueue.d.ts +28 -0
- package/dist/cjs/src/queue/EventQueue.js +97 -19
- package/dist/cjs/src/queue/type.d.ts +1 -0
- package/dist/cjs/src/tracking/TrackingPolicy.d.ts +146 -0
- package/dist/cjs/src/tracking/TrackingPolicy.js +200 -0
- package/dist/cjs/src/validators/address.d.ts +1 -1
- 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 +43 -0
- package/dist/cjs/src/wagmi/WagmiEventHandler.js +253 -2
- package/dist/cjs/src/wallet/WalletStateStore.d.ts +223 -0
- package/dist/cjs/src/wallet/WalletStateStore.js +515 -0
- package/dist/esm/src/FormoAnalytics.d.ts +79 -363
- package/dist/esm/src/FormoAnalytics.js +369 -2235
- package/dist/esm/src/event/EventManager.d.ts +3 -1
- package/dist/esm/src/event/EventManager.js +5 -1
- package/dist/esm/src/event/type.d.ts +1 -0
- package/dist/esm/src/evm/EvmEventTracker.d.ts +175 -0
- package/dist/esm/src/evm/EvmEventTracker.js +1027 -0
- package/dist/esm/src/evm/EvmProviderRegistry.d.ts +132 -0
- package/dist/esm/src/evm/EvmProviderRegistry.js +345 -0
- package/dist/esm/src/evm/EvmRequestTracker.d.ts +98 -0
- package/dist/esm/src/evm/EvmRequestTracker.js +710 -0
- package/dist/esm/src/evm/batch.d.ts +94 -0
- package/dist/esm/src/evm/batch.js +123 -0
- package/dist/esm/src/queue/EventQueue.d.ts +28 -0
- package/dist/esm/src/queue/EventQueue.js +97 -19
- package/dist/esm/src/queue/type.d.ts +1 -0
- package/dist/esm/src/tracking/TrackingPolicy.d.ts +146 -0
- package/dist/esm/src/tracking/TrackingPolicy.js +197 -0
- 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 +43 -0
- package/dist/esm/src/wagmi/WagmiEventHandler.js +253 -2
- package/dist/esm/src/wallet/WalletStateStore.d.ts +223 -0
- package/dist/esm/src/wallet/WalletStateStore.js +512 -0
- package/dist/index.umd.min.js +1 -1
- package/package.json +6 -4
|
@@ -18,8 +18,10 @@ declare class EventManager implements IEventManager {
|
|
|
18
18
|
* @param event Incoming event data
|
|
19
19
|
*/
|
|
20
20
|
addEvent(event: APIEvent, address?: Address, userId?: string): Promise<void>;
|
|
21
|
-
/** Drop any buffered events (consent withdrawal
|
|
21
|
+
/** Drop any buffered events (consent withdrawal). Recoverable. */
|
|
22
22
|
clear(): void;
|
|
23
|
+
/** Terminal shutdown on teardown: nothing can be sent after this. */
|
|
24
|
+
close(): void;
|
|
23
25
|
}
|
|
24
26
|
export { EventManager };
|
|
25
27
|
//# sourceMappingURL=EventManager.d.ts.map
|
|
@@ -93,10 +93,14 @@ var EventManager = /** @class */ (function () {
|
|
|
93
93
|
});
|
|
94
94
|
});
|
|
95
95
|
};
|
|
96
|
-
/** Drop any buffered events (consent withdrawal
|
|
96
|
+
/** Drop any buffered events (consent withdrawal). Recoverable. */
|
|
97
97
|
EventManager.prototype.clear = function () {
|
|
98
98
|
this.eventQueue.clear();
|
|
99
99
|
};
|
|
100
|
+
/** Terminal shutdown on teardown: nothing can be sent after this. */
|
|
101
|
+
EventManager.prototype.close = function () {
|
|
102
|
+
this.eventQueue.close();
|
|
103
|
+
};
|
|
100
104
|
return EventManager;
|
|
101
105
|
}());
|
|
102
106
|
export { EventManager };
|
|
@@ -2,6 +2,7 @@ import { Address, APIEvent, IFormoEvent } from "../types";
|
|
|
2
2
|
export interface IEventManager {
|
|
3
3
|
addEvent(event: APIEvent, address?: Address, userId?: string): Promise<void>;
|
|
4
4
|
clear(): void;
|
|
5
|
+
close(): void;
|
|
5
6
|
}
|
|
6
7
|
export interface IEventFactory {
|
|
7
8
|
create(event: APIEvent, address?: Address, userId?: string): Promise<IFormoEvent>;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { EIP6963ProviderDetail } from "mipd";
|
|
2
|
+
import { Address, ChainID, EIP1193Provider, IFormoEventProperties } from "../types";
|
|
3
|
+
import { WalletStateStore } from "../wallet/WalletStateStore";
|
|
4
|
+
import { EvmProviderRegistry } from "./EvmProviderRegistry";
|
|
5
|
+
import { AutocaptureEventType } from "../tracking/TrackingPolicy";
|
|
6
|
+
/** What the tracker needs from the SDK that owns it. */
|
|
7
|
+
export interface EvmEventTrackerDeps {
|
|
8
|
+
/** Whether this wallet event kind is enabled for autocapture. */
|
|
9
|
+
isAutocaptureEnabled(eventType: AutocaptureEventType): boolean;
|
|
10
|
+
/** Visitor-level or page-level suppression: never LEARN a wallet. */
|
|
11
|
+
isTrackingSuppressed(): boolean;
|
|
12
|
+
/** Whether an event on this chain would actually be sent. */
|
|
13
|
+
willTrackEvent(chainId?: ChainID): boolean;
|
|
14
|
+
/** In wagmi mode the SDK does not wrap providers itself. */
|
|
15
|
+
isWagmiMode(): boolean;
|
|
16
|
+
/** Emission. The tracker decides WHEN; the SDK owns the event API. */
|
|
17
|
+
connect(params: {
|
|
18
|
+
chainId: ChainID;
|
|
19
|
+
address: Address;
|
|
20
|
+
}, properties?: IFormoEventProperties): Promise<void>;
|
|
21
|
+
disconnect(params?: {
|
|
22
|
+
chainId?: ChainID;
|
|
23
|
+
address?: Address;
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
chain(params: {
|
|
26
|
+
chainId: ChainID;
|
|
27
|
+
address?: Address;
|
|
28
|
+
}, properties?: IFormoEventProperties): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* `rdns` is the session dedup key for detect, so it must reach `detect()`
|
|
31
|
+
* exactly as the wallet announced it. Required here rather than optional
|
|
32
|
+
* so no caller can quietly substitute a placeholder for a missing value.
|
|
33
|
+
*/
|
|
34
|
+
detect(params: {
|
|
35
|
+
providerName: string;
|
|
36
|
+
rdns: string;
|
|
37
|
+
}): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Install the request wrapper that captures signatures and transactions.
|
|
40
|
+
*
|
|
41
|
+
* Still owned by the SDK: it is the next thing to move, and keeping it out
|
|
42
|
+
* of this change keeps the diff reviewable.
|
|
43
|
+
*/
|
|
44
|
+
registerRequestListeners(provider: EIP1193Provider): boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The EIP-1193 side of wallet tracking: which providers to watch, and what
|
|
48
|
+
* their events mean.
|
|
49
|
+
*
|
|
50
|
+
* Split out of `FormoAnalytics` (#336). It holds no wallet state and no
|
|
51
|
+
* provider registry of its own - those have owners already - so what is left
|
|
52
|
+
* here is the part that is genuinely about interpreting wallet events:
|
|
53
|
+
* deciding when a connect has to be reported, when a switch is stale, and
|
|
54
|
+
* when a provider has stopped being the one we follow.
|
|
55
|
+
*/
|
|
56
|
+
export declare class EvmEventTracker {
|
|
57
|
+
private readonly wallet;
|
|
58
|
+
private readonly registry;
|
|
59
|
+
private readonly deps;
|
|
60
|
+
/**
|
|
61
|
+
* The connect this SDK has already reported for a provider.
|
|
62
|
+
*
|
|
63
|
+
* Connection REPORTING, which is why it lives with the handlers rather than
|
|
64
|
+
* with wallet state. The store tells us when a provider stops being active,
|
|
65
|
+
* which is when a record must lapse.
|
|
66
|
+
*/
|
|
67
|
+
private _announcedConnect;
|
|
68
|
+
/**
|
|
69
|
+
* The EIP-6963 discovery subscription, so teardown can release it. Left
|
|
70
|
+
* live, a disposed SDK kept reacting to every later wallet announcement:
|
|
71
|
+
* wrapping providers and emitting detect events from an instance the host
|
|
72
|
+
* had already replaced.
|
|
73
|
+
*/
|
|
74
|
+
private unsubscribeDiscovery?;
|
|
75
|
+
constructor(wallet: WalletStateStore, registry: EvmProviderRegistry, deps: EvmEventTrackerDeps);
|
|
76
|
+
/** Stop listening for wallet announcements. Called from SDK teardown. */
|
|
77
|
+
cleanup(): void;
|
|
78
|
+
/** Drop a provider's reported connect. Called when it stops being active. */
|
|
79
|
+
forgetAnnouncedConnect(provider: EIP1193Provider): void;
|
|
80
|
+
/**
|
|
81
|
+
* Helper method to check if a provider is different from the currently active one
|
|
82
|
+
* @param provider The provider to check
|
|
83
|
+
* @returns true if there's a provider mismatch, false otherwise
|
|
84
|
+
*/
|
|
85
|
+
private isProviderMismatch;
|
|
86
|
+
/**
|
|
87
|
+
* Track an EIP-1193 provider by wrapping its request method and adding event listeners
|
|
88
|
+
* Note: This is only used in non-Wagmi mode. When Wagmi is enabled, all tracking
|
|
89
|
+
* happens through Wagmi's connector system instead of EIP-1193/EIP-6963.
|
|
90
|
+
* @param provider The EIP-1193 provider to track
|
|
91
|
+
*/
|
|
92
|
+
trackEIP1193Provider(provider: EIP1193Provider): void;
|
|
93
|
+
trackProviders(providers: readonly EIP6963ProviderDetail[]): void;
|
|
94
|
+
private registerAccountsChangedListener;
|
|
95
|
+
private onAccountsChanged;
|
|
96
|
+
/**
|
|
97
|
+
* Handles changes to the accounts of a given EIP-1193 provider.
|
|
98
|
+
*
|
|
99
|
+
* @param provider - The EIP-1193 provider whose accounts have changed.
|
|
100
|
+
* @param accounts - The new array of account addresses. An empty array indicates a disconnect.
|
|
101
|
+
* @returns A promise that resolves when the account change has been processed.
|
|
102
|
+
*
|
|
103
|
+
* If the accounts array is empty and the provider is the active provider, this method triggers
|
|
104
|
+
* a disconnect flow. Otherwise, it updates the state to reflect the new accounts as needed.
|
|
105
|
+
*/
|
|
106
|
+
private _handleAccountsChanged;
|
|
107
|
+
private registerChainChangedListener;
|
|
108
|
+
private onChainChanged;
|
|
109
|
+
/**
|
|
110
|
+
* Record a provider's chain from its `connect` event, and nothing else.
|
|
111
|
+
*
|
|
112
|
+
* Used when connect autocapture is off. `connect` carries `chainId` in its
|
|
113
|
+
* payload, so this needs no RPC - unlike the full handler, which resolves
|
|
114
|
+
* the account.
|
|
115
|
+
*/
|
|
116
|
+
private registerConnectChainObserver;
|
|
117
|
+
/**
|
|
118
|
+
* Whether a connect for this wallet still needs reporting.
|
|
119
|
+
*
|
|
120
|
+
* True when nothing has been reported for this provider, or when the account
|
|
121
|
+
* changed. A wallet already reported is not reported again.
|
|
122
|
+
*
|
|
123
|
+
* Deliberately does NOT re-report to correct a chain. When `accountsChanged`
|
|
124
|
+
* wins the race on a provider that exposes no synchronous `chainId`, the
|
|
125
|
+
* connect carries 0 - honestly, since the chain is unknown at that instant -
|
|
126
|
+
* and the `connect` payload that follows knows the real one. Emitting again
|
|
127
|
+
* to relabel would mean two connects for one connection, which is the bug
|
|
128
|
+
* this whole path exists to prevent. That payload still corrects
|
|
129
|
+
* `currentChainId`, so everything after it is attributed properly.
|
|
130
|
+
*/
|
|
131
|
+
private shouldReportConnect;
|
|
132
|
+
/**
|
|
133
|
+
* Record a connect as reported - but only if it will actually be sent.
|
|
134
|
+
*
|
|
135
|
+
* `connect()` passes through `shouldTrack()`, which refuses an unresolvable
|
|
136
|
+
* chain when `tracking.excludeChains` is configured. Marking a refused event
|
|
137
|
+
* as reported would suppress the authoritative one that follows.
|
|
138
|
+
*/
|
|
139
|
+
private markConnectReported;
|
|
140
|
+
private registerConnectListener;
|
|
141
|
+
private registerDisconnectListener;
|
|
142
|
+
private onConnected;
|
|
143
|
+
getProviders(): Promise<readonly EIP6963ProviderDetail[]>;
|
|
144
|
+
detectWallets(providers: readonly EIP6963ProviderDetail[]): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Seed a provider's chain from whatever it already exposes synchronously.
|
|
147
|
+
*
|
|
148
|
+
* Most EIP-1193 implementations carry a `chainId` property (MetaMask,
|
|
149
|
+
* WalletConnect, Coinbase). Reading it costs nothing and cannot block.
|
|
150
|
+
*
|
|
151
|
+
* There is deliberately no RPC fallback. An earlier version probed with
|
|
152
|
+
* `eth_chainId` when a provider was first tracked, on the theory that
|
|
153
|
+
* tracking time is off the user's critical path. It is not: a serialized
|
|
154
|
+
* transport has ONE queue, so a stalled probe sits in front of every later
|
|
155
|
+
* signature and transaction the dapp makes. It could also land out of order
|
|
156
|
+
* - a slow probe response overwriting a newer `chainChanged` - and relabel
|
|
157
|
+
* events onto a chain the wallet had already left.
|
|
158
|
+
*
|
|
159
|
+
* A provider that exposes nothing stays unknown until it emits
|
|
160
|
+
* `chainChanged` or `connect`, and unknown is reported honestly as 0.
|
|
161
|
+
*/
|
|
162
|
+
private seedProviderChainFromState;
|
|
163
|
+
untrackProvider(provider: EIP1193Provider): void;
|
|
164
|
+
/**
|
|
165
|
+
* Clean up providers that are no longer available
|
|
166
|
+
* This helps maintain consistent state and prevents memory leaks
|
|
167
|
+
*/
|
|
168
|
+
private cleanupUnavailableProviders;
|
|
169
|
+
/**
|
|
170
|
+
* Handle provider mismatch by switching to the new provider and invalidating old tokens
|
|
171
|
+
* @param provider The new provider to switch to
|
|
172
|
+
*/
|
|
173
|
+
private handleProviderMismatch;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=EvmEventTracker.d.ts.map
|