@searchcraft/vue-sdk 0.10.1 → 0.10.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/dist/index.d.ts CHANGED
@@ -42,7 +42,7 @@ export type SearchResultFieldName = {
42
42
  numberFormatLocale?: string;
43
43
  /**
44
44
  * If it's a number, the number format to apply.
45
- * reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat
45
+ * Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat
46
46
  */
47
47
  numberFormatOptions?: Intl.NumberFormatOptions;
48
48
  /**
@@ -50,9 +50,14 @@ export type SearchResultFieldName = {
50
50
  */
51
51
  numberScale?: number;
52
52
  /**
53
- * TODO: Implement DateFormatOptions, for date formatting
53
+ * The locale to use when formatting dataType: `date`.
54
54
  */
55
- dateFormatOptions?: unknown;
55
+ dateFormatLocale?: string;
56
+ /**
57
+ * If it's a date, the date format to apply.
58
+ * Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
59
+ */
60
+ dateFormatOptions?: Intl.DateTimeFormatOptions;
56
61
  };
57
62
  /**
58
63
  * A data type representing the mapping of index fields, for the purpose of rendering them
@@ -138,7 +143,9 @@ export type CustomAdTemplate = (data: {
138
143
  }, utils: {
139
144
  html: TemplateHtml;
140
145
  }) => string;
141
- export type PopoverButtonTemplate = (data: boolean, utils: {
146
+ export type PopoverButtonTemplate = (data: {
147
+ isPopoverVisible: boolean;
148
+ }, utils: {
142
149
  html: TemplateHtml;
143
150
  }) => string;
144
151
  /**
@@ -146,11 +153,11 @@ export type PopoverButtonTemplate = (data: boolean, utils: {
146
153
  */
