@searchcraft/javascript-sdk 0.13.3 → 0.15.0
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/components/defineCustomElements.js +25 -23
- package/dist/components/html.js +1 -1
- package/dist/components/index.d.ts +213 -5
- package/dist/components/index.js +245 -64
- package/dist/components/index.js.map +1 -1
- package/dist/components/marked.esm.js +2163 -0
- package/dist/components/marked.esm.js.map +1 -0
- package/dist/components/searchcraft-ad.js +1 -1
- package/dist/components/searchcraft-ad2.js +4 -4
- package/dist/components/searchcraft-button.js +1 -1
- package/dist/components/searchcraft-button2.js +2 -2
- package/dist/components/searchcraft-error-message.js +1 -1
- package/dist/components/searchcraft-error-message2.js +1 -1
- package/dist/components/searchcraft-facet-list.js +1 -1
- package/dist/components/searchcraft-facet-list2.js +2 -2
- package/dist/components/searchcraft-facet-list2.js.map +1 -1
- package/dist/components/searchcraft-filter-panel.js +18 -9
- package/dist/components/searchcraft-filter-panel.js.map +1 -1
- package/dist/components/searchcraft-input-form.js +1 -1
- package/dist/components/searchcraft-input-form2.js +6 -6
- package/dist/components/searchcraft-input-label.js +1 -1
- package/dist/components/searchcraft-input-label2.js +2 -2
- package/dist/components/searchcraft-loading.js +1 -1
- package/dist/components/searchcraft-loading2.js +5 -2
- package/dist/components/searchcraft-loading2.js.map +1 -1
- package/dist/components/searchcraft-pagination.js +96 -8
- package/dist/components/searchcraft-pagination.js.map +1 -1
- package/dist/components/searchcraft-popover-button.js +6 -4
- package/dist/components/searchcraft-popover-button.js.map +1 -1
- package/dist/components/searchcraft-popover-footer.js +1 -1
- package/dist/components/searchcraft-popover-footer2.js +51 -7
- package/dist/components/searchcraft-popover-footer2.js.map +1 -1
- package/dist/components/searchcraft-popover-form.js +96 -22
- package/dist/components/searchcraft-popover-form.js.map +1 -1
- package/dist/components/searchcraft-popover-list-item.js +1 -1
- package/dist/components/searchcraft-popover-list-item2.js +3 -3
- package/dist/components/searchcraft-popover-list-view.js +1 -1
- package/dist/components/searchcraft-popover-list-view2.js +4 -4
- package/dist/components/searchcraft-results-info.js +4 -4
- package/dist/components/searchcraft-results-summary.d.ts +11 -0
- package/dist/components/searchcraft-results-summary.js +9 -0
- package/dist/components/searchcraft-results-summary.js.map +1 -0
- package/dist/components/searchcraft-results-summary2.js +97 -0
- package/dist/components/searchcraft-results-summary2.js.map +1 -0
- package/dist/components/searchcraft-search-result.js +1 -1
- package/dist/components/searchcraft-search-result2.js +3 -3
- package/dist/components/searchcraft-search-results-per-page.js +3 -3
- package/dist/components/searchcraft-search-results.js +5 -5
- package/dist/components/searchcraft-select.js +1 -1
- package/dist/components/searchcraft-select2.js +1 -1
- package/dist/components/searchcraft-slider.js +1 -1
- package/dist/components/searchcraft-slider2.js +5 -5
- package/dist/components/searchcraft-summary-box.js +11 -2178
- package/dist/components/searchcraft-summary-box.js.map +1 -1
- package/dist/components/searchcraft-theme.js +3 -3
- package/dist/components/searchcraft-theme.js.map +1 -1
- package/dist/components/searchcraft-toggle-button.js +1 -1
- package/dist/components/searchcraft-toggle-button2.js +5 -5
- package/dist/hydrate/index.js +2294 -1985
- package/dist/hydrate/index.mjs +2294 -1985
- package/dist/themes/hologram.css +1 -1
- package/dist/themes/hologram.css.map +1 -1
- package/dist/types/clients/SummaryClient.d.ts +10 -1
- package/dist/types/components/searchcraft-pagination/searchcraft-pagination.d.ts +28 -0
- package/dist/types/components/searchcraft-popover-button/searchcraft-popover-button.d.ts +1 -1
- package/dist/types/components/searchcraft-popover-footer/searchcraft-popover-footer.d.ts +15 -0
- package/dist/types/components/searchcraft-popover-form/searchcraft-popover-form.d.ts +24 -0
- package/dist/types/components/searchcraft-results-summary/searchcraft-results-summary.d.ts +65 -0
- package/dist/types/components/searchcraft-summary-box/searchcraft-summary-box.d.ts +5 -5
- package/dist/types/components.d.ts +191 -2
- package/dist/types/store/SearchcraftStore.types.d.ts +1 -0
- package/dist/types/types/core-types/SearchcraftConfig.types.d.ts +2 -2
- package/package.json +19 -2
package/dist/components/index.js
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
export { g as getAssetPath, r as render, s as setAssetPath, a as setNonce, b as setPlatformOptions } from './index2.js?
|
|
2
|
-
import { n as nanoid } from './searchcraft-ad2.js?
|
|
3
|
-
import { D as DEFAULT_CORE_INSTANCE_ID, r as registry } from './CoreInstanceRegistry.js?
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
1
|
+
export { g as getAssetPath, r as render, s as setAssetPath, a as setNonce, b as setPlatformOptions } from './index2.js?scv=0.15.0';
|
|
2
|
+
import { n as nanoid } from './searchcraft-ad2.js?scv=0.15.0';
|
|
3
|
+
import { D as DEFAULT_CORE_INSTANCE_ID, r as registry } from './CoreInstanceRegistry.js?scv=0.15.0';
|
|
4
|
+
import { v as version, n as name } from './searchcraft-popover-footer2.js?scv=0.15.0';
|
|
5
|
+
export { SearchcraftAd, defineCustomElement as defineCustomElementSearchcraftAd } from './searchcraft-ad.js?scv=0.15.0';
|
|
6
|
+
export { SearchcraftButton, defineCustomElement as defineCustomElementSearchcraftButton } from './searchcraft-button.js?scv=0.15.0';
|
|
7
|
+
export { SearchcraftErrorMessage, defineCustomElement as defineCustomElementSearchcraftErrorMessage } from './searchcraft-error-message.js?scv=0.15.0';
|
|
8
|
+
export { SearchcraftFacetList, defineCustomElement as defineCustomElementSearchcraftFacetList } from './searchcraft-facet-list.js?scv=0.15.0';
|
|
9
|
+
export { SearchcraftFilterPanel, defineCustomElement as defineCustomElementSearchcraftFilterPanel } from './searchcraft-filter-panel.js?scv=0.15.0';
|
|
10
|
+
export { SearchcraftInputForm, defineCustomElement as defineCustomElementSearchcraftInputForm } from './searchcraft-input-form.js?scv=0.15.0';
|
|
11
|
+
export { SearchcraftInputLabel, defineCustomElement as defineCustomElementSearchcraftInputLabel } from './searchcraft-input-label.js?scv=0.15.0';
|
|
12
|
+
export { SearchcraftLoading, defineCustomElement as defineCustomElementSearchcraftLoading } from './searchcraft-loading.js?scv=0.15.0';
|
|
13
|
+
export { SearchcraftPagination, defineCustomElement as defineCustomElementSearchcraftPagination } from './searchcraft-pagination.js?scv=0.15.0';
|
|
14
|
+
export { SearchcraftPopoverButton, defineCustomElement as defineCustomElementSearchcraftPopoverButton } from './searchcraft-popover-button.js?scv=0.15.0';
|
|
15
|
+
export { SearchcraftPopoverFooter, defineCustomElement as defineCustomElementSearchcraftPopoverFooter } from './searchcraft-popover-footer.js?scv=0.15.0';
|
|
16
|
+
export { SearchcraftPopoverForm, defineCustomElement as defineCustomElementSearchcraftPopoverForm } from './searchcraft-popover-form.js?scv=0.15.0';
|
|
17
|
+
export { SearchcraftPopoverListItem, defineCustomElement as defineCustomElementSearchcraftPopoverListItem } from './searchcraft-popover-list-item.js?scv=0.15.0';
|
|
18
|
+
export { SearchcraftPopoverListView, defineCustomElement as defineCustomElementSearchcraftPopoverListView } from './searchcraft-popover-list-view.js?scv=0.15.0';
|
|
19
|
+
export { SearchcraftResultsInfo, defineCustomElement as defineCustomElementSearchcraftResultsInfo } from './searchcraft-results-info.js?scv=0.15.0';
|
|
20
|
+
export { SearchcraftResultsSummary, defineCustomElement as defineCustomElementSearchcraftResultsSummary } from './searchcraft-results-summary.js?scv=0.15.0';
|
|
21
|
+
export { SearchcraftSearchResult, defineCustomElement as defineCustomElementSearchcraftSearchResult } from './searchcraft-search-result.js?scv=0.15.0';
|
|
22
|
+
export { SearchcraftSearchResults, defineCustomElement as defineCustomElementSearchcraftSearchResults } from './searchcraft-search-results.js?scv=0.15.0';
|
|
23
|
+
export { SearchcraftSearchResultsPerPage, defineCustomElement as defineCustomElementSearchcraftSearchResultsPerPage } from './searchcraft-search-results-per-page.js?scv=0.15.0';
|
|
24
|
+
export { SearchcraftSelect, defineCustomElement as defineCustomElementSearchcraftSelect } from './searchcraft-select.js?scv=0.15.0';
|
|
25
|
+
export { SearchcraftSlider, defineCustomElement as defineCustomElementSearchcraftSlider } from './searchcraft-slider.js?scv=0.15.0';
|
|
26
|
+
export { SearchcraftSummaryBox, defineCustomElement as defineCustomElementSearchcraftSummaryBox } from './searchcraft-summary-box.js?scv=0.15.0';
|
|
27
|
+
export { SearchcraftTheme, defineCustomElement as defineCustomElementSearchcraftTheme } from './searchcraft-theme.js?scv=0.15.0';
|
|
28
|
+
export { SearchcraftToggleButton, defineCustomElement as defineCustomElementSearchcraftToggleButton } from './searchcraft-toggle-button.js?scv=0.15.0';
|
|
27
29
|
|
|
28
30
|
var LogLevel;
|
|
29
31
|
(function (LogLevel) {
|
|
@@ -608,16 +610,19 @@ const createStoreImpl = (createState) => {
|
|
|
608
610
|
const createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
|
|
609
611
|
|
|
610
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.';
|
|
611
615
|
class SummaryClient {
|
|
612
616
|
set;
|
|
613
617
|
get;
|
|
614
618
|
abortController;
|
|
615
619
|
timeout;
|
|
620
|
+
hasWarnedAboutDeprecatedCortexURL = false;
|
|
616
621
|
constructor(get, set) {
|
|
617
622
|
this.get = get;
|
|
618
623
|
this.set = set;
|
|
619
624
|
}
|
|
620
|
-
streamSummaryData() {
|
|
625
|
+
streamSummaryData(requestProperties) {
|
|
621
626
|
const begin = async () => {
|
|
622
627
|
const state = this.get();
|
|
623
628
|
const config = state.core?.config;
|
|
@@ -625,21 +630,34 @@ class SummaryClient {
|
|
|
625
630
|
console.error('Could not stream summary data, no config found.');
|
|
626
631
|
return;
|
|
627
632
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
return;
|
|
631
|
-
}
|
|
633
|
+
const deprecatedCortexURL = config.cortexURL;
|
|
634
|
+
this.warnIfUsingDeprecatedCortexURL(deprecatedCortexURL);
|
|
632
635
|
const indexName = state.core?.config.indexName;
|
|
633
636
|
if (!state.hasSummaryBox || !indexName) {
|
|
634
637
|
return;
|
|
635
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
|
+
}
|
|
636
652
|
this.abortController?.abort('A newer request has replaced this one.');
|
|
637
653
|
this.abortController = new AbortController();
|
|
638
654
|
this.set({
|
|
639
655
|
isSummaryLoading: true,
|
|
656
|
+
isSummaryNotEnabled: false,
|
|
640
657
|
summary: '',
|
|
658
|
+
summaryErrorMessage: '',
|
|
641
659
|
});
|
|
642
|
-
const endpointUrl = `${config.
|
|
660
|
+
const endpointUrl = `${config.endpointURL}/index/${indexName}/search/summary`;
|
|
643
661
|
try {
|
|
644
662
|
const fetchResponse = await fetch(endpointUrl, {
|
|
645
663
|
method: 'POST',
|
|
@@ -650,45 +668,49 @@ class SummaryClient {
|
|
|
650
668
|
'X-Sc-Session-Id': state.core?.measureClient?.sessionId || '',
|
|
651
669
|
'X-Sc-User-Type': state.core?.userType || 'anonymous',
|
|
652
670
|
},
|
|
653
|
-
body: JSON.stringify(
|
|
654
|
-
searchQuery: state.searchClientRequest,
|
|
655
|
-
summaryInstructionsPrompt: state.core?.config.summaryInstructionsPrompt,
|
|
656
|
-
indexName: indexName,
|
|
657
|
-
endpointUrl: state.core?.config.endpointURL,
|
|
658
|
-
}),
|
|
671
|
+
body: JSON.stringify(searchClientRequest),
|
|
659
672
|
signal: this.abortController.signal,
|
|
660
673
|
});
|
|
661
674
|
if (!fetchResponse) {
|
|
662
675
|
throw new Error('Invalid fetch response');
|
|
663
676
|
}
|
|
664
|
-
if (!fetchResponse.body) {
|
|
665
|
-
throw new Error('Invalid fetch response');
|
|
666
|
-
}
|
|
667
677
|
if (!fetchResponse.ok) {
|
|
678
|
+
if (fetchResponse.status === 401) {
|
|
679
|
+
console.warn(SUMMARY_PERMISSION_MESSAGE);
|
|
680
|
+
this.setSummaryUnavailable(SUMMARY_PERMISSION_MESSAGE);
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
668
683
|
if (fetchResponse.status === 403) {
|
|
669
|
-
console.warn(
|
|
670
|
-
this.
|
|
671
|
-
isSummaryLoading: false,
|
|
672
|
-
isSummaryNotEnabled: true,
|
|
673
|
-
});
|
|
684
|
+
console.warn(SUMMARY_NOT_ENABLED_MESSAGE);
|
|
685
|
+
this.setSummaryUnavailable(SUMMARY_NOT_ENABLED_MESSAGE);
|
|
674
686
|
return;
|
|
675
687
|
}
|
|
676
688
|
throw new Error(`HTTP ${fetchResponse.status}`);
|
|
677
689
|
}
|
|
690
|
+
if (!fetchResponse.body) {
|
|
691
|
+
throw new Error('Invalid fetch response');
|
|
692
|
+
}
|
|
678
693
|
const reader = fetchResponse.body.getReader();
|
|
679
694
|
const decoder = new TextDecoder();
|
|
680
|
-
let
|
|
681
|
-
|
|
695
|
+
let buffer = '';
|
|
696
|
+
while (true) {
|
|
682
697
|
const { done, value } = await reader.read();
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
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
|
+
}
|
|
690
709
|
}
|
|
691
710
|
catch (error) {
|
|
711
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
692
714
|
if (error instanceof Error) {
|
|
693
715
|
console.error(error.message);
|
|
694
716
|
}
|
|
@@ -701,6 +723,157 @@ class SummaryClient {
|
|
|
701
723
|
clearTimeout(this.timeout);
|
|
702
724
|
this.timeout = setTimeout(() => begin(), delay);
|
|
703
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
|
+
}
|
|
704
877
|
}
|
|
705
878
|
|
|
706
879
|
const initialSearchcraftStateValues = {
|
|
@@ -734,6 +907,7 @@ const initialSearchcraftStateValues = {
|
|
|
734
907
|
sortType: undefined,
|
|
735
908
|
orderByField: undefined,
|
|
736
909
|
summary: '',
|
|
910
|
+
summaryErrorMessage: '',
|
|
737
911
|
hasSummaryBox: false,
|
|
738
912
|
summaryClient: undefined,
|
|
739
913
|
isSummaryLoading: false,
|
|
@@ -813,9 +987,6 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
|
|
|
813
987
|
if (!state.core) {
|
|
814
988
|
throw new Error('Searchcraft instance is not initialized.');
|
|
815
989
|
}
|
|
816
|
-
if (state.core.config.cortexURL && !options?.skipSummary) {
|
|
817
|
-
state.summaryClient?.streamSummaryData();
|
|
818
|
-
}
|
|
819
990
|
// Check if this is an initialQuery case (string requestProperties with empty searchTerm)
|
|
820
991
|
const isInitialQuery = typeof state.cachedSearchClientRequestProperties === 'string' &&
|
|
821
992
|
state.searchTerm.trim() === '';
|
|
@@ -830,8 +1001,15 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
|
|
|
830
1001
|
(hasActiveFilters ||
|
|
831
1002
|
hasNonDefaultPagination ||
|
|
832
1003
|
hasNonDefaultSearchMode)) {
|
|
833
|
-
|
|
834
|
-
|
|
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
|
+
}
|
|
835
1013
|
set({ isSearchInProgress: true });
|
|
836
1014
|
// Build the modified query array starting with the base query
|
|
837
1015
|
const baseQuery = Array.isArray(initialQueryObj.query)
|
|
@@ -875,6 +1053,9 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
|
|
|
875
1053
|
: 0,
|
|
876
1054
|
limit: state.searchResultsPerPage,
|
|
877
1055
|
};
|
|
1056
|
+
if (!options?.skipSummary) {
|
|
1057
|
+
state.summaryClient?.streamSummaryData(JSON.stringify(modifiedRequest));
|
|
1058
|
+
}
|
|
878
1059
|
state.core.getResponseItems({
|
|
879
1060
|
requestProperties: JSON.stringify(modifiedRequest),
|
|
880
1061
|
shouldCacheResultsForEmptyState: false,
|
|
@@ -911,6 +1092,9 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
|
|
|
911
1092
|
: 0,
|
|
912
1093
|
limit: state.searchResultsPerPage,
|
|
913
1094
|
};
|
|
1095
|
+
if (!options?.skipSummary) {
|
|
1096
|
+
state.summaryClient?.streamSummaryData(searchClientRequestProperites);
|
|
1097
|
+
}
|
|
914
1098
|
state.core.getResponseItems({
|
|
915
1099
|
requestProperties: searchClientRequestProperites,
|
|
916
1100
|
shouldCacheResultsForEmptyState: false,
|
|
@@ -1236,9 +1420,6 @@ class SearchcraftCore {
|
|
|
1236
1420
|
};
|
|
1237
1421
|
}
|
|
1238
1422
|
|
|
1239
|
-
const name = "@searchcraft/javascript-sdk";
|
|
1240
|
-
const version = "0.13.3";
|
|
1241
|
-
|
|
1242
1423
|
/**
|
|
1243
1424
|
* @fileoverview entry point for your component library
|
|
1244
1425
|
*
|
|
@@ -1264,4 +1445,4 @@ export { Searchcraft, SearchcraftCore };
|
|
|
1264
1445
|
//# sourceMappingURL=index.js.map
|
|
1265
1446
|
|
|
1266
1447
|
//# sourceMappingURL=index.js.map
|
|
1267
|
-
export { defineCustomElements } from './defineCustomElements.js?
|
|
1448
|
+
export { defineCustomElements } from './defineCustomElements.js?scv=0.15.0';
|