@seekora-ai/search-sdk 0.2.6 → 0.2.8

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.
@@ -1,43 +0,0 @@
1
- /**
2
- * Configuration Loader
3
- *
4
- * Loads SDK configuration from file or environment variables
5
- */
6
- import type { SeekoraClientConfig } from './client';
7
- import type { LogLevel } from './logger';
8
- export interface FileConfig {
9
- storeId?: string;
10
- readSecret?: string;
11
- writeSecret?: string;
12
- baseUrl?: string;
13
- environment?: 'local' | 'stage' | 'production';
14
- timeout?: number;
15
- logLevel?: LogLevel;
16
- logger?: {
17
- level?: LogLevel;
18
- enableConsole?: boolean;
19
- enableFile?: boolean;
20
- filePath?: string;
21
- format?: 'json' | 'text';
22
- };
23
- }
24
- /**
25
- * Load configuration from file
26
- * Note: File loading is only available in Node.js environment
27
- * In browser, this will always return null
28
- */
29
- export declare function loadConfigFromFile(filePath?: string): FileConfig | null;
30
- /**
31
- * Load configuration from environment variables
32
- * Note: In browser, environment variables are not available via process.env
33
- * Use window.SEEKORA_CONFIG or pass config directly to client
34
- */
35
- export declare function loadConfigFromEnv(): Partial<FileConfig>;
36
- /**
37
- * Merge configurations (file config < env config < code config)
38
- */
39
- export declare function mergeConfig(fileConfig: FileConfig | null, envConfig: Partial<FileConfig>, codeConfig: Partial<SeekoraClientConfig>): SeekoraClientConfig;
40
- /**
41
- * Load and merge all configuration sources
42
- */
43
- export declare function loadConfig(codeConfig?: Partial<SeekoraClientConfig>): SeekoraClientConfig;
@@ -1,147 +0,0 @@
1
- "use strict";
2
- /**
3
- * Configuration Loader
4
- *
5
- * Loads SDK configuration from file or environment variables
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.loadConfigFromFile = loadConfigFromFile;
9
- exports.loadConfigFromEnv = loadConfigFromEnv;
10
- exports.mergeConfig = mergeConfig;
11
- exports.loadConfig = loadConfig;
12
- // Browser-safe imports - only import fs/path if in Node.js environment
13
- let fs;
14
- let path;
15
- try {
16
- // Only import in Node.js environment
17
- if (typeof window === 'undefined' && typeof require !== 'undefined') {
18
- fs = require('fs');
19
- path = require('path');
20
- }
21
- }
22
- catch (e) {
23
- // Ignore - we're in browser environment
24
- }
25
- /**
26
- * Default config file paths (checked in order)
27
- */
28
- function getDefaultConfigPaths() {
29
- const paths = [
30
- '.seekora.json',
31
- '.seekora.yaml',
32
- '.seekora.yml',
33
- 'seekora.config.json',
34
- 'seekora.config.yaml',
35
- 'seekora.config.yml',
36
- ];
37
- // Only add home directory paths if we're in Node.js
38
- if (path && typeof process !== 'undefined' && process.env) {
39
- const home = process.env.HOME || process.env.USERPROFILE || '';
40
- if (home) {
41
- paths.push(path.join(home, '.seekora.json'), path.join(home, '.seekora.yaml'));
42
- }
43
- }
44
- return paths;
45
- }
46
- /**
47
- * Load configuration from file
48
- * Note: File loading is only available in Node.js environment
49
- * In browser, this will always return null
50
- */
51
- function loadConfigFromFile(filePath) {
52
- // File system access is not available in browser
53
- if (!fs || typeof window !== 'undefined') {
54
- return null;
55
- }
56
- const pathsToCheck = filePath
57
- ? [filePath]
58
- : getDefaultConfigPaths();
59
- for (const configPath of pathsToCheck) {
60
- if (!configPath)
61
- continue;
62
- try {
63
- // Check if file exists
64
- if (!fs.existsSync(configPath)) {
65
- continue;
66
- }
67
- const content = fs.readFileSync(configPath, 'utf-8');
68
- let config;
69
- // Parse based on file extension
70
- if (configPath.endsWith('.yaml') || configPath.endsWith('.yml')) {
71
- // Try to parse YAML (would need yaml package)
72
- // For now, fallback to JSON
73
- try {
74
- config = JSON.parse(content);
75
- }
76
- catch {
77
- // If JSON parse fails, try to use a simple YAML parser
78
- // For production, use 'yaml' or 'js-yaml' package
79
- throw new Error('YAML parsing not fully supported. Use JSON or install yaml package.');
80
- }
81
- }
82
- else {
83
- config = JSON.parse(content);
84
- }
85
- return config;
86
- }
87
- catch (error) {
88
- // Continue to next file if this one fails
89
- continue;
90
- }
91
- }
92
- return null;
93
- }
94
- /**
95
- * Load configuration from environment variables
96
- * Note: In browser, environment variables are not available via process.env
97
- * Use window.SEEKORA_CONFIG or pass config directly to client
98
- */
99
- function loadConfigFromEnv() {
100
- // In browser, try to get config from window object
101
- if (typeof window !== 'undefined' && window.SEEKORA_CONFIG) {
102
- return window.SEEKORA_CONFIG;
103
- }
104
- // In Node.js, use process.env
105
- if (typeof process !== 'undefined' && process.env) {
106
- return {
107
- storeId: process.env.SEEKORA_STORE_ID,
108
- readSecret: process.env.SEEKORA_READ_SECRET,
109
- writeSecret: process.env.SEEKORA_WRITE_SECRET,
110
- baseUrl: process.env.SEEKORA_BASE_URL,
111
- environment: process.env.SEEKORA_ENV,
112
- timeout: process.env.SEEKORA_TIMEOUT ? parseInt(process.env.SEEKORA_TIMEOUT, 10) : undefined,
113
- logLevel: process.env.SEEKORA_LOG_LEVEL,
114
- };
115
- }
116
- return {};
117
- }
118
- /**
119
- * Merge configurations (file config < env config < code config)
120
- */
121
- function mergeConfig(fileConfig, envConfig, codeConfig) {
122
- const merged = {};
123
- // Start with file config
124
- if (fileConfig) {
125
- Object.assign(merged, fileConfig);
126
- }
127
- // Override with env config
128
- Object.assign(merged, envConfig);
129
- // Override with code config (highest priority)
130
- Object.assign(merged, codeConfig);
131
- // Validate required fields
132
- if (!merged.storeId) {
133
- throw new Error('storeId is required. Provide it in config file, environment variable, or code.');
134
- }
135
- if (!merged.readSecret) {
136
- throw new Error('readSecret is required. Provide it in config file, environment variable, or code.');
137
- }
138
- return merged;
139
- }
140
- /**
141
- * Load and merge all configuration sources
142
- */
143
- function loadConfig(codeConfig = {}) {
144
- const fileConfig = loadConfigFromFile(codeConfig.configFile);
145
- const envConfig = loadConfigFromEnv();
146
- return mergeConfig(fileConfig, envConfig, codeConfig);
147
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * Seekora SDK Configuration
3
- *
4
- * Environment-based configuration for different deployment targets
5
- */
6
- export type SeekoraEnvironment = 'local' | 'stage' | 'production';
7
- export interface EnvironmentConfig {
8
- baseUrl: string;
9
- name: string;
10
- }
11
- /**
12
- * Environment configurations
13
- */
14
- export declare const ENVIRONMENTS: Record<SeekoraEnvironment, EnvironmentConfig>;
15
- /**
16
- * Get base URL for environment
17
- */
18
- export declare function getBaseUrl(environment?: SeekoraEnvironment, customBaseUrl?: string): string;
19
- /**
20
- * Get current environment from config or env var
21
- */
22
- export declare function getEnvironment(environment?: SeekoraEnvironment): SeekoraEnvironment;
@@ -1,58 +0,0 @@
1
- "use strict";
2
- /**
3
- * Seekora SDK Configuration
4
- *
5
- * Environment-based configuration for different deployment targets
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.ENVIRONMENTS = void 0;
9
- exports.getBaseUrl = getBaseUrl;
10
- exports.getEnvironment = getEnvironment;
11
- /**
12
- * Environment configurations
13
- */
14
- exports.ENVIRONMENTS = {
15
- local: {
16
- baseUrl: 'http://localhost:3000',
17
- name: 'Local Development',
18
- },
19
- stage: {
20
- baseUrl: 'https://stage-api.seekora.ai/api',
21
- name: 'Staging',
22
- },
23
- production: {
24
- baseUrl: 'https://api.seekora.com/api',
25
- name: 'Production',
26
- },
27
- };
28
- /**
29
- * Get base URL for environment
30
- */
31
- function getBaseUrl(environment, customBaseUrl) {
32
- if (customBaseUrl) {
33
- return customBaseUrl;
34
- }
35
- // Check environment variable first (Node.js) or window variable (browser)
36
- let envFromVar;
37
- if (typeof process !== 'undefined' && process.env) {
38
- envFromVar = process.env.SEEKORA_ENV;
39
- }
40
- else if (typeof window !== 'undefined' && window.SEEKORA_ENV) {
41
- envFromVar = window.SEEKORA_ENV;
42
- }
43
- const env = environment || envFromVar || 'stage';
44
- return exports.ENVIRONMENTS[env]?.baseUrl || exports.ENVIRONMENTS.stage.baseUrl;
45
- }
46
- /**
47
- * Get current environment from config or env var
48
- */
49
- function getEnvironment(environment) {
50
- let envFromVar;
51
- if (typeof process !== 'undefined' && process.env) {
52
- envFromVar = process.env.SEEKORA_ENV;
53
- }
54
- else if (typeof window !== 'undefined' && window.SEEKORA_ENV) {
55
- envFromVar = window.SEEKORA_ENV;
56
- }
57
- return environment || envFromVar || 'stage';
58
- }
@@ -1,273 +0,0 @@
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>;