147
154
  export interface SearchcraftConfig {
148
155
  /**
149
- * Host IP Address and port number configured and created using Vektron
156
+ * Host IP Address and port number configured and created using Vektron.
150
157
  */
151
158
  endpointURL: string;
152
159
  /**
153
- * Name or names of search indices configured using Vektron. Given as an array of strings
160
+ * Name or names of search indices configured using Vektron. Given as an array of strings.
154
161
  */
155
162
  index: string[];
156
163
  /**
@@ -169,6 +176,10 @@ export interface SearchcraftConfig {
169
176
  * The maximum number of results to return per page.
170
177
  */
171
178
  searchResultsPerPage?: number;
179
+ /**
180
+ * The name of the field to use for `order_by` when sorting.
181
+ */
182
+ indexFieldName?: string;
172
183
  /**
173
184
  * Name of the ad source to use.
174
185
  */
@@ -301,6 +312,56 @@ export interface MeasureRequestUser {
301
312
  latitude?: number;
302
313
  longitude?: number;
303
314
  }
315
+ export interface FacetPathsForIndexField {
316
+ fieldName: string;
317
+ value: string;
318
+ }
319
+ export interface RangeValueForIndexField {
320
+ fieldName: string;
321
+ value: string;
322
+ }
323
+ export interface SearchClientRequestProperties {
324
+ /**
325
+ * The search mode, which can be either 'fuzzy' or 'exact'.
326
+ */
327
+ mode: "fuzzy" | "exact";
328
+ /**
329
+ * The starting point for the results, used for pagination.
330
+ * Optional parameter.
331
+ */
332
+ offset?: number;
333
+ /**
334
+ * The number of results returned.
335
+ * Optional parameter.
336
+ */
337
+ limit?: number;
338
+ /**
339
+ * The field to order the results by (e.g., 'date_published', 'title', etc.).
340
+ * Optional parameter.
341
+ */
342
+ order_by?: string;
343
+ /**
344
+ * The search term provided by the user.
345
+ */
346
+ searchTerm: string;
347
+ /**
348
+ * The sort order, which can be either 'asc' or 'desc'.
349
+ * Optional parameter.
350
+ */
351
+ sort?: "asc" | "desc";
352
+ /**
353
+ * The facet path value(s) specified by the `facets` filter items that the `searchcraft-filter-panel` renders.
354
+ * There may be multiple rendered within a single filter panel.
355
+ * Optional parameter.
356
+ */
357
+ facetPathsForIndexFields?: Record<string, FacetPathsForIndexField>;
358
+ /**
359
+ * The date range slider value(s) specified by the `dateRange` filter items that the `searchcraft-filter-panel` renders.
360
+ * There may be multiple rendered within a single filter panel.
361
+ * Optional parameter.
362
+ */
363
+ rangeValueForIndexFields?: Record<string, RangeValueForIndexField>;
364
+ }
304
365
  /**
305
366
  * The structure of a response returned from a Searchcraft operation.
306
367
  */
@@ -327,13 +388,13 @@ export type SearchcraftResponseError = {
327
388
  export interface SearchcraftResponseData {
328
389
  count?: number;
329
390
  facets?: FacetPrime;
330
- hits?: SearchIndexEntry[];
391
+ hits?: SearchIndexHit[];
331
392
  time_taken?: number;
332
393
  }
333
394
  /**
334
395
  * Represents an entry in the search index returned as part of a search result.
335
396
  */
336
- export interface SearchIndexEntry {
397
+ export interface SearchIndexHit {
337
398
  doc?: SearchDocument;
338
399
  document_id?: string;
339
400
  score?: number;
@@ -349,54 +410,12 @@ export interface SearchClientResponseItem {
349
410
  id: string;
350
411
  document: SearchDocument;
351
412
  }
352
- export type FacetPathsForIndexField = {
353
- fieldName: string;
354
- value: string;
355
- };
356
- export type RangeValueForIndexField = {
357
- fieldName: string;
358
- value: string;
359
- };
360
- /**
361
- * Parameters required to make a successful Search request.
362
- */
363
- export type SearchParams = {
364
- /**
365
- * The search mode, which can be either 'fuzzy' or 'exact'.
366
- */
367
- mode: "fuzzy" | "exact";
368
- /**
369
- * The starting point for the results, used for pagination.
370
- * Optional parameter.
371
- */
372
- offset?: number;
373
- /**
374
- * The number of results returned.
375
- * Optional parameter.
376
- */
377
- limit?: number;
378
- /**
379
- * The field to order the results by (e.g., 'date_published', 'title', etc.).
380
- * Optional parameter.
381
- */
382
- order_by?: string;
383
- /**
384
- * The search term provided by the user.
385
- */
386
- searchTerm: string;
387
- /**
388
- * The sort order, which can be either 'asc' or 'desc'.
389
- * Optional parameter.
390
- */
391
- sort?: "asc" | "desc";
392
- facetPathsForIndexFields?: Record<string, FacetPathsForIndexField>;
393
- rangeValueForIndexFields?: Record<string, RangeValueForIndexField>;
394
- };
395
413
  export interface SubscriptionEventMap {
396
414
  ad_container_rendered: AdContainerRenderedSubscriptionEvent;
397
415
  ad_container_viewed: AdContainerViewedSubscriptionEvent;
398
416
  query_fetched: QueryFetchedEvent;
399
417
  query_submitted: QuerySubmittedEvent;
418
+ initialized: InitializedEvent;
400
419
  input_cleared: InputClearedEvent;
401
420
  no_results_returned: NoResultsReturnedEvent;
402
421
  }
@@ -434,6 +453,9 @@ export interface InputClearedEvent extends SubscriptionEvent {
434
453
  export interface NoResultsReturnedEvent extends SubscriptionEvent {
435
454
  name: "no_results_returned";
436
455
  }
456
+ export interface InitializedEvent extends SubscriptionEvent {
457
+ name: "initialized";
458
+ }
437
459
  export type SubscriptionEventName = keyof SubscriptionEventMap;
438
460
  export type SubscriptionEventCallback<T extends SubscriptionEventName> = (event: SubscriptionEventMap[T]) => void;
439
461
  export type UnsubscribeFunction = () => void;
@@ -443,9 +465,9 @@ export interface SubscriptionEvent {
443
465
  declare class AdClient {
444
466
  config: SearchcraftConfig;
445
467
  constructor(config: SearchcraftConfig);
446
- getAdsForSearchParams(_params: SearchParams): Promise<AdClientResponseItem[]>;
447
- onQuerySubmitted(_params: SearchParams): Promise<void>;
448
- onQueryFetched(_params: SearchParams, _response: SearchcraftResponse): Promise<void>;
468
+ getAds(_properties: SearchClientRequestProperties): Promise<AdClientResponseItem[]>;
469
+ onQuerySubmitted(_properties: SearchClientRequestProperties): Promise<void>;
470
+ onQueryFetched(_properties: SearchClientRequestProperties, _response: SearchcraftResponse): Promise<void>;
449
471
  onInputCleared(): Promise<void>;
450
472
  onAdContainerRendered(_data: {
451
473
  adClientResponseItem?: AdClientResponseItem;
@@ -496,10 +518,19 @@ declare class SearchClient {
496
518
  */
497
519
  private get baseSearchUrl();
498
520
  /**
499
- * Performs a search operation.
500
- * @param {SearchParams} searchParams - The parameters for the search.
521
+ * Make the request to get the search results.
522
+ * @param {properties} properties - The properties for the search.
523
+ * @returns
524
+ */
525
+ getSearchResponseItems: (properties: SearchClientRequestProperties | string) => Promise<SearchcraftResponse>;
526
+ private handleGetSearchResponseItemsWithString;
527
+ private handleGetSearchResponseItemsWithObject;
528
+ /**
529
+ * Builds a query object for the SearchClient request.
530
+ * @param {properties} properties - The properties for the search.
531
+ * @returns {SearchClientQuery} - A properly formatted SearchClient query object.
501
532
  */
502
- getSearchResponse: (searchParams: SearchParams) => Promise<SearchcraftResponse>;
533
+ private formatParamsForRequest;
503
534
  }
504
535
  /**
505
536
  * Javascript Class providing the functionality to interact with the Searchcraft BE
@@ -543,25 +574,28 @@ export declare class SearchcraftCore {
543
574
  * Perform various actions when the input is cleared
544
575
  */
545
576
  handleInputCleared(): void;
546
- /**
547
- * Gets items from the SearchClient and the AdClient.
548
- */
549
- getItems: (searchParams: SearchParams, itemsCallback: (response: SearchcraftResponse, items: SearchClientResponseItem[]) => void, adCallback: (adClientResponseItems: AdClientResponseItem[]) => void) => void;
577
+ getResponseItems: (properties: SearchClientRequestProperties | string, searchCallback: (response: SearchcraftResponse, items: SearchClientResponseItem[]) => void, adCallback: (items: AdClientResponseItem[]) => void) => void;
550
578
  }
551
579
  /**
552
580
  * Callable functions made available by the SearchcraftStore.
553
581
  */
554
582
  export interface SearchcraftStateFunctions {
555
- addFacetPathsForIndexField: (data: FacetPathsForIndexField) => void;
556
- addRangeValueForIndexField: (data: RangeValueForIndexField) => void;
557
- getSearchcraftInstance: () => SearchcraftCore | undefined;
558
- initialize: (searchcraft: unknown, debug?: boolean) => void;
583
+ addFacetPathsForIndexField: (field: FacetPathsForIndexField) => void;
584
+ addRangeValueForIndexField: (field: RangeValueForIndexField) => void;
585
+ getSearchcraftCore: () => SearchcraftCore | undefined;
586
+ init: (searchcraft: SearchcraftCore | undefined, debug?: boolean) => void;
559
587
  removeFacetPathsForIndexField: (fieldName: string) => void;
560
588
  removeRangeValueForIndexField: (fieldName: string) => void;
561
589
  resetFacetPaths: () => void;
562
590
  search: () => Promise<void>;
591
+ set: (state: Partial<SearchcraftState> | ((state: SearchcraftState) => Partial<SearchcraftState>)) => SearchcraftState;
592
+ setAdClientResponseItems: (items: AdClientResponseItem[]) => void;
593
+ setSearchClientResponseItemsFromResponse: (response: SearchcraftResponse, items: SearchClientResponseItem[]) => void;
594
+ setInitialSearchClientResponseItemsFromResponse: (response: SearchcraftResponse, items: SearchClientResponseItem[]) => void;
595
+ setInitialQuery: (query: string) => void;
563
596
  setPopoverVisibility: (isVisible: boolean) => void;
564
- setSearchClientResponseItems: (results: SearchClientResponseItem[]) => void;
597
+ setSearchResultsCount: (count: number) => void;
598
+ setSearchClientResponseItems: (items: SearchClientResponseItem[]) => void;
565
599
  setSearchResultsPage: (page: number) => void;
566
600
  setSearchResultsPerPage: (perPage: number) => void;
567
601
  setSearchTerm: (searchTerm: string) => void;
@@ -579,6 +613,8 @@ export interface SearchcraftStateValues {
579
613
  hotkeyModifier: "ctrl" | "meta" | "alt" | "option";
580
614
  logger: Logger | undefined;
581
615
  facetPathsForIndexFields: Record<string, FacetPathsForIndexField>;
616
+ initialQuery: string;
617
+ initialSearchClientResponseItems: SearchClientResponseItem[];
582
618
  isPopoverVisible: boolean;
583
619
  isSearchInProgress: boolean;
584
620
  rangeValueForIndexFields: Record<string, RangeValueForIndexField>;
@@ -591,12 +627,11 @@ export interface SearchcraftStateValues {
591
627
  searchResultsPerPage: number;
592
628
  searchTerm: string;
593
629
  sortType: "asc" | "desc";
630
+ afterInit: (state: SearchcraftState) => void;
594
631
  }
595
632
  export interface SearchcraftState extends SearchcraftStateFunctions, SearchcraftStateValues {
596
633
  }
597
634
  export declare const searchcraftStore: import("zustand").StoreApi<SearchcraftState>;
598
- export declare function parseCustomStyles(styles: string | Record<string, string>): Record<string, string>;
599
- export declare function serializeStyles(styles: Record<string, Record<string, string>>): string;
600
635
  export type SearchcraftSelectOption = {
601
636
  label: string;
602
637
  value: string | number;
@@ -800,13 +835,13 @@ export namespace Components {
800
835
  * ```js
801
836
  * // index.js
802
837
  * const popoverButton = document.querySelector('searchcraft-popover-button');
803
- * popoverButton.template = (isPopoverVisible, { html }) => html`
838
+ * popoverButton.template = ({ isPopoverVisible }, { html }) => html`
804
839
  * <span>Click me</span>
805
840
  * `;
806
841
  * ```
807
842
  * @react-example ```jsx
808
843
  * <SearchcraftPopoverButton
809
- * template={(isPopoverVisible, { html }) => html`
844
+ * template={({ isPopoverVisible }, { html }) => html`
810
845
  * <span>Click me</span>
811
846
  * `}
812
847
  * >
@@ -815,7 +850,7 @@ export namespace Components {
815
850
  * ```
816
851
  * @vue-example ```jsx
817
852
  * <SearchcraftPopoverButton
818
- * :template={(isPopoverVisible, { html }) => html`
853
+ * :template={({ isPopoverVisible }, { html }) => html`
819
854
  * <span>Click me</span>
820
855
  * `}
821
856
  * >
@@ -1011,6 +1046,10 @@ export namespace Components {
1011
1046
  * ```
1012
1047
  */
1013
1048
  interface SearchcraftSearchResults {
1049
+ /**
1050
+ * A query that will appears when the component initializes or the search term is ''..
1051
+ */
1052
+ "initialQuery"?: string;
1014
1053
  /**
1015
1054
  * A callback function responsible for rendering a result. Passed to `searchcraft-search-result`.
1016
1055
  */
@@ -1363,13 +1402,13 @@ declare global {
1363
1402
  * ```js
1364
1403
  * // index.js
1365
1404
  * const popoverButton = document.querySelector('searchcraft-popover-button');
1366
- * popoverButton.template = (isPopoverVisible, { html }) => html`
1405
+ * popoverButton.template = ({ isPopoverVisible }, { html }) => html`
1367
1406
  * <span>Click me</span>
1368
1407
  * `;
1369
1408
  * ```
1370
1409
  * @react-example ```jsx
1371
1410
  * <SearchcraftPopoverButton
1372
- * template={(isPopoverVisible, { html }) => html`
1411
+ * template={({ isPopoverVisible }, { html }) => html`
1373
1412
  * <span>Click me</span>
1374
1413
  * `}
1375
1414
  * >
@@ -1378,7 +1417,7 @@ declare global {
1378
1417
  * ```
1379
1418
  * @vue-example ```jsx
1380
1419
  * <SearchcraftPopoverButton
1381
- * :template={(isPopoverVisible, { html }) => html`
1420
+ * :template={({ isPopoverVisible }, { html }) => html`
1382
1421
  * <span>Click me</span>
1383
1422
  * `}
1384
1423
  * >
@@ -1910,13 +1949,13 @@ declare namespace LocalJSX {
1910
1949
  * ```js
1911
1950
  * // index.js
1912
1951
  * const popoverButton = document.querySelector('searchcraft-popover-button');
1913
- * popoverButton.template = (isPopoverVisible, { html }) => html`
1952
+ * popoverButton.template = ({ isPopoverVisible }, { html }) => html`
1914
1953
  * <span>Click me</span>
1915
1954
  * `;
1916
1955
  * ```
1917
1956
  * @react-example ```jsx
1918
1957
  * <SearchcraftPopoverButton
1919
- * template={(isPopoverVisible, { html }) => html`
1958
+ * template={({ isPopoverVisible }, { html }) => html`
1920
1959
  * <span>Click me</span>
1921
1960
  * `}
1922
1961
  * >
@@ -1925,7 +1964,7 @@ declare namespace LocalJSX {
1925
1964
  * ```
1926
1965
  * @vue-example ```jsx
1927
1966
  * <SearchcraftPopoverButton
1928
- * :template={(isPopoverVisible, { html }) => html`
1967
+ * :template={({ isPopoverVisible }, { html }) => html`
1929
1968
  * <span>Click me</span>
1930
1969
  * `}
1931
1970
  * >
@@ -2121,6 +2160,10 @@ declare namespace LocalJSX {
2121
2160
  * ```
2122
2161
  */
2123
2162
  interface SearchcraftSearchResults {
2163
+ /**
2164
+ * A query that will appears when the component initializes or the search term is ''..
2165
+ */
2166
+ "initialQuery"?: string;
2124
2167
  /**
2125
2168
  * A callback function responsible for rendering a result. Passed to `searchcraft-search-result`.
2126
2169
  */
@@ -2409,13 +2452,13 @@ declare module "@stencil/core" {
2409
2452
  * ```js
2410
2453
  * // index.js
2411
2454
  * const popoverButton = document.querySelector('searchcraft-popover-button');
2412
- * popoverButton.template = (isPopoverVisible, { html }) => html`
2455
+ * popoverButton.template = ({ isPopoverVisible }, { html }) => html`
2413
2456
  * <span>Click me</span>
2414
2457
  * `;
2415
2458
  * ```
2416
2459
  * @react-example ```jsx
2417
2460
  * <SearchcraftPopoverButton
2418
- * template={(isPopoverVisible, { html }) => html`
2461
+ * template={({ isPopoverVisible }, { html }) => html`
2419
2462
  * <span>Click me</span>
2420
2463
  * `}
2421
2464
  * >
@@ -2424,7 +2467,7 @@ declare module "@stencil/core" {
2424
2467
  * ```
2425
2468
  * @vue-example ```jsx
2426
2469
  * <SearchcraftPopoverButton
2427
- * :template={(isPopoverVisible, { html }) => html`
2470
+ * :template={({ isPopoverVisible }, { html }) => html`
2428
2471
  * <span>Click me</span>
2429
2472
  * `}
2430
2473
  * >