@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.
package/cdn/_headers CHANGED
@@ -23,3 +23,6 @@
23
23
  Cache-Control: public, max-age=3600
24
24
  Content-Type: application/json; charset=utf-8
25
25
 
26
+
27
+
28
+
@@ -5,6 +5,8 @@
5
5
  import type { DataTypesIndexConfig, DataTypesEventPayload } from '../generated';
6
6
  import { type SeekoraEnvironment } from './config';
7
7
  import { Logger, type LogLevel, type LoggerConfig } from './logger';
8
+ import { type ContextCollectorConfig, type BrowserContext } from './context-collector';
9
+ import { EventQueue, type EventQueueConfig } from './event-queue';
8
10
  export interface SeekoraClientConfig {
9
11
  storeId?: string;
10
12
  readSecret?: string;
@@ -34,6 +36,24 @@ export interface SeekoraClientConfig {
34
36
  * @default false
35
37
  */
36
38
  autoTrackSearch?: boolean;
39
+ /**
40
+ * Enable automatic context collection (screen, viewport, timezone, UTM, etc.)
41
+ * @default true
42
+ */
43
+ enableContextCollection?: boolean;
44
+ /**
45
+ * Context collector configuration
46
+ */
47
+ contextCollector?: ContextCollectorConfig;
48
+ /**
49
+ * Enable event queue for offline buffering and retry
50
+ * @default false
51
+ */
52
+ enableEventQueue?: boolean;
53
+ /**
54
+ * Event queue configuration
55
+ */
56
+ eventQueue?: EventQueueConfig;
37
57
  }
38
58
  /**
39
59
  * Search context containing identifiers for linking events to searches
@@ -54,20 +74,75 @@ export interface SearchContext {
54
74
  sessionId: string;
55
75
  }
56
76
  /**
57
- * Extended event payload with correlation_id and search_id at top level
77
+ * Extended event payload with correlation_id, search_id, and browser context
58
78
  * (per identifier spec requirements)
59
79
  *
60
80
  * This extends the base DataTypesEventPayload to include:
61
81
  * - correlation_id: Required for linking events to search journeys
62
82
  * - search_id: Optional, but should be included when available
83
+ * - Browser context: Screen, viewport, timezone, UTM, etc.
63
84
  *
64
- * Both fields are set at the top level (not just in metadata) per spec.
85
+ * Both correlation_id and search_id are set at the top level (not just in metadata) per spec.
65
86
  */
66
87
  export interface ExtendedEventPayload extends DataTypesEventPayload {
67
88
  /** Correlation ID for linking events to search journeys */
68
89
  correlation_id?: string;
69
90
  /** Search ID at top level (also in metadata for backward compat) */
70
91
  search_id?: string;
92
+ /** Screen width in pixels */
93
+ screen_width?: number;
94
+ /** Screen height in pixels */
95
+ screen_height?: number;
96
+ /** Viewport width in pixels */
97
+ viewport_width?: number;
98
+ /** Viewport height in pixels */
99
+ viewport_height?: number;
100
+ /** Color depth */
101
+ color_depth?: number;
102
+ /** Device pixel ratio */
103
+ pixel_ratio?: number;
104
+ /** Device fingerprint (if enabled) */
105
+ device_fingerprint?: string;
106
+ /** Browser name (chrome, firefox, safari, etc.) */
107
+ browser_name?: string;
108
+ /** Browser version */
109
+ browser_version?: string;
110
+ /** Browser language */
111
+ browser_language?: string;
112
+ /** User timezone (e.g., "America/New_York") */
113
+ timezone?: string;
114
+ /** Timezone offset in minutes */
115
+ timezone_offset?: number;
116
+ /** Current page URL */
117
+ page_url?: string;
118
+ /** Current page path */
119
+ page_path?: string;
120
+ /** Current page title */
121
+ page_title?: string;
122
+ /** Page referrer URL */
123
+ page_referrer?: string;
124
+ /** UTM source parameter */
125
+ utm_source?: string;
126
+ /** UTM medium parameter */
127
+ utm_medium?: string;
128
+ /** UTM campaign parameter */
129
+ utm_campaign?: string;
130
+ /** UTM term parameter */
131
+ utm_term?: string;
132
+ /** UTM content parameter */
133
+ utm_content?: string;
134
+ /** Connection type (wifi, cellular, etc.) */
135
+ connection_type?: string;
136
+ /** Effective connection type (4g, 3g, 2g, slow-2g) */
137
+ connection_effective_type?: string;
138
+ /** Platform (windows, macos, linux, android, ios) */
139
+ platform?: string;
140
+ /** Is mobile device */
141
+ is_mobile?: boolean;
142
+ /** Is tablet device */
143
+ is_tablet?: boolean;
144
+ /** Is touch-capable device */
145
+ is_touch_device?: boolean;
71
146
  }
72
147
  export interface SearchOptions {
73
148
  q: string;
@@ -140,6 +215,87 @@ export interface QuerySuggestionsFullResponse {
140
215
  /** Raw API response data */
141
216
  raw?: any;
142
217
  }
218
+ /**
219
+ * Response from indexing a single document
220
+ */
221
+ export interface IndexDocumentResponse {
222
+ /** The document ID (either provided or auto-generated) */
223
+ id: string;
224
+ /** Whether the document was successfully indexed */
225
+ success: boolean;
226
+ /** Optional message from the server */
227
+ message?: string;
228
+ /** Raw response data */
229
+ data?: Record<string, any>;
230
+ }
231
+ /**
232
+ * Response from bulk document indexing
233
+ */
234
+ export interface BulkIndexResponse {
235
+ /** Number of documents successfully processed */
236
+ success_count: number;
237
+ /** Number of documents that failed */
238
+ error_count: number;
239
+ /** Array of results for each document */
240
+ results: Array<{
241
+ id?: string;
242
+ success: boolean;
243
+ error?: string;
244
+ }>;
245
+ /** Raw response data */
246
+ data?: Record<string, any>;
247
+ }
248
+ /**
249
+ * Response from deleting a document
250
+ */
251
+ export interface DeleteDocumentResponse {
252
+ /** Whether the document was successfully deleted */
253
+ success: boolean;
254
+ /** The ID of the deleted document */
255
+ id: string;
256
+ /** Optional message from the server */
257
+ message?: string;
258
+ }
259
+ /**
260
+ * Schema field definition for creating collection schema
261
+ */
262
+ export interface SchemaField {
263
+ name: string;
264
+ type: 'string' | 'int32' | 'int64' | 'float' | 'bool' | 'string[]' | 'int32[]' | 'int64[]' | 'float[]' | 'bool[]' | 'object' | 'object[]' | 'auto' | 'geopoint' | 'geopoint[]';
265
+ facet?: boolean;
266
+ index?: boolean;
267
+ optional?: boolean;
268
+ sort?: boolean;
269
+ infix?: boolean;
270
+ locale?: string;
271
+ }
272
+ /**
273
+ * Request for creating or updating collection schema
274
+ */
275
+ export interface CreateSchemaRequest {
276
+ fields: SchemaField[];
277
+ mode?: 'additive' | 'replace';
278
+ confirmDelete?: boolean;
279
+ defaultSortingField?: string;
280
+ enableNestedFields?: boolean;
281
+ }
282
+ /**
283
+ * Response from schema operations
284
+ */
285
+ export interface SchemaResponse {
286
+ name: string;
287
+ fields: SchemaField[];
288
+ defaultSortingField?: string;
289
+ numDocuments: number;
290
+ createdAt?: number;
291
+ }
292
+ /**
293
+ * Response from clear documents operation
294
+ */
295
+ export interface ClearDocumentsResponse {
296
+ deletedCount: number;
297
+ message: string;
298
+ }
143
299
  /**
144
300
  * Seekora SDK Client
145
301
  *
@@ -152,6 +308,8 @@ export declare class SeekoraClient {
152
308
  private suggestionsConfigApi;
153
309
  private analyticsApi;
154
310
  private storesApi;
311
+ private documentsApi;
312
+ private schemaApi;
155
313
  private storeId;
156
314
  private readSecret;
157
315
  private writeSecret?;
@@ -160,6 +318,11 @@ export declare class SeekoraClient {
160
318
  private anonId;
161
319
  private sessionId;
162
320
  private autoTrackSearch;
321
+ private enableContextCollection;
322
+ private contextCollector;
323
+ private cachedBrowserContext;
324
+ private enableEventQueue;
325
+ private eventQueue;
163
326
  constructor(config?: SeekoraClientConfig);
164
327
  /**
165
328
  * Search for documents
@@ -248,7 +411,116 @@ export declare class SeekoraClient {
248
411
  */
249
412
  getConfigSchema(): Promise<any>;
250
413
  /**
251
- * Build event payload with identifiers
414
+ * Index a single document into the store
415
+ *
416
+ * @param document - Document data with optional id
417
+ * @returns IndexDocumentResponse with document id and status
418
+ */
419
+ indexDocument(document: {
420
+ id?: string;
421
+ data: Record<string, any>;
422
+ }): Promise<IndexDocumentResponse>;
423
+ /**
424
+ * Index multiple documents in bulk
425
+ *
426
+ * @param documents - Array of documents with optional actions (insert/update/upsert/delete)
427
+ * @returns BulkIndexResponse with success/error counts
428
+ */
429
+ indexDocuments(documents: Array<{
430
+ id?: string;
431
+ action?: string;
432
+ data: Record<string, any>;
433
+ }>): Promise<BulkIndexResponse>;
434
+ /**
435
+ * Delete a document by ID
436
+ *
437
+ * @param documentId - Document ID to delete
438
+ */
439
+ deleteDocument(documentId: string): Promise<void>;
440
+ /**
441
+ * Create or update the collection schema for this store
442
+ *
443
+ * @param request - Schema request with fields and options
444
+ * @returns SchemaResponse with the created/updated schema
445
+ *
446
+ * @example
447
+ * // Create a new schema
448
+ * const schema = await client.createSchema({
449
+ * fields: [
450
+ * { name: 'title', type: 'string' },
451
+ * { name: 'content', type: 'string' },
452
+ * { name: 'url', type: 'string' },
453
+ * { name: 'hierarchy.lvl0', type: 'string', facet: true }
454
+ * ]
455
+ * });
456
+ *
457
+ * @example
458
+ * // Add new fields to existing schema (additive mode)
459
+ * const schema = await client.createSchema({
460
+ * fields: [{ name: 'newField', type: 'string' }],
461
+ * mode: 'additive'
462
+ * });
463
+ *
464
+ * @example
465
+ * // Replace entire schema (destructive, clears all documents)
466
+ * const schema = await client.createSchema({
467
+ * fields: [...],
468
+ * mode: 'replace',
469
+ * confirmDelete: true
470
+ * });
471
+ */
472
+ createSchema(request: CreateSchemaRequest): Promise<SchemaResponse>;
473
+ /**
474
+ * Get the current collection schema for this store
475
+ *
476
+ * @returns SchemaResponse with the current schema
477
+ *
478
+ * @example
479
+ * const schema = await client.getSchema();
480
+ * console.log('Fields:', schema.fields.map(f => f.name));
481
+ * console.log('Documents:', schema.numDocuments);
482
+ */
483
+ getSchema(): Promise<SchemaResponse>;
484
+ /**
485
+ * Clear all documents from the store's collection
486
+ *
487
+ * This deletes all documents but preserves the collection and its schema.
488
+ * Useful for re-indexing data from scratch.
489
+ *
490
+ * @returns ClearDocumentsResponse with count of deleted documents
491
+ *
492
+ * @example
493
+ * const result = await client.clearDocuments();
494
+ * console.log(`Cleared ${result.deletedCount} documents`);
495
+ */
496
+ clearDocuments(): Promise<ClearDocumentsResponse>;
497
+ /**
498
+ * Asynchronously collect browser context (called during initialization)
499
+ */
500
+ private collectContextAsync;
501
+ /**
502
+ * Create the event sender function for the event queue
503
+ */
504
+ private createQueueSender;
505
+ /**
506
+ * Send a single event directly to the backend (bypasses queue)
507
+ */
508
+ private sendEventDirect;
509
+ /**
510
+ * Send a batch of events directly to the backend (bypasses queue)
511
+ */
512
+ private sendEventsBatchDirect;
513
+ /**
514
+ * Get browser context (sync if cached, otherwise returns null)
515
+ * Use collectBrowserContext() for async collection
516
+ */
517
+ getBrowserContext(): BrowserContext | null;
518
+ /**
519
+ * Collect browser context asynchronously
520
+ */
521
+ collectBrowserContext(): Promise<BrowserContext>;
522
+ /**
523
+ * Build event payload with identifiers and browser context
252
524
  * Ensures user_id or anon_id is present, and sets correlation_id/search_id at top level
253
525
  */
254
526
  private buildEventPayload;
@@ -389,6 +661,42 @@ export declare class SeekoraClient {
389
661
  anonId: string;
390
662
  sessionId: string;
391
663
  };
664
+ /**
665
+ * Get the event queue instance (if enabled)
666
+ */
667
+ getEventQueue(): EventQueue | null;
668
+ /**
669
+ * Flush the event queue manually
670
+ * Useful when you want to ensure events are sent before page unload
671
+ */
672
+ flushEventQueue(): Promise<void>;
673
+ /**
674
+ * Get event queue statistics
675
+ */
676
+ getEventQueueStats(): {
677
+ enabled: boolean;
678
+ queueSize: number;
679
+ isOnline: boolean;
680
+ isFlushing: boolean;
681
+ oldestEventAge: number | null;
682
+ pendingRetries: number;
683
+ } | null;
684
+ /**
685
+ * Identify a user and link their anonymous ID/fingerprint to their user ID
686
+ * Call this when a user logs in to enable cross-device/session tracking
687
+ *
688
+ * @param userId - The authenticated user ID
689
+ * @param traits - Optional user traits/properties
690
+ */
691
+ identify(userId: string, traits?: Record<string, any>): Promise<void>;
692
+ /**
693
+ * Alias an anonymous ID to a user ID
694
+ * Use this when you want to link an external anonymous ID to a user
695
+ *
696
+ * @param anonId - The anonymous ID to alias
697
+ * @param userId - The user ID to link to
698
+ */
699
+ alias(anonId: string, userId: string): Promise<void>;
392
700
  /**
393
701
  * Handle errors consistently
394
702
  */