@searchcraft/javascript-sdk 0.14.0 → 0.15.1

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.
Files changed (67) hide show
  1. package/dist/components/defineCustomElements.js +25 -23
  2. package/dist/components/html.js +1 -1
  3. package/dist/components/index.d.ts +131 -5
  4. package/dist/components/index.js +245 -62
  5. package/dist/components/index.js.map +1 -1
  6. package/dist/components/{searchcraft-summary-box2.js → marked.esm.js} +3 -101
  7. package/dist/components/marked.esm.js.map +1 -0
  8. package/dist/components/searchcraft-ad.js +1 -1
  9. package/dist/components/searchcraft-ad2.js +4 -4
  10. package/dist/components/searchcraft-button.js +1 -1
  11. package/dist/components/searchcraft-button2.js +2 -2
  12. package/dist/components/searchcraft-error-message.js +1 -1
  13. package/dist/components/searchcraft-error-message2.js +1 -1
  14. package/dist/components/searchcraft-facet-list.js +1 -1
  15. package/dist/components/searchcraft-facet-list2.js +2 -2
  16. package/dist/components/searchcraft-filter-panel.js +5 -5
  17. package/dist/components/searchcraft-input-form.js +1 -1
  18. package/dist/components/searchcraft-input-form2.js +6 -6
  19. package/dist/components/searchcraft-input-label.js +1 -1
  20. package/dist/components/searchcraft-input-label2.js +2 -2
  21. package/dist/components/searchcraft-loading.js +1 -1
  22. package/dist/components/searchcraft-loading2.js +1 -1
  23. package/dist/components/searchcraft-pagination.js +4 -4
  24. package/dist/components/searchcraft-popover-button.js +6 -4
  25. package/dist/components/searchcraft-popover-button.js.map +1 -1
  26. package/dist/components/searchcraft-popover-footer.js +1 -1
  27. package/dist/components/searchcraft-popover-footer2.js +5 -7
  28. package/dist/components/searchcraft-popover-footer2.js.map +1 -1
  29. package/dist/components/searchcraft-popover-form.js +18 -18
  30. package/dist/components/searchcraft-popover-form.js.map +1 -1
  31. package/dist/components/searchcraft-popover-list-item.js +1 -1
  32. package/dist/components/searchcraft-popover-list-item2.js +4 -4
  33. package/dist/components/searchcraft-popover-list-view.js +1 -1
  34. package/dist/components/searchcraft-popover-list-view2.js +4 -4
  35. package/dist/components/searchcraft-results-info.js +4 -4
  36. package/dist/components/searchcraft-results-summary.d.ts +11 -0
  37. package/dist/components/searchcraft-results-summary.js +9 -0
  38. package/dist/components/searchcraft-results-summary.js.map +1 -0
  39. package/dist/components/searchcraft-results-summary2.js +98 -0
  40. package/dist/components/searchcraft-results-summary2.js.map +1 -0
  41. package/dist/components/searchcraft-search-result.js +1 -1
  42. package/dist/components/searchcraft-search-result2.js +3 -3
  43. package/dist/components/searchcraft-search-results-per-page.js +3 -3
  44. package/dist/components/searchcraft-search-results.js +5 -5
  45. package/dist/components/searchcraft-select.js +1 -1
  46. package/dist/components/searchcraft-select2.js +1 -1
  47. package/dist/components/searchcraft-slider.js +1 -1
  48. package/dist/components/searchcraft-slider2.js +5 -5
  49. package/dist/components/searchcraft-summary-box.js +89 -1
  50. package/dist/components/searchcraft-summary-box.js.map +1 -1
  51. package/dist/components/searchcraft-theme.js +3 -3
  52. package/dist/components/searchcraft-theme.js.map +1 -1
  53. package/dist/components/searchcraft-toggle-button.js +1 -1
  54. package/dist/components/searchcraft-toggle-button2.js +5 -5
  55. package/dist/hydrate/index.js +2076 -1973
  56. package/dist/hydrate/index.mjs +2076 -1973
  57. package/dist/themes/hologram.css +1 -1
  58. package/dist/themes/hologram.css.map +1 -1
  59. package/dist/types/clients/SummaryClient.d.ts +10 -1
  60. package/dist/types/components/searchcraft-popover-button/searchcraft-popover-button.d.ts +1 -1
  61. package/dist/types/components/searchcraft-results-summary/searchcraft-results-summary.d.ts +65 -0
  62. package/dist/types/components/searchcraft-summary-box/searchcraft-summary-box.d.ts +5 -5
  63. package/dist/types/components.d.ts +119 -2
  64. package/dist/types/store/SearchcraftStore.types.d.ts +1 -0
  65. package/dist/types/types/core-types/SearchcraftConfig.types.d.ts +2 -2
  66. package/package.json +2 -2
  67. package/dist/components/searchcraft-summary-box2.js.map +0 -1
