@formo/analytics 1.19.5 → 1.19.7

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.
@@ -3,4 +3,5 @@ export declare const SESSION_WALLET_DETECTED_KEY = "wallet-detected";
3
3
  export declare const SESSION_CURRENT_URL_KEY = "analytics-current-url";
4
4
  export declare const SESSION_USER_ID_KEY = "user-id";
5
5
  export declare const LOCAL_ANONYMOUS_ID_KEY = "anonymous-id";
6
+ export declare const DEFAULT_PROVIDER_ICON = "data:image/svg+xml;base64,";
6
7
  //# sourceMappingURL=base.d.ts.map
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LOCAL_ANONYMOUS_ID_KEY = exports.SESSION_USER_ID_KEY = exports.SESSION_CURRENT_URL_KEY = exports.SESSION_WALLET_DETECTED_KEY = exports.SESSION_TRAFFIC_SOURCE_KEY = void 0;
3
+ exports.DEFAULT_PROVIDER_ICON = exports.LOCAL_ANONYMOUS_ID_KEY = exports.SESSION_USER_ID_KEY = exports.SESSION_CURRENT_URL_KEY = exports.SESSION_WALLET_DETECTED_KEY = exports.SESSION_TRAFFIC_SOURCE_KEY = void 0;
4
4
  exports.SESSION_TRAFFIC_SOURCE_KEY = "traffic-source";
5
5
  exports.SESSION_WALLET_DETECTED_KEY = "wallet-detected";
6
6
  exports.SESSION_CURRENT_URL_KEY = "analytics-current-url";
7
7
  exports.SESSION_USER_ID_KEY = "user-id";
8
8
  exports.LOCAL_ANONYMOUS_ID_KEY = "anonymous-id";
9
+ // Default provider icon (empty data URL)
10
+ exports.DEFAULT_PROVIDER_ICON = 'data:image/svg+xml;base64,';
9
11
  //# sourceMappingURL=base.js.map
@@ -7,6 +7,19 @@ function formofy(writeKey, options) {
7
7
  FormoAnalytics_1.FormoAnalytics.init(writeKey, options)
8
8
  .then(function (f) {
9
9
  window.formo = f;
10
+ // Call ready callback if provided with proper error handling
11
+ if (options === null || options === void 0 ? void 0 : options.ready) {
12
+ // Wrap the callback execution in a try-catch to handle synchronous errors
13
+ try {
14
+ options.ready(f);
15
+ }
16
+ catch (callbackError) {
17
+ console.error("Error in FormoAnalytics ready callback:", callbackError);
18
+ }
19
+ // Note: If the callback returns a Promise (even though typed as void),
20
+ // it's the responsibility of the callback implementation to handle its own errors.
21
+ // This prevents the callback from throwing unhandled rejections.
22
+ }
10
23
  })
11
24
  .catch(function (e) { return console.error("Error initializing FormoAnalytics:", e); });
12
25
  }
