@seekora-ai/search-sdk 0.2.7 → 0.2.12
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/client.d.ts +121 -2
- package/dist/client.js +219 -9
- package/dist/generated/api.d.ts +291 -20
- package/dist/generated/api.js +449 -23
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14 -1
- package/dist/ui-components.d.ts +74 -0
- package/dist/ui-components.js +165 -0
- package/package.json +1 -1
- package/dist/src/cdn.d.ts +0 -16
- package/dist/src/cdn.js +0 -26
- package/dist/src/client.d.ts +0 -709
- package/dist/src/client.js +0 -1548
- package/dist/src/config-loader.d.ts +0 -43
- package/dist/src/config-loader.js +0 -147
- package/dist/src/config.d.ts +0 -22
- package/dist/src/config.js +0 -58
- package/dist/src/context-collector.d.ts +0 -273
- package/dist/src/context-collector.js +0 -868
- package/dist/src/event-queue.d.ts +0 -195
- package/dist/src/event-queue.js +0 -424
- package/dist/src/index.d.ts +0 -14
- package/dist/src/index.js +0 -48
- package/dist/src/logger.d.ts +0 -61
- package/dist/src/logger.js +0 -172
- package/dist/src/utils.d.ts +0 -20
- package/dist/src/utils.js +0 -73
package/dist/src/client.d.ts
DELETED
|
@@ -1,709 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Seekora SDK Client
|
|
3
|
-
* High-level wrapper around generated OpenAPI client
|
|
4
|
-
*/
|
|
5
|
-
import type { DataTypesIndexConfig, DataTypesEventPayload } from '../generated';
|
|
6
|
-
import { type SeekoraEnvironment } from './config';
|
|
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';
|
|
10
|
-
export interface SeekoraClientConfig {
|
|
11
|
-
storeId?: string;
|
|
12
|
-
readSecret?: string;
|
|
13
|
-
writeSecret?: string;
|
|
14
|
-
baseUrl?: string;
|
|
15
|
-
environment?: SeekoraEnvironment;
|
|
16
|
-
timeout?: number;
|
|
17
|
-
logLevel?: LogLevel;
|
|
18
|
-
logger?: LoggerConfig;
|
|
19
|
-
configFile?: string;
|
|
20
|
-
/**
|
|
21
|
-
* User identifier (authenticated user ID)
|
|
22
|
-
* If provided, will be used in all analytics events
|
|
23
|
-
*/
|
|
24
|
-
userId?: string;
|
|
25
|
-
/**
|
|
26
|
-
* Anonymous identifier (if not provided, will be auto-generated)
|
|
27
|
-
* Required if userId is not provided
|
|
28
|
-
*/
|
|
29
|
-
anonId?: string;
|
|
30
|
-
/**
|
|
31
|
-
* Session identifier (if not provided, will be auto-generated per session)
|
|
32
|
-
*/
|
|
33
|
-
sessionId?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Automatically track search events when search() is called
|
|
36
|
-
* @default false
|
|
37
|
-
*/
|
|
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;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Search context containing identifiers for linking events to searches
|
|
60
|
-
*
|
|
61
|
-
* Returned by search() method and should be passed to tracking methods
|
|
62
|
-
* to link clicks/conversions back to the originating search.
|
|
63
|
-
*/
|
|
64
|
-
export interface SearchContext {
|
|
65
|
-
/** Correlation ID for this search journey (generated per search) */
|
|
66
|
-
correlationId: string;
|
|
67
|
-
/** Search ID from backend (if present in response) */
|
|
68
|
-
searchId?: string;
|
|
69
|
-
/** User ID if authenticated */
|
|
70
|
-
userId?: string;
|
|
71
|
-
/** Anonymous user ID */
|
|
72
|
-
anonId: string;
|
|
73
|
-
/** Session ID */
|
|
74
|
-
sessionId: string;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Extended event payload with correlation_id, search_id, and browser context
|
|
78
|
-
* (per identifier spec requirements)
|
|
79
|
-
*
|
|
80
|
-
* This extends the base DataTypesEventPayload to include:
|
|
81
|
-
* - correlation_id: Required for linking events to search journeys
|
|
82
|
-
* - search_id: Optional, but should be included when available
|
|
83
|
-
* - Browser context: Screen, viewport, timezone, UTM, etc.
|
|
84
|
-
*
|
|
85
|
-
* Both correlation_id and search_id are set at the top level (not just in metadata) per spec.
|
|
86
|
-
*/
|
|
87
|
-
export interface ExtendedEventPayload extends DataTypesEventPayload {
|
|
88
|
-
/** Correlation ID for linking events to search journeys */
|
|
89
|
-
correlation_id?: string;
|
|
90
|
-
/** Search ID at top level (also in metadata for backward compat) */
|
|
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;
|
|
146
|
-
}
|
|
147
|
-
export interface SearchOptions {
|
|
148
|
-
q: string;
|
|
149
|
-
per_page?: number;
|
|
150
|
-
page?: number;
|
|
151
|
-
/**
|
|
152
|
-
* Filter string in format: "field:value" or "field1:value1 && field2:value2" for multiple filters.
|
|
153
|
-
* Examples: "Type:variation", "1:western", "Type:variation && Size:Large"
|
|
154
|
-
* Multiple filters use && separator: "field1:value1 && field2:value2"
|
|
155
|
-
*/
|
|
156
|
-
filter?: string;
|
|
157
|
-
filter_by?: string;
|
|
158
|
-
facet_by?: string;
|
|
159
|
-
sort?: string;
|
|
160
|
-
sort_by?: string;
|
|
161
|
-
analytics_tags?: string[];
|
|
162
|
-
widget_mode?: boolean;
|
|
163
|
-
search_fields?: string[];
|
|
164
|
-
field_weights?: number[];
|
|
165
|
-
return_fields?: string[];
|
|
166
|
-
omit_fields?: string[];
|
|
167
|
-
snippet_fields?: string[];
|
|
168
|
-
full_snippet_fields?: string[];
|
|
169
|
-
snippet_prefix?: string;
|
|
170
|
-
snippet_suffix?: string;
|
|
171
|
-
snippet_token_limit?: number;
|
|
172
|
-
snippet_min_len?: number;
|
|
173
|
-
include_snippets?: boolean;
|
|
174
|
-
group_field?: string;
|
|
175
|
-
group_size?: number;
|
|
176
|
-
prefix_mode?: 'always' | 'fallback' | 'false';
|
|
177
|
-
infix_mode?: 'always' | 'fallback' | 'false';
|
|
178
|
-
typo_max?: number;
|
|
179
|
-
typo_min_len_1?: number;
|
|
180
|
-
typo_min_len_2?: number;
|
|
181
|
-
typo_timeout_ms?: number;
|
|
182
|
-
search_timeout_ms?: number;
|
|
183
|
-
require_all_terms?: boolean;
|
|
184
|
-
exact_match_boost?: boolean;
|
|
185
|
-
cache_results?: boolean;
|
|
186
|
-
apply_rules?: boolean;
|
|
187
|
-
preset_name?: string;
|
|
188
|
-
facet_search_text?: string;
|
|
189
|
-
include_suggestions?: boolean;
|
|
190
|
-
suggestions_limit?: number;
|
|
191
|
-
max_facet_values?: number;
|
|
192
|
-
stopword_sets?: string[];
|
|
193
|
-
synonym_sets?: string[];
|
|
194
|
-
}
|
|
195
|
-
export interface SearchResponse {
|
|
196
|
-
results: any[];
|
|
197
|
-
totalResults: number;
|
|
198
|
-
searchId?: string;
|
|
199
|
-
/** Search context for linking subsequent events */
|
|
200
|
-
context: SearchContext;
|
|
201
|
-
[key: string]: any;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Full query suggestions API response when returnFullResponse is true.
|
|
205
|
-
* Includes suggestion hits plus dropdown recommendations (trending_searches, top_searches,
|
|
206
|
-
* related_searches, popular_brands, filtered_tabs) when requested.
|
|
207
|
-
*/
|
|
208
|
-
export interface QuerySuggestionsFullResponse {
|
|
209
|
-
/** Suggestion hits (same as getSuggestions() default return) */
|
|
210
|
-
suggestions: any[];
|
|
211
|
-
/** Full results array from API (multi-index: first = suggestions, second = extensions when include_dropdown_recommendations/filtered_tabs) */
|
|
212
|
-
results?: any[];
|
|
213
|
-
/** Extensions from the response (e.g. trending_searches, top_searches, related_searches, popular_brands, filtered_tabs) */
|
|
214
|
-
extensions?: Record<string, any>;
|
|
215
|
-
/** Raw API response data */
|
|
216
|
-
raw?: any;
|
|
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
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Seekora SDK Client
|
|
301
|
-
*
|
|
302
|
-
* Provides a clean, easy-to-use interface for the Seekora Search API
|
|
303
|
-
*/
|
|
304
|
-
export declare class SeekoraClient {
|
|
305
|
-
private config;
|
|
306
|
-
private searchApi;
|
|
307
|
-
private suggestionsApi;
|
|
308
|
-
private suggestionsConfigApi;
|
|
309
|
-
private analyticsApi;
|
|
310
|
-
private storesApi;
|
|
311
|
-
private documentsApi;
|
|
312
|
-
private schemaApi;
|
|
313
|
-
private storeId;
|
|
314
|
-
private readSecret;
|
|
315
|
-
private writeSecret?;
|
|
316
|
-
private logger;
|
|
317
|
-
private userId?;
|
|
318
|
-
private anonId;
|
|
319
|
-
private sessionId;
|
|
320
|
-
private autoTrackSearch;
|
|
321
|
-
private enableContextCollection;
|
|
322
|
-
private contextCollector;
|
|
323
|
-
private cachedBrowserContext;
|
|
324
|
-
private enableEventQueue;
|
|
325
|
-
private eventQueue;
|
|
326
|
-
constructor(config?: SeekoraClientConfig);
|
|
327
|
-
/**
|
|
328
|
-
* Search for documents
|
|
329
|
-
*
|
|
330
|
-
* Generates a new correlation_id for this search and returns SearchContext
|
|
331
|
-
* for linking subsequent events (clicks, conversions) to this search.
|
|
332
|
-
*
|
|
333
|
-
* @param query - Search query string
|
|
334
|
-
* @param options - Search options (pagination, filters, facets, etc.)
|
|
335
|
-
* @returns SearchResponse with results and SearchContext
|
|
336
|
-
*/
|
|
337
|
-
search(query: string, options?: Partial<SearchOptions>): Promise<SearchResponse>;
|
|
338
|
-
/**
|
|
339
|
-
* Get query suggestions
|
|
340
|
-
*
|
|
341
|
-
* Uses POST when filtered_tabs or include_dropdown_recommendations is set (GET does not send include_dropdown_recommendations).
|
|
342
|
-
* With returnFullResponse: true returns full shape including extensions (trending_searches, top_searches, related_searches, popular_brands, filtered_tabs).
|
|
343
|
-
*
|
|
344
|
-
* @param query - Partial query to get suggestions for
|
|
345
|
-
* @param options - Optional parameters for suggestions
|
|
346
|
-
* @returns Suggestion hits array, or QuerySuggestionsFullResponse when returnFullResponse is true
|
|
347
|
-
*/
|
|
348
|
-
getSuggestions(query: string, options?: {
|
|
349
|
-
hitsPerPage?: number;
|
|
350
|
-
page?: number;
|
|
351
|
-
analytics_tags?: string | string[];
|
|
352
|
-
tags_match_mode?: 'any' | 'all';
|
|
353
|
-
include_categories?: boolean;
|
|
354
|
-
include_facets?: boolean;
|
|
355
|
-
max_categories?: number;
|
|
356
|
-
max_facets?: number;
|
|
357
|
-
min_popularity?: number;
|
|
358
|
-
time_range?: '7d' | '30d' | '90d';
|
|
359
|
-
disable_typo_tolerance?: boolean;
|
|
360
|
-
include_dropdown_recommendations?: boolean;
|
|
361
|
-
filtered_tabs?: Array<{
|
|
362
|
-
id?: string;
|
|
363
|
-
label: string;
|
|
364
|
-
filter: string;
|
|
365
|
-
count?: number;
|
|
366
|
-
}>;
|
|
367
|
-
/** When true, returns full response with results and extensions (dropdown recommendations, filtered_tabs) */
|
|
368
|
-
returnFullResponse?: boolean;
|
|
369
|
-
}): Promise<any[] | QuerySuggestionsFullResponse>;
|
|
370
|
-
/**
|
|
371
|
-
* Get query suggestions configuration (store-specific).
|
|
372
|
-
* Uses GET /api/v1/stores/{storeId}/query-suggestions/config via SDKQuerySuggestionsConfigApi.
|
|
373
|
-
*/
|
|
374
|
-
getSuggestionsConfig(): Promise<any>;
|
|
375
|
-
/**
|
|
376
|
-
* Get store configuration
|
|
377
|
-
* Returns store search configuration and onboarding status
|
|
378
|
-
*/
|
|
379
|
-
getConfig(): Promise<DataTypesIndexConfig>;
|
|
380
|
-
/**
|
|
381
|
-
* Get store information
|
|
382
|
-
* Returns store metadata including name, status, and configuration details
|
|
383
|
-
*
|
|
384
|
-
* Note: This extracts information from the store config response.
|
|
385
|
-
* Store name may be derived from config fields if not directly available.
|
|
386
|
-
*
|
|
387
|
-
* @returns Store information object
|
|
388
|
-
*/
|
|
389
|
-
getStoreInfo(): Promise<{
|
|
390
|
-
storeId: string;
|
|
391
|
-
storeName?: string;
|
|
392
|
-
onboardingStatus?: string;
|
|
393
|
-
isActive?: boolean;
|
|
394
|
-
orgId?: number;
|
|
395
|
-
queryFields?: string[];
|
|
396
|
-
facetFields?: string[];
|
|
397
|
-
primaryField?: string;
|
|
398
|
-
config?: any;
|
|
399
|
-
}>;
|
|
400
|
-
/**
|
|
401
|
-
* Update store configuration (requires write secret)
|
|
402
|
-
*/
|
|
403
|
-
updateConfig(config: Partial<DataTypesIndexConfig>): Promise<DataTypesIndexConfig>;
|
|
404
|
-
/**
|
|
405
|
-
* Update query suggestions configuration (requires write secret).
|
|
406
|
-
* Uses PUT /api/v1/stores/{xStoreID}/query-suggestions/config via SDKQuerySuggestionsConfigApi.
|
|
407
|
-
*/
|
|
408
|
-
updateQuerySuggestionsConfig(config: any): Promise<any>;
|
|
409
|
-
/**
|
|
410
|
-
* Get configuration schema
|
|
411
|
-
*/
|
|
412
|
-
getConfigSchema(): Promise<any>;
|
|
413
|
-
/**
|
|
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
|
|
524
|
-
* Ensures user_id or anon_id is present, and sets correlation_id/search_id at top level
|
|
525
|
-
*/
|
|
526
|
-
private buildEventPayload;
|
|
527
|
-
/**
|
|
528
|
-
* Track a single analytics event
|
|
529
|
-
*
|
|
530
|
-
* @param event - Event payload (partial, will be enriched with identifiers)
|
|
531
|
-
* @param context - Optional search context for linking events to searches
|
|
532
|
-
*/
|
|
533
|
-
trackEvent(event: Partial<DataTypesEventPayload>, context?: SearchContext | Partial<SearchContext>): Promise<void>;
|
|
534
|
-
/**
|
|
535
|
-
* Track multiple analytics events (batch)
|
|
536
|
-
*
|
|
537
|
-
* Note: Events should already have identifiers set. Consider using individual trackEvent()
|
|
538
|
-
* calls or buildEventPayload() to ensure identifiers are properly set.
|
|
539
|
-
*
|
|
540
|
-
* @param events - Array of event payloads (should have identifiers already set)
|
|
541
|
-
*/
|
|
542
|
-
trackEvents(events: (Partial<DataTypesEventPayload> & {
|
|
543
|
-
event_name?: string;
|
|
544
|
-
})[], context?: SearchContext): Promise<void>;
|
|
545
|
-
/**
|
|
546
|
-
* Track a search event
|
|
547
|
-
*
|
|
548
|
-
* @param params - Search tracking parameters
|
|
549
|
-
*/
|
|
550
|
-
trackSearch(params: {
|
|
551
|
-
query: string;
|
|
552
|
-
resultsCount: number;
|
|
553
|
-
context?: SearchContext;
|
|
554
|
-
analyticsTags?: string[];
|
|
555
|
-
metadata?: Record<string, any>;
|
|
556
|
-
}): Promise<void>;
|
|
557
|
-
/**
|
|
558
|
-
* Track an impression event
|
|
559
|
-
*
|
|
560
|
-
* @param params - Impression tracking parameters
|
|
561
|
-
*/
|
|
562
|
-
trackImpression(params: {
|
|
563
|
-
itemId: string;
|
|
564
|
-
position: number;
|
|
565
|
-
listType?: string;
|
|
566
|
-
searchQuery?: string;
|
|
567
|
-
context?: SearchContext;
|
|
568
|
-
metadata?: Record<string, any>;
|
|
569
|
-
}): Promise<void>;
|
|
570
|
-
/**
|
|
571
|
-
* Track a click event
|
|
572
|
-
*
|
|
573
|
-
* @param itemId - Item ID that was clicked
|
|
574
|
-
* @param position - Position in search results (1-based)
|
|
575
|
-
* @param context - Search context (from search() response) for linking to search
|
|
576
|
-
*/
|
|
577
|
-
trackClick(itemId: string, position: number, context?: SearchContext): Promise<void>;
|
|
578
|
-
/**
|
|
579
|
-
* Track a click event (backward compatibility)
|
|
580
|
-
*
|
|
581
|
-
* @param itemId - Item ID that was clicked
|
|
582
|
-
* @param position - Position in search results (1-based)
|
|
583
|
-
* @param searchId - Search ID (deprecated, use context instead)
|
|
584
|
-
*/
|
|
585
|
-
trackClick(itemId: string, position: number, searchId?: string): Promise<void>;
|
|
586
|
-
/**
|
|
587
|
-
* Track a view event
|
|
588
|
-
*
|
|
589
|
-
* @param itemId - Item ID that was viewed
|
|
590
|
-
* @param context - Search context (from search() response) for linking to search
|
|
591
|
-
*/
|
|
592
|
-
trackView(itemId: string, context?: SearchContext): Promise<void>;
|
|
593
|
-
/**
|
|
594
|
-
* Track a view event (backward compatibility)
|
|
595
|
-
*
|
|
596
|
-
* @param itemId - Item ID that was viewed
|
|
597
|
-
* @param searchId - Search ID (deprecated, use context instead)
|
|
598
|
-
*/
|
|
599
|
-
trackView(itemId: string, searchId?: string): Promise<void>;
|
|
600
|
-
/**
|
|
601
|
-
* Track a conversion event
|
|
602
|
-
*
|
|
603
|
-
* @param itemId - Item ID that was converted
|
|
604
|
-
* @param value - Conversion value (optional)
|
|
605
|
-
* @param currency - Currency code (optional)
|
|
606
|
-
* @param context - Search context (from search() response) for linking to search
|
|
607
|
-
*/
|
|
608
|
-
trackConversion(itemId: string, value?: number, currency?: string, context?: SearchContext): Promise<void>;
|
|
609
|
-
/**
|
|
610
|
-
* Track a conversion event (backward compatibility)
|
|
611
|
-
*
|
|
612
|
-
* @param itemId - Item ID that was converted
|
|
613
|
-
* @param value - Conversion value (optional)
|
|
614
|
-
* @param currency - Currency code (optional)
|
|
615
|
-
* @param searchId - Search ID (deprecated, use context instead)
|
|
616
|
-
*/
|
|
617
|
-
trackConversion(itemId: string, value?: number, currency?: string, searchId?: string): Promise<void>;
|
|
618
|
-
/**
|
|
619
|
-
* Track a custom event
|
|
620
|
-
*
|
|
621
|
-
* @param eventName - Custom event name
|
|
622
|
-
* @param payload - Additional event data
|
|
623
|
-
* @param context - Optional search context for linking events to searches
|
|
624
|
-
*/
|
|
625
|
-
trackCustom(eventName: string, payload?: Partial<DataTypesEventPayload>, context?: SearchContext): Promise<void>;
|
|
626
|
-
/**
|
|
627
|
-
* Validate an event payload before sending
|
|
628
|
-
* Useful for debugging and ensuring events are properly formatted
|
|
629
|
-
*
|
|
630
|
-
* @param event - Event payload to validate
|
|
631
|
-
* @returns Validation result with success status and any error messages
|
|
632
|
-
*/
|
|
633
|
-
validateEvent(event: Partial<DataTypesEventPayload>): Promise<{
|
|
634
|
-
valid: boolean;
|
|
635
|
-
message?: string;
|
|
636
|
-
errors?: any;
|
|
637
|
-
}>;
|
|
638
|
-
/**
|
|
639
|
-
* Get event schema
|
|
640
|
-
* Returns the JSON schema for event payloads, useful for understanding required/optional fields
|
|
641
|
-
*
|
|
642
|
-
* @returns Event schema with field definitions, types, and validation rules
|
|
643
|
-
*/
|
|
644
|
-
getEventSchema(): Promise<any>;
|
|
645
|
-
/**
|
|
646
|
-
* Set user ID (call this when user logs in)
|
|
647
|
-
*
|
|
648
|
-
* @param userId - Authenticated user ID
|
|
649
|
-
*/
|
|
650
|
-
setUserId(userId: string): void;
|
|
651
|
-
/**
|
|
652
|
-
* Clear user ID (call this when user logs out)
|
|
653
|
-
*/
|
|
654
|
-
clearUserId(): void;
|
|
655
|
-
/**
|
|
656
|
-
* Get current identifiers
|
|
657
|
-
* Useful for debugging or custom event tracking
|
|
658
|
-
*/
|
|
659
|
-
getIdentifiers(): {
|
|
660
|
-
userId?: string;
|
|
661
|
-
anonId: string;
|
|
662
|
-
sessionId: string;
|
|
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>;
|
|
700
|
-
/**
|
|
701
|
-
* Handle errors consistently
|
|
702
|
-
*/
|
|
703
|
-
private handleError;
|
|
704
|
-
/**
|
|
705
|
-
* Get the logger instance
|
|
706
|
-
*/
|
|
707
|
-
getLogger(): Logger;
|
|
708
|
-
}
|
|
709
|
-
export default SeekoraClient;
|