@@ -1,30 +1,31 @@
1
- export { g as getAssetPath, r as render, s as setAssetPath, a as setNonce, b as setPlatformOptions } from './index2.js?scv=0.14.0';
2
- import { n as nanoid } from './searchcraft-ad2.js?scv=0.14.0';
3
- import { D as DEFAULT_CORE_INSTANCE_ID, r as registry } from './CoreInstanceRegistry.js?scv=0.14.0';
4
- import { v as version, n as name } from './searchcraft-popover-footer2.js?scv=0.14.0';
5
- export { SearchcraftAd, defineCustomElement as defineCustomElementSearchcraftAd } from './searchcraft-ad.js?scv=0.14.0';
6
- export { SearchcraftButton, defineCustomElement as defineCustomElementSearchcraftButton } from './searchcraft-button.js?scv=0.14.0';
7
- export { SearchcraftErrorMessage, defineCustomElement as defineCustomElementSearchcraftErrorMessage } from './searchcraft-error-message.js?scv=0.14.0';
8
- export { SearchcraftFacetList, defineCustomElement as defineCustomElementSearchcraftFacetList } from './searchcraft-facet-list.js?scv=0.14.0';
9
- export { SearchcraftFilterPanel, defineCustomElement as defineCustomElementSearchcraftFilterPanel } from './searchcraft-filter-panel.js?scv=0.14.0';
10
- export { SearchcraftInputForm, defineCustomElement as defineCustomElementSearchcraftInputForm } from './searchcraft-input-form.js?scv=0.14.0';
11
- export { SearchcraftInputLabel, defineCustomElement as defineCustomElementSearchcraftInputLabel } from './searchcraft-input-label.js?scv=0.14.0';
12
- export { SearchcraftLoading, defineCustomElement as defineCustomElementSearchcraftLoading } from './searchcraft-loading.js?scv=0.14.0';
13
- export { SearchcraftPagination, defineCustomElement as defineCustomElementSearchcraftPagination } from './searchcraft-pagination.js?scv=0.14.0';
14
- export { SearchcraftPopoverButton, defineCustomElement as defineCustomElementSearchcraftPopoverButton } from './searchcraft-popover-button.js?scv=0.14.0';
15
- export { SearchcraftPopoverFooter, defineCustomElement as defineCustomElementSearchcraftPopoverFooter } from './searchcraft-popover-footer.js?scv=0.14.0';
16
- export { SearchcraftPopoverForm, defineCustomElement as defineCustomElementSearchcraftPopoverForm } from './searchcraft-popover-form.js?scv=0.14.0';
17
- export { SearchcraftPopoverListItem, defineCustomElement as defineCustomElementSearchcraftPopoverListItem } from './searchcraft-popover-list-item.js?scv=0.14.0';
18
- export { SearchcraftPopoverListView, defineCustomElement as defineCustomElementSearchcraftPopoverListView } from './searchcraft-popover-list-view.js?scv=0.14.0';
19
- export { SearchcraftResultsInfo, defineCustomElement as defineCustomElementSearchcraftResultsInfo } from './searchcraft-results-info.js?scv=0.14.0';
20
- export { SearchcraftSearchResult, defineCustomElement as defineCustomElementSearchcraftSearchResult } from './searchcraft-search-result.js?scv=0.14.0';
21
- export { SearchcraftSearchResults, defineCustomElement as defineCustomElementSearchcraftSearchResults } from './searchcraft-search-results.js?scv=0.14.0';
22
- export { SearchcraftSearchResultsPerPage, defineCustomElement as defineCustomElementSearchcraftSearchResultsPerPage } from './searchcraft-search-results-per-page.js?scv=0.14.0';
23
- export { SearchcraftSelect, defineCustomElement as defineCustomElementSearchcraftSelect } from './searchcraft-select.js?scv=0.14.0';
24
- export { SearchcraftSlider, defineCustomElement as defineCustomElementSearchcraftSlider } from './searchcraft-slider.js?scv=0.14.0';
25
- export { SearchcraftSummaryBox, defineCustomElement as defineCustomElementSearchcraftSummaryBox } from './searchcraft-summary-box.js?scv=0.14.0';
26
- export { SearchcraftTheme, defineCustomElement as defineCustomElementSearchcraftTheme } from './searchcraft-theme.js?scv=0.14.0';
27
- export { SearchcraftToggleButton, defineCustomElement as defineCustomElementSearchcraftToggleButton } from './searchcraft-toggle-button.js?scv=0.14.0';
1
+ export { g as getAssetPath, r as render, s as setAssetPath, a as setNonce, b as setPlatformOptions } from './index2.js?scv=0.15.1';
2
+ import { n as nanoid } from './searchcraft-ad2.js?scv=0.15.1';
3
+ import { D as DEFAULT_CORE_INSTANCE_ID, r as registry } from './CoreInstanceRegistry.js?scv=0.15.1';
4
+ import { v as version, n as name } from './searchcraft-popover-footer2.js?scv=0.15.1';
5
+ export { SearchcraftAd, defineCustomElement as defineCustomElementSearchcraftAd } from './searchcraft-ad.js?scv=0.15.1';
6
+ export { SearchcraftButton, defineCustomElement as defineCustomElementSearchcraftButton } from './searchcraft-button.js?scv=0.15.1';
7
+ export { SearchcraftErrorMessage, defineCustomElement as defineCustomElementSearchcraftErrorMessage } from './searchcraft-error-message.js?scv=0.15.1';
8
+ export { SearchcraftFacetList, defineCustomElement as defineCustomElementSearchcraftFacetList } from './searchcraft-facet-list.js?scv=0.15.1';
9
+ export { SearchcraftFilterPanel, defineCustomElement as defineCustomElementSearchcraftFilterPanel } from './searchcraft-filter-panel.js?scv=0.15.1';
10
+ export { SearchcraftInputForm, defineCustomElement as defineCustomElementSearchcraftInputForm } from './searchcraft-input-form.js?scv=0.15.1';
11
+ export { SearchcraftInputLabel, defineCustomElement as defineCustomElementSearchcraftInputLabel } from './searchcraft-input-label.js?scv=0.15.1';
12
+ export { SearchcraftLoading, defineCustomElement as defineCustomElementSearchcraftLoading } from './searchcraft-loading.js?scv=0.15.1';
13
+ export { SearchcraftPagination, defineCustomElement as defineCustomElementSearchcraftPagination } from './searchcraft-pagination.js?scv=0.15.1';
14
+ export { SearchcraftPopoverButton, defineCustomElement as defineCustomElementSearchcraftPopoverButton } from './searchcraft-popover-button.js?scv=0.15.1';
15
+ export { SearchcraftPopoverFooter, defineCustomElement as defineCustomElementSearchcraftPopoverFooter } from './searchcraft-popover-footer.js?scv=0.15.1';
16
+ export { SearchcraftPopoverForm, defineCustomElement as defineCustomElementSearchcraftPopoverForm } from './searchcraft-popover-form.js?scv=0.15.1';
17
+ export { SearchcraftPopoverListItem, defineCustomElement as defineCustomElementSearchcraftPopoverListItem } from './searchcraft-popover-list-item.js?scv=0.15.1';
18
+ export { SearchcraftPopoverListView, defineCustomElement as defineCustomElementSearchcraftPopoverListView } from './searchcraft-popover-list-view.js?scv=0.15.1';
19
+ export { SearchcraftResultsInfo, defineCustomElement as defineCustomElementSearchcraftResultsInfo } from './searchcraft-results-info.js?scv=0.15.1';
20
+ export { SearchcraftResultsSummary, defineCustomElement as defineCustomElementSearchcraftResultsSummary } from './searchcraft-results-summary.js?scv=0.15.1';
21
+ export { SearchcraftSearchResult, defineCustomElement as defineCustomElementSearchcraftSearchResult } from './searchcraft-search-result.js?scv=0.15.1';
22
+ export { SearchcraftSearchResults, defineCustomElement as defineCustomElementSearchcraftSearchResults } from './searchcraft-search-results.js?scv=0.15.1';
23
+ export { SearchcraftSearchResultsPerPage, defineCustomElement as defineCustomElementSearchcraftSearchResultsPerPage } from './searchcraft-search-results-per-page.js?scv=0.15.1';
24
+ export { SearchcraftSelect, defineCustomElement as defineCustomElementSearchcraftSelect } from './searchcraft-select.js?scv=0.15.1';
25
+ export { SearchcraftSlider, defineCustomElement as defineCustomElementSearchcraftSlider } from './searchcraft-slider.js?scv=0.15.1';
26
+ export { SearchcraftSummaryBox, defineCustomElement as defineCustomElementSearchcraftSummaryBox } from './searchcraft-summary-box.js?scv=0.15.1';
27
+ export { SearchcraftTheme, defineCustomElement as defineCustomElementSearchcraftTheme } from './searchcraft-theme.js?scv=0.15.1';
28
+ export { SearchcraftToggleButton, defineCustomElement as defineCustomElementSearchcraftToggleButton } from './searchcraft-toggle-button.js?scv=0.15.1';
28
29
 