@@ -20,7 +20,7 @@ declare class EventFactory implements IEventFactory {
20
20
  generateDetectWalletEvent(providerName: string, rdns: string, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
21
21
  generateIdentifyEvent(providerName: string, rdns: string, address: Nullable<Address>, userId?: Nullable<string>, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
22
22
  generateConnectEvent(chainId: ChainID, address: Address, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
23
- generateDisconnectEvent(chainId: ChainID, address: Address, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
23
+ generateDisconnectEvent(chainId?: ChainID, address?: Address, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
24
24
  generateChainChangedEvent(chainId: ChainID, address: Address, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
25
25
  generateSignatureEvent(status: SignatureStatus, chainId: ChainID, address: Address, message: string, signatureHash?: string, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
26
26
  generateTransactionEvent(status: TransactionStatus, chainId: ChainID, address: Address, data: string, to: string, value: string, transactionHash?: string, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
@@ -66,7 +66,7 @@ var EventFactory = /** @class */ (function () {
66
66
  var storedTrafficSources = (0, storage_1.session)().get(constants_1.SESSION_TRAFFIC_SOURCE_KEY) || {};
67
67
  var finalTrafficSources = {
68
68
  ref: contextTrafficSources.ref || (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.ref) || "",
69
- referrer: contextTrafficSources.referrer || (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.referrer),
69
+ referrer: contextTrafficSources.referrer || (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.referrer) || "",
70
70
  utm_campaign: contextTrafficSources.utm_campaign ||
71
71
  (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_campaign) ||
72
72
  "",
@@ -71,6 +71,7 @@ export interface Options {
71
71
  enabled?: boolean;
72
72
  levels?: LogLevel[];
73
73
  };
74
+ ready?: (formo: IFormoAnalytics) => void;
74
75
  }
75
76
  export interface FormoAnalyticsProviderProps {
76
77
  writeKey: string;
@@ -79,8 +79,8 @@ export interface ConnectAPIEvent {
79
79
  }
80
80
  export interface DisconnectAPIEvent {
81
81
  type: "disconnect";
82
- chainId: ChainID;
83
- address: Address;
82
+ chainId?: ChainID;
83
+ address?: Address;
84
84
  }
85
85
  export interface TrackAPIEvent {
86
86
  type: "track";
@@ -15,4 +15,12 @@ export interface RPCError extends Error {
15
15
  export interface ConnectInfo {
16
16
  chainId: string;
17
17
  }
18
+ export declare const WRAPPED_REQUEST_SYMBOL: unique symbol;
19
+ export type WrappedRequestFunction = (<T>(args: RequestArguments) => Promise<T | null | undefined>) & {
20
+ [WRAPPED_REQUEST_SYMBOL]?: boolean;
21
+ };
22
+ export declare const WRAPPED_REQUEST_REF_SYMBOL: unique symbol;
23
+ export interface WrappedEIP1193Provider extends EIP1193Provider {
24
+ [WRAPPED_REQUEST_REF_SYMBOL]?: WrappedRequestFunction;
25
+ }
18
26
  //# sourceMappingURL=provider.d.ts.map
@@ -1,3 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WRAPPED_REQUEST_REF_SYMBOL = exports.WRAPPED_REQUEST_SYMBOL = void 0;
4
+ exports.WRAPPED_REQUEST_SYMBOL = Symbol("formoWrappedRequest");
5
+ exports.WRAPPED_REQUEST_REF_SYMBOL = Symbol("formoWrappedRequestRef");
3
6
  //# sourceMappingURL=provider.js.map
@@ -4,14 +4,41 @@ export declare class FormoAnalytics implements IFormoAnalytics {
4
4
  readonly writeKey: string;
5
5
  options: Options;
6
6
  private _provider?;
7
- private _providerListeners;
7
+ private _providerListenersMap;
8
8
  private session;
9
9
  private eventManager;
10
+ /**
11
+ * EIP-6963 provider details discovered through the browser
12
+ * This array contains all available providers with their metadata
13
+ */
10
14
  private _providers;
15
+ /**
16
+ * Set of providers that have been tracked with event listeners
17
+ * This is separate from _providers because:
18
+ * - _providers contains all discovered providers (EIP-6963)
19
+ * - _trackedProviders contains only providers that have been set up with listeners
20
+ * - A provider can be discovered but not yet tracked (e.g., during initialization)
21
+ * - A provider can be tracked but later removed from discovery
22
+ */
23
+ private _trackedProviders;
24
+ private _injectedProviderDetail?;
25
+ private _seenProviders;
11
26
  config: Config;
12
27
  currentChainId?: ChainID;
13
28
  currentAddress?: Address;
14
29
  currentUserId?: string;
30
+ /**
31
+ * Helper method to check if a provider is different from the currently active one
32
+ * @param provider The provider to check
33
+ * @returns true if there's a provider mismatch, false otherwise
34
+ */
35
+ private isProviderMismatch;
36
+ /**
37
+ * Check if a provider is in a valid state for switching
38
+ * @param provider The provider to validate
39
+ * @returns true if the provider is in a valid state
40
+ */
41
+ private isProviderInValidState;
15
42
  private constructor();
16
43
  static init(writeKey: string, options?: Options): Promise<FormoAnalytics>;
17
44
  /**
@@ -36,7 +63,6 @@ export declare class FormoAnalytics implements IFormoAnalytics {
36
63
  * @param {IFormoEventProperties} properties
37
64
  * @param {IFormoEventContext} context
38
65
  * @param {(...args: unknown[]) => void} callback
39
- * @throws {Error} If chainId or address is empty
40
66
  * @returns {Promise<void>}
41
67
  */
42
68
  connect({ chainId, address, }: {
@@ -63,8 +89,6 @@ export declare class FormoAnalytics implements IFormoAnalytics {
63
89
  * @param {IFormoEventProperties} properties
64
90
  * @param {IFormoEventContext} context
65
91
  * @param {(...args: unknown[]) => void} callback
66
- * @throws {Error} If chainId is empty, zero, or not a valid number
67
- * @throws {Error} If no address is provided and no previous address is recorded
68
92
  * @returns {Promise<void>}
69
93
  */
70
94
  chain({ chainId, address, }: {
@@ -153,11 +177,14 @@ export declare class FormoAnalytics implements IFormoAnalytics {
153
177
  */
154
178
  track(event: string, properties?: IFormoEventProperties, context?: IFormoEventContext, callback?: (...args: unknown[]) => void): Promise<void>;
155
179
  private trackProvider;
180
+ private trackProviders;
181
+ private addProviderListener;
156
182
  private registerAccountsChangedListener;
157
183
  private onAccountsChanged;
158
184
  private registerChainChangedListener;
159
185
  private onChainChanged;
160
186
  private registerConnectListener;
187
+ private registerDisconnectListener;
161
188
  private onConnected;
162
189
  private registerRequestListeners;
163
190
  private onLocationChange;
@@ -169,6 +196,18 @@ export declare class FormoAnalytics implements IFormoAnalytics {
169
196
  * @returns {boolean} True if tracking should be enabled
170
197
  */
171
198
  private shouldTrack;
199
+ /**
200
+ * Get provider information for a given provider
201
+ * @param provider The provider to get info for
202
+ * @returns Provider information
203
+ */
204
+ private getProviderInfo;
205
+ /**
206
+ * Attempts to detect information about an injected provider
207
+ * @param provider The injected provider to analyze
208
+ * @returns Provider information with fallback values
209
+ */
210
+ private detectInjectedProviderInfo;
172
211
  private getProviders;
173
212
  get providers(): readonly EIP6963ProviderDetail[];
174
213
  private detectWallets;
@@ -182,5 +221,47 @@ export declare class FormoAnalytics implements IFormoAnalytics {
182
221
  * Polls for transaction receipt and emits tx.status = CONFIRMED or REVERTED.
183
222
  */
184
223
  private pollTransactionReceipt;
224
+ private removeProviderListeners;
225
+ private untrackProvider;
226
+ getTrackedProvidersCount(): number;
227
+ /**
228
+ * Get current provider state for debugging
229
+ * @returns Object containing current provider state information
230
+ */
231
+ getProviderState(): {
232
+ totalProviders: number;
233
+ trackedProviders: number;
234
+ seenProviders: number;
235
+ activeProvider: boolean;
236
+ };
237
+ /**
238
+ * Clean up providers that are no longer available
239
+ * This helps maintain consistent state and prevents memory leaks
240
+ */
241
+ private cleanupUnavailableProviders;
242
+ /**
243
+ * Helper method to check if a provider is already wrapped
244
+ * @param provider The provider to check
245
+ * @param currentRequest The current request function
246
+ * @returns true if the provider is already wrapped
247
+ */
248
+ private isProviderAlreadyWrapped;
249
+ /**
250
+ * Handle provider mismatch by switching to the new provider and invalidating old tokens
251
+ * @param provider The new provider to switch to
252
+ */
253
+ private handleProviderMismatch;
254
+ /**
255
+ * Helper method to validate and checksum an address
256
+ * @param address The address to validate and checksum
257
+ * @returns The checksummed address or undefined if invalid
258
+ */
259
+ private validateAndChecksumAddress;
260
+ /**
261
+ * Helper method to safely add a provider detail to _providers array, ensuring no duplicates
262
+ * @param detail The provider detail to add
263
+ * @returns true if the provider was added, false if it was already present
264
+ */
265
+ private safeAddProviderDetail;
185
266
  }
186
267
  //# sourceMappingURL=FormoAnalytics.d.ts.map