@seekora-ai/search-sdk 1.0.0 → 1.0.2

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.
@@ -0,0 +1,273 @@
1
+ /**
2
+ * Context Collector for Seekora SDK
3
+ *
4
+ * Collects browser context, device information, and fingerprinting
5
+ * for enriching analytics events with comprehensive user environment data.
6
+ *
7
+ * Uses FingerprintJS Open Source for industry-standard device fingerprinting
8
+ * with 50+ browser signals for high accuracy cross-session identification.
9
+ */
10
+ /**
11
+ * Browser and device context collected for analytics enrichment
12
+ */
13
+ export interface BrowserContext {
14
+ screen_width: number;
15
+ screen_height: number;
16
+ viewport_width: number;
17
+ viewport_height: number;
18
+ color_depth: number;
19
+ pixel_ratio: number;
20
+ browser_name: string;
21
+ browser_version: string;
22
+ browser_language: string;
23
+ browser_languages: string[];
24
+ timezone: string;
25
+ timezone_offset: number;
26
+ page_url: string;
27
+ page_path: string;
28
+ page_title: string;
29
+ page_referrer: string;
30
+ document_visibility: string;
31
+ utm_source?: string;
32
+ utm_medium?: string;
33
+ utm_campaign?: string;
34
+ utm_term?: string;
35
+ utm_content?: string;
36
+ connection_type?: string;
37
+ connection_effective_type?: string;
38
+ connection_downlink?: number;
39
+ connection_rtt?: number;
40
+ device_fingerprint?: string;
41
+ platform: string;
42
+ is_mobile: boolean;
43
+ is_tablet: boolean;
44
+ is_touch_device: boolean;
45
+ hardware_concurrency?: number;
46
+ max_touch_points?: number;
47
+ device_memory?: number;
48
+ }
49
+ /**
50
+ * Configuration for context collection
51
+ */
52
+ export interface ContextCollectorConfig {
53
+ /**
54
+ * Enable device fingerprinting (generates a stable device ID)
55
+ * @default true
56
+ */
57
+ enableFingerprinting?: boolean;
58
+ /**
59
+ * Use FingerprintJS library for high-accuracy fingerprinting (recommended)
60
+ * Falls back to manual implementation if FingerprintJS is not available
61
+ * @default true
62
+ */
63
+ useFingerprintJS?: boolean;
64
+ /**
65
+ * Enable canvas fingerprinting (only used in manual mode)
66
+ * @default true
67
+ */
68
+ enableCanvasFingerprint?: boolean;
69
+ /**
70
+ * Enable WebGL fingerprinting (only used in manual mode)
71
+ * @default true
72
+ */
73
+ enableWebGLFingerprint?: boolean;
74
+ /**
75
+ * Enable audio fingerprinting (only used in manual mode)
76
+ * @default false
77
+ */
78
+ enableAudioFingerprint?: boolean;
79
+ /**
80
+ * Automatically collect context on initialization
81
+ * @default true
82
+ */
83
+ autoCollect?: boolean;
84
+ /**
85
+ * Cache context for this many milliseconds (0 = no caching)
86
+ * @default 30000 (30 seconds)
87
+ */
88
+ cacheDuration?: number;
89
+ /**
90
+ * Storage key for fingerprint persistence
91
+ * @default 'seekora_device_fp'
92
+ */
93
+ fingerprintStorageKey?: string;
94
+ /**
95
+ * Enable extended fingerprint components for higher uniqueness
96
+ * Includes fonts, plugins, and other signals
97
+ * @default true
98
+ */
99
+ enableExtendedComponents?: boolean;
100
+ }
101
+ /**
102
+ * ContextCollector class for gathering browser and device context
103
+ *
104
+ * Uses FingerprintJS Open Source for industry-standard fingerprinting
105
+ * with automatic fallback to manual implementation if unavailable.
106
+ */
107
+ export declare class ContextCollector {
108
+ private config;
109
+ private cachedContext;
110
+ private cacheTimestamp;
111
+ private cachedFingerprint;
112
+ private fingerprintJSAgent;
113
+ private fingerprintJSLoading;
114
+ private usingFingerprintJS;
115
+ constructor(config?: ContextCollectorConfig);
116
+ /**
117
+ * Initialize FingerprintJS agent (async, non-blocking)
118
+ */
119
+ private initFingerprintJS;
120
+ /**
121
+ * Get FingerprintJS agent, waiting for initialization if needed
122
+ */
123
+ private getFingerprintJSAgent;
124
+ /**
125
+ * Check if running in browser environment
126
+ */
127
+ private isBrowser;
128
+ /**
129
+ * Collect complete browser context
130
+ */
131
+ collect(): Promise<BrowserContext>;
132
+ /**
133
+ * Collect fresh context without caching
134
+ */
135
+ private collectFresh;
136
+ /**
137
+ * Get server-side context (for Node.js environments)
138
+ */
139
+ private getServerContext;
140
+ /**
141
+ * Get viewport width
142
+ */
143
+ private getViewportWidth;
144
+ /**
145
+ * Get viewport height
146
+ */
147
+ private getViewportHeight;
148
+ /**
149
+ * Get document visibility state
150
+ */
151
+ private getDocumentVisibility;
152
+ /**
153
+ * Get timezone name
154
+ */
155
+ private getTimezone;
156
+ /**
157
+ * Parse UTM parameters from URL
158
+ */
159
+ private parseUTMParameters;
160
+ /**
161
+ * Get connection information from Network Information API
162
+ */
163
+ private getConnectionInfo;
164
+ /**
165
+ * Parse browser name and version from user agent
166
+ */
167
+ private parseBrowserInfo;
168
+ /**
169
+ * Detect platform from user agent
170
+ */
171
+ private detectPlatform;
172
+ /**
173
+ * Check if device is mobile
174
+ */
175
+ private isMobile;
176
+ /**
177
+ * Check if device is tablet
178
+ */
179
+ private isTablet;
180
+ /**
181
+ * Check if device supports touch
182
+ */
183
+ private isTouchDevice;
184
+ /**
185
+ * Sanitize URL to remove sensitive query parameters
186
+ */
187
+ private sanitizeUrl;
188
+ /**
189
+ * Load cached fingerprint from storage
190
+ */
191
+ private loadCachedFingerprint;
192
+ /**
193
+ * Get or generate device fingerprint
194
+ */
195
+ private getOrGenerateFingerprint;
196
+ /**
197
+ * Generate device fingerprint using FingerprintJS or manual fallback
198
+ *
199
+ * FingerprintJS provides ~99.5% accuracy with 50+ browser signals
200
+ * Manual fallback provides ~70% accuracy with 15+ signals
201
+ */
202
+ private generateFingerprint;
203
+ /**
204
+ * Generate fingerprint manually using browser characteristics
205
+ * Used as fallback when FingerprintJS is not available
206
+ */
207
+ private generateManualFingerprint;
208
+ /**
209
+ * Get audio fingerprint using AudioContext
210
+ */
211
+ private getAudioFingerprint;
212
+ /**
213
+ * Get font fingerprint by testing font availability
214
+ */
215
+ private getFontFingerprint;
216
+ /**
217
+ * Get additional WebGL parameters for fingerprinting
218
+ */
219
+ private getWebGLParameters;
220
+ /**
221
+ * Get canvas fingerprint
222
+ */
223
+ private getCanvasFingerprint;
224
+ /**
225
+ * Get WebGL fingerprint
226
+ */
227
+ private getWebGLFingerprint;
228
+ /**
229
+ * Hash array of components into a fingerprint string
230
+ */
231
+ private hashComponents;
232
+ /**
233
+ * Simple hash function (djb2 variant)
234
+ */
235
+ private simpleHash;
236
+ /**
237
+ * Clear cached context
238
+ */
239
+ clearCache(): void;
240
+ /**
241
+ * Clear cached fingerprint (both in memory and storage)
242
+ */
243
+ clearFingerprint(): void;
244
+ /**
245
+ * Get current configuration
246
+ */
247
+ getConfig(): Required<ContextCollectorConfig>;
248
+ /**
249
+ * Update configuration
250
+ */
251
+ updateConfig(config: Partial<ContextCollectorConfig>): void;
252
+ /**
253
+ * Check if using FingerprintJS (vs manual implementation)
254
+ */
255
+ isUsingFingerprintJS(): boolean;
256
+ /**
257
+ * Get fingerprint info including method used and confidence
258
+ */
259
+ getFingerprintInfo(): Promise<{
260
+ fingerprint: string;
261
+ method: 'fingerprintjs' | 'manual';
262
+ confidence?: number;
263
+ componentsCount?: number;
264
+ }>;
265
+ }
266
+ /**
267
+ * Get or create the default context collector
268
+ */
269
+ export declare function getDefaultContextCollector(config?: ContextCollectorConfig): ContextCollector;
270
+ /**
271
+ * Collect browser context using the default collector
272
+ */
273
+ export declare function collectBrowserContext(config?: ContextCollectorConfig): Promise<BrowserContext>;