29
30
  var LogLevel;
30
31
  (function (LogLevel) {
@@ -609,16 +610,19 @@ const createStoreImpl = (createState) => {
609
610
  const createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
610
611
 
611
612
  const DEBOUNCE_DELAY = 1000;
613
+ const SUMMARY_PERMISSION_MESSAGE = 'Your read key does not have permission to generate AI summaries.';
614
+ const SUMMARY_NOT_ENABLED_MESSAGE = 'AI summaries are not enabled for this account. Please contact Searchcraft to enable them.';
612
615
  class SummaryClient {
613
616
  set;
614
617
  get;
615
618
  abortController;
616
619
  timeout;
620
+ hasWarnedAboutDeprecatedCortexURL = false;
617
621
  constructor(get, set) {
618
622
  this.get = get;
619
623
  this.set = set;
620
624
  }
621
- streamSummaryData() {
625
+ streamSummaryData(requestProperties) {
622
626
  const begin = async () => {
623
627
  const state = this.get();
624
628
  const config = state.core?.config;
@@ -626,21 +630,34 @@ class SummaryClient {
626
630
  console.error('Could not stream summary data, no config found.');
627
631
  return;
628
632
  }
629
- if (!config.cortexURL) {
630
- console.error('Could not stream summary data, cortexURL was not specified in the config.');
631
- return;
632
- }
633
+ const deprecatedCortexURL = config.cortexURL;
634
+ this.warnIfUsingDeprecatedCortexURL(deprecatedCortexURL);
633
635
  const indexName = state.core?.config.indexName;
634
636
  if (!state.hasSummaryBox || !indexName) {
635
637
  return;
636
638
  }
639
+ let searchClientRequest;
640
+ try {
641
+ searchClientRequest = this.buildSearchClientRequest(requestProperties, config.searchResultsPerPage);
642
+ }
643
+ catch (error) {
644
+ if (error instanceof Error) {
645
+ console.error(error.message);
646
+ }
647
+ this.set({
648
+ isSummaryLoading: false,
649
+ });
650
+ return;
651
+ }
637
652
  this.abortController?.abort('A newer request has replaced this one.');
638
653
  this.abortController = new AbortController();
639
654
  this.set({
640
655
  isSummaryLoading: true,
656
+ isSummaryNotEnabled: false,
641
657
  summary: '',
658
+ summaryErrorMessage: '',
642
659
  });
643
- const endpointUrl = `${config.cortexURL.replace(/\/$/, '')}/api/search/summary`;
660
+ const endpointUrl = `${config.endpointURL}/index/${indexName}/search/summary`;
644
661
  try {
645
662
  const fetchResponse = await fetch(endpointUrl, {
646
663
  method: 'POST',
@@ -651,45 +668,49 @@ class SummaryClient {
651
668
  'X-Sc-Session-Id': state.core?.measureClient?.sessionId || '',
652
669
  'X-Sc-User-Type': state.core?.userType || 'anonymous',
653
670
  },
654
- body: JSON.stringify({
655
- searchQuery: state.searchClientRequest,
656
- summaryInstructionsPrompt: state.core?.config.summaryInstructionsPrompt,
657
- indexName: indexName,
658
- endpointUrl: state.core?.config.endpointURL,
659
- }),
671
+ body: JSON.stringify(searchClientRequest),
660
672
  signal: this.abortController.signal,
661
673
  });
662
674
  if (!fetchResponse) {
663
675
  throw new Error('Invalid fetch response');
664
676
  }
665
- if (!fetchResponse.body) {
666
- throw new Error('Invalid fetch response');
667
- }
668
677
  if (!fetchResponse.ok) {
678
+ if (fetchResponse.status === 401) {
679
+ console.warn(SUMMARY_PERMISSION_MESSAGE);
680
+ this.setSummaryUnavailable(SUMMARY_PERMISSION_MESSAGE);
681
+ return;
682
+ }
669
683
  if (fetchResponse.status === 403) {
670
- console.warn('Please contact Searchcraft to enable AI summaries with your account');
671
- this.set({
672
- isSummaryLoading: false,
673
- isSummaryNotEnabled: true,
674
- });
684
+ console.warn(SUMMARY_NOT_ENABLED_MESSAGE);
685
+ this.setSummaryUnavailable(SUMMARY_NOT_ENABLED_MESSAGE);
675
686
  return;
676
687
  }
677
688
  throw new Error(`HTTP ${fetchResponse.status}`);
678
689
  }
690
+ if (!fetchResponse.body) {
691
+ throw new Error('Invalid fetch response');
692
+ }
679
693
  const reader = fetchResponse.body.getReader();
680
694
  const decoder = new TextDecoder();
681
- let finishedReading = false;
682
- do {
695
+ let buffer = '';
696
+ while (true) {
683
697
  const { done, value } = await reader.read();
684
- finishedReading = done;
685
- const chunk = decoder.decode(value, { stream: true });
686
- this.set((state) => ({
687
- isSummaryLoading: false,
688
- summary: `${state.summary}${chunk}`,
689
- }));
690
- } while (!finishedReading);
698
+ buffer += decoder.decode(value || new Uint8Array(), {
699
+ stream: !done,
700
+ });
701
+ buffer = this.processSseBuffer(buffer);
702
+ if (done) {
703
+ break;
704
+ }
705
+ }
706
+ if (buffer.trim()) {
707
+ this.handleSseFrame(buffer);
708
+ }
691
709
  }
692
710
  catch (error) {
711
+ if (error instanceof Error && error.name === 'AbortError') {
712
+ return;
713
+ }
693
714
  if (error instanceof Error) {
694
715
  console.error(error.message);
695
716
  }
@@ -702,6 +723,157 @@ class SummaryClient {
702
723
  clearTimeout(this.timeout);
703
724
  this.timeout = setTimeout(() => begin(), delay);
704
725
  }
726
+ setSummaryUnavailable(message) {
727
+ this.set({
728
+ isSummaryLoading: false,
729
+ isSummaryNotEnabled: true,
730
+ summary: '',
731
+ summaryErrorMessage: message,
732
+ });
733
+ }
734
+ warnIfUsingDeprecatedCortexURL(cortexURL) {
735
+ if (!cortexURL || this.hasWarnedAboutDeprecatedCortexURL) {
736
+ return;
737
+ }
738
+ this.hasWarnedAboutDeprecatedCortexURL = true;
739
+ console.warn('The Searchcraft config field `cortexURL` is deprecated and ignored. Summary requests now use `endpointURL` and `indexName`.');
740
+ }
741
+ buildSearchClientRequest(requestProperties, defaultLimit) {
742
+ if (typeof requestProperties === 'string') {
743
+ let parsedRequest;
744
+ try {
745
+ parsedRequest = JSON.parse(requestProperties);
746
+ }
747
+ catch {
748
+ throw new Error('Invalid summary request payload.');
749
+ }
750
+ return {
751
+ limit: defaultLimit,
752
+ ...parsedRequest,
753
+ };
754
+ }
755
+ return {
756
+ query: this.formatParamsForRequest(requestProperties),
757
+ offset: requestProperties.offset || 0,
758
+ limit: requestProperties.limit || defaultLimit || 20,
759
+ ...(requestProperties.order_by && {
760
+ order_by: requestProperties.order_by,
761
+ }),
762
+ ...(requestProperties.sort && {
763
+ sort: requestProperties.sort,
764
+ }),
765
+ };
766
+ }
767
+ formatParamsForRequest(properties) {
768
+ const queries = [];
769
+ let occur = 'should';
770
+ if (properties.facetPathsForIndexFields) {
771
+ Object.keys(properties.facetPathsForIndexFields).forEach((fieldName) => {
772
+ const item = properties.facetPathsForIndexFields?.[fieldName];
773
+ if (item) {
774
+ occur = 'must';
775
+ queries.push({
776
+ occur: 'must',
777
+ exact: {
778
+ ctx: sanitize(item.value),
779
+ },
780
+ });
781
+ }
782
+ });
783
+ }
784
+ if (properties.rangeValueForIndexFields) {
785
+ Object.keys(properties.rangeValueForIndexFields).forEach((fieldName) => {
786
+ const item = properties.rangeValueForIndexFields?.[fieldName];
787
+ if (item) {
788
+ occur = 'must';
789
+ queries.push({
790
+ occur: 'must',
791
+ exact: {
792
+ ctx: sanitize(item.value),
793
+ },
794
+ });
795
+ }
796
+ });
797
+ }
798
+ const searchTerm = sanitize(properties.searchTerm);
799
+ const query = properties.mode === 'fuzzy'
800
+ ? { fuzzy: { ctx: searchTerm } }
801
+ : {
802
+ exact: {
803
+ ctx: `${searchTerm.startsWith('"') ? searchTerm : `"${searchTerm}"`}`,
804
+ },
805
+ };
806
+ queries.push({
807
+ occur: properties.mode === 'exact' ? 'must' : occur,
808
+ ...query,
809
+ });
810
+ return queries;
811
+ }
812
+ processSseBuffer(buffer) {
813
+ const frames = buffer.replace(/\r\n/g, '\n').split('\n\n');
814
+ const remainder = frames.pop() ?? '';
815
+ frames.forEach((frame) => this.handleSseFrame(frame));
816
+ return remainder;
817
+ }
818
+ handleSseFrame(frame) {
819
+ const parsedEvent = this.parseSseFrame(frame);
820
+ if (!parsedEvent?.event) {
821
+ return;
822
+ }
823
+ if (parsedEvent.event === 'metadata' || parsedEvent.event === 'done') {
824
+ this.set({
825
+ isSummaryLoading: false,
826
+ });
827
+ return;
828
+ }
829
+ let payload;
830
+ if (parsedEvent.data) {
831
+ try {
832
+ payload = JSON.parse(parsedEvent.data);
833
+ }
834
+ catch {
835
+ throw new Error(`Invalid summary SSE payload for "${parsedEvent.event}" event.`);
836
+ }
837
+ }
838
+ if (parsedEvent.event === 'delta') {
839
+ const content = payload && typeof payload.content === 'string' ? payload.content : '';
840
+ if (!content) {
841
+ return;
842
+ }
843
+ this.set((state) => ({
844
+ isSummaryLoading: false,
845
+ summary: `${state.summary}${content}`,
846
+ }));
847
+ return;
848
+ }
849
+ if (parsedEvent.event === 'error') {
850
+ throw new Error(payload && typeof payload.message === 'string'
851
+ ? payload.message
852
+ : 'Summary stream error');
853
+ }
854
+ }
855
+ parseSseFrame(frame) {
856
+ const eventData = {};
857
+ const dataLines = [];
858
+ frame.split('\n').forEach((line) => {
859
+ if (!line || line.startsWith(':')) {
860
+ return;
861
+ }
862
+ const separatorIndex = line.indexOf(':');
863
+ const field = separatorIndex >= 0 ? line.slice(0, separatorIndex) : line;
864
+ const value = separatorIndex >= 0 ? line.slice(separatorIndex + 1).trimStart() : '';
865
+ if (field === 'event') {
866
+ eventData.event = value;
867
+ }
868
+ if (field === 'data') {
869
+ dataLines.push(value);
870
+ }
871
+ });
872
+ if (dataLines.length > 0) {
873
+ eventData.data = dataLines.join('\n');
874
+ }
875
+ return eventData.event || eventData.data ? eventData : undefined;
876
+ }
705
877
  }
706
878
 
707
879
  const initialSearchcraftStateValues = {
@@ -735,6 +907,7 @@ const initialSearchcraftStateValues = {
735
907
  sortType: undefined,
736
908
  orderByField: undefined,
737
909
  summary: '',
910
+ summaryErrorMessage: '',
738
911
  hasSummaryBox: false,
739
912
  summaryClient: undefined,
740
913
  isSummaryLoading: false,
@@ -814,9 +987,6 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
814
987
  if (!state.core) {
815
988
  throw new Error('Searchcraft instance is not initialized.');
816
989
  }
817
- if (state.core.config.cortexURL && !options?.skipSummary) {
818
- state.summaryClient?.streamSummaryData();
819
- }
820
990
  // Check if this is an initialQuery case (string requestProperties with empty searchTerm)
821
991
  const isInitialQuery = typeof state.cachedSearchClientRequestProperties === 'string' &&
822
992
  state.searchTerm.trim() === '';
@@ -831,8 +1001,15 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
831
1001
  (hasActiveFilters ||
832
1002
  hasNonDefaultPagination ||
833
1003
  hasNonDefaultSearchMode)) {
834
- // Parse the initialQuery
835
- const initialQueryObj = JSON.parse(state.cachedSearchClientRequestProperties);
1004
+ let initialQueryObj;
1005
+ try {
1006
+ initialQueryObj = JSON.parse(state.cachedSearchClientRequestProperties);
1007
+ }
1008
+ catch {
1009
+ console.error('Invalid cached initial query payload.');
1010
+ set({ isSearchInProgress: false });
1011
+ return;
1012
+ }
836
1013
  set({ isSearchInProgress: true });
837
1014
  // Build the modified query array starting with the base query
838
1015
  const baseQuery = Array.isArray(initialQueryObj.query)
@@ -876,6 +1053,9 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
876
1053
  : 0,
877
1054
  limit: state.searchResultsPerPage,
878
1055
  };
1056
+ if (!options?.skipSummary) {
1057
+ state.summaryClient?.streamSummaryData(JSON.stringify(modifiedRequest));
1058
+ }
879
1059
  state.core.getResponseItems({
880
1060
  requestProperties: JSON.stringify(modifiedRequest),
881
1061
  shouldCacheResultsForEmptyState: false,
@@ -912,6 +1092,9 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
912
1092
  : 0,
913
1093
  limit: state.searchResultsPerPage,
914
1094
  };
1095
+ if (!options?.skipSummary) {
1096
+ state.summaryClient?.streamSummaryData(searchClientRequestProperites);
1097
+ }
915
1098
  state.core.getResponseItems({
916
1099
  requestProperties: searchClientRequestProperites,
917
1100
  shouldCacheResultsForEmptyState: false,
@@ -1262,4 +1445,4 @@ export { Searchcraft, SearchcraftCore };
1262
1445
  //# sourceMappingURL=index.js.map
1263
1446
 
1264
1447
  //# sourceMappingURL=index.js.map
1265
- export { defineCustomElements } from './defineCustomElements.js?scv=0.14.0';
1448
+ export { defineCustomElements } from './defineCustomElements.js?scv=0.15.1';