@searchcraft/javascript-sdk 0.11.1 → 0.12.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/README.md +11 -2
- package/dist/components/index.d.ts +31 -2
- package/dist/components/index.js +27 -79
- package/dist/components/index.js.map +1 -1
- package/dist/components/{p-3e41546c.js → p-02ad136b.js} +3 -3
- package/dist/components/{p-3e41546c.js.map → p-02ad136b.js.map} +1 -1
- package/dist/components/searchcraft-filter-panel.js +1 -1
- package/dist/components/searchcraft-popover-form.js +21 -3
- package/dist/components/searchcraft-popover-form.js.map +1 -1
- package/dist/components/searchcraft-summary-box.js +42 -10
- package/dist/components/searchcraft-summary-box.js.map +1 -1
- package/dist/components/searchcraft-theme.js +1 -1
- package/dist/components/searchcraft-toggle-button.js +1 -1
- package/dist/hydrate/index.js +66 -16
- package/dist/hydrate/index.mjs +66 -16
- package/dist/types/clients/SearchClient.d.ts +1 -0
- package/dist/types/components/searchcraft-popover-form/searchcraft-popover-form.d.ts +10 -0
- package/dist/types/components/searchcraft-summary-box/searchcraft-summary-box.d.ts +17 -0
- package/dist/types/components.d.ts +16 -0
- package/dist/types/store/SearchcraftStore.types.d.ts +4 -1
- package/dist/types/types/core-types/Measure.types.d.ts +1 -0
- package/dist/types/types/core-types/SearchcraftConfig.types.d.ts +9 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -49,8 +49,17 @@ As early as possible in your app's lifecycle, initialize searchcraft, passing in
|
|
|
49
49
|
```js
|
|
50
50
|
import { Searchcraft } from '@searchcraft/javascript-sdk';
|
|
51
51
|
|
|
52
|
+
// Index Search Configuration
|
|
52
53
|
const searchcraft = new Searchcraft({
|
|
53
|
-
|
|
54
|
+
indexName: 'your_index_from_vektron',
|
|
55
|
+
readKey: 'your_read_key_from_vektron',
|
|
56
|
+
endpointURL: 'your_searchcraft_endpoint_url',
|
|
57
|
+
searchDebounceDelay: 50, // The amount of debounce, in millis, to add to search requests (optional)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
// Federation Search Configuration (searches across multiple indices)
|
|
61
|
+
const federationSearchcraft = new Searchcraft({
|
|
62
|
+
federationName: 'your_federation_name',
|
|
54
63
|
readKey: 'your_read_key_from_vektron',
|
|
55
64
|
endpointURL: 'your_searchcraft_endpoint_url',
|
|
56
65
|
searchDebounceDelay: 50, // The amount of debounce, in millis, to add to search requests (optional)
|
|
@@ -170,7 +179,7 @@ You can subscribe to various events within Searchcraft:
|
|
|
170
179
|
```jsx
|
|
171
180
|
|
|
172
181
|
const searchcraft = new Searchcraft({
|
|
173
|
-
|
|
182
|
+
indexName: 'your_index_from_vektron',
|
|
174
183
|
readKey: 'your_read_key_from_vektron',
|
|
175
184
|
endpointURL: 'your_searchcraft_endpoint_url',
|
|
176
185
|
});
|
|
@@ -90,6 +90,7 @@ export interface MeasureRequestProperties {
|
|
|
90
90
|
searchcraft_organization_id?: string;
|
|
91
91
|
searchcraft_application_id?: string;
|
|
92
92
|
searchcraft_index_names: string[];
|
|
93
|
+
searchcraft_federation_name?: string;
|
|
93
94
|
search_term?: string;
|
|
94
95
|
number_of_documents?: number;
|
|
95
96
|
external_document_id?: string;
|
|
@@ -333,8 +334,16 @@ export interface SearchcraftConfig {
|
|
|
333
334
|
endpointURL: string;
|
|
334
335
|
/**
|
|
335
336
|
* Name of the Searchcraft search index to search for results within. If you are using Searchcraft Cloud, this value can be found within the Vektron dashboard in the Code Snippets section when configuring a search index.
|
|
337
|
+
*
|
|
338
|
+
* Note: Either `indexName` or `federationName` must be provided, but not both.
|
|
336
339
|
*/
|
|
337
|
-
indexName
|
|
340
|
+
indexName?: string;
|
|
341
|
+
/**
|
|
342
|
+
* Name of the Searchcraft federation to search across multiple indices. Federation search allows you to search across all indices defined in a federation with a single query.
|
|
343
|
+
*
|
|
344
|
+
* Note: Either `indexName` or `federationName` must be provided, but not both.
|
|
345
|
+
*/
|
|
346
|
+
federationName?: string;
|
|
338
347
|
/**
|
|
339
348
|
* The initial search query to call when Searchcraft is first initialized in your front-end application. This parameter can be used when you want to populate a page with an initial set of search results based on a query.
|
|
340
349
|
*
|
|
@@ -601,6 +610,7 @@ declare class SearchClient {
|
|
|
601
610
|
constructor(parent: SearchcraftCore, config: SearchcraftConfig, userId: string);
|
|
602
611
|
/**
|
|
603
612
|
* Getter for the base url used by the /search endpoint.
|
|
613
|
+
* Supports both index and federation search endpoints.
|
|
604
614
|
*/
|
|
605
615
|
private get baseSearchUrl();
|
|
606
616
|
/**
|
|
@@ -640,7 +650,9 @@ export interface SearchcraftStateFunctions {
|
|
|
640
650
|
removeFacetPathsForIndexField: (fieldName: string) => void;
|
|
641
651
|
removeRangeValueForIndexField: (fieldName: string) => void;
|
|
642
652
|
resetSearchValues: () => void;
|
|
643
|
-
search: (
|
|
653
|
+
search: (options?: {
|
|
654
|
+
skipSummary?: boolean;
|
|
655
|
+
}) => Promise<void>;
|
|
644
656
|
setPopoverVisibility: (isVisible: boolean) => void;
|
|
645
657
|
setSearchResultsCount: (count: number) => void;
|
|
646
658
|
setSearchResultsPage: (page: number) => void;
|
|
@@ -684,6 +696,7 @@ export interface SearchcraftStateValues {
|
|
|
684
696
|
hasSummaryBox: boolean;
|
|
685
697
|
isSummaryLoading: boolean;
|
|
686
698
|
summaryClient?: SummaryClient;
|
|
699
|
+
isSummaryNotEnabled: boolean;
|
|
687
700
|
}
|
|
688
701
|
export interface SearchcraftState extends SearchcraftStateFunctions, SearchcraftStateValues {
|
|
689
702
|
}
|
|
@@ -1048,6 +1061,14 @@ export namespace Components {
|
|
|
1048
1061
|
* The hotkey modifier that activates the popover. Used together with the `hotkey` prop.
|
|
1049
1062
|
*/
|
|
1050
1063
|
"hotkeyModifier"?: "ctrl" | "meta" | "alt" | "option";
|
|
1064
|
+
/**
|
|
1065
|
+
* The placeholder's render behavior. 'hide-on-focus' - Hide the placeholder text immediately when the input form gains focus. 'hide-on-text-entered' - Only hide the placeholder when the input form has text entered into it.
|
|
1066
|
+
*/
|
|
1067
|
+
"placeholderBehavior"?: "hide-on-focus" | "hide-on-text-entered";
|
|
1068
|
+
/**
|
|
1069
|
+
* The input element's placeholder value.
|
|
1070
|
+
*/
|
|
1071
|
+
"placeholderValue"?: string;
|
|
1051
1072
|
/**
|
|
1052
1073
|
* Formats the content rendered for each result.
|
|
1053
1074
|
*/
|
|
@@ -2303,6 +2324,14 @@ declare namespace LocalJSX {
|
|
|
2303
2324
|
* The hotkey modifier that activates the popover. Used together with the `hotkey` prop.
|
|
2304
2325
|
*/
|
|
2305
2326
|
"hotkeyModifier"?: "ctrl" | "meta" | "alt" | "option";
|
|
2327
|
+
/**
|
|
2328
|
+
* The placeholder's render behavior. 'hide-on-focus' - Hide the placeholder text immediately when the input form gains focus. 'hide-on-text-entered' - Only hide the placeholder when the input form has text entered into it.
|
|
2329
|
+
*/
|
|
2330
|
+
"placeholderBehavior"?: "hide-on-focus" | "hide-on-text-entered";
|
|
2331
|
+
/**
|
|
2332
|
+
* The input element's placeholder value.
|
|
2333
|
+
*/
|
|
2334
|
+
"placeholderValue"?: string;
|
|
2306
2335
|
/**
|
|
2307
2336
|
* Formats the content rendered for each result.
|
|
2308
2337
|
*/
|
package/dist/components/index.js
CHANGED
|
@@ -264,7 +264,8 @@ class MeasureClient {
|
|
|
264
264
|
const request = {
|
|
265
265
|
event_name: eventName,
|
|
266
266
|
properties: {
|
|
267
|
-
searchcraft_index_names: [this.config.indexName],
|
|
267
|
+
searchcraft_index_names: this.config.indexName ? [this.config.indexName] : [],
|
|
268
|
+
searchcraft_federation_name: this.config.federationName,
|
|
268
269
|
session_id: this.sessionId,
|
|
269
270
|
...properties,
|
|
270
271
|
},
|
|
@@ -372,9 +373,12 @@ class SearchClient {
|
|
|
372
373
|
}
|
|
373
374
|
/**
|
|
374
375
|
* Getter for the base url used by the /search endpoint.
|
|
376
|
+
* Supports both index and federation search endpoints.
|
|
375
377
|
*/
|
|
376
378
|
get baseSearchUrl() {
|
|
377
|
-
return
|
|
379
|
+
return this.config.federationName
|
|
380
|
+
? `${this.config.endpointURL}/federation/${this.config.federationName}/search`
|
|
381
|
+
: `${this.config.endpointURL}/index/${this.config.indexName}/search`;
|
|
378
382
|
}
|
|
379
383
|
/**
|
|
380
384
|
* Immediately cancels all pending search requests.
|
|
@@ -1245,6 +1249,14 @@ class SummaryClient {
|
|
|
1245
1249
|
throw new Error('Invalid fetch response');
|
|
1246
1250
|
}
|
|
1247
1251
|
if (!fetchResponse.ok) {
|
|
1252
|
+
if (fetchResponse.status === 403) {
|
|
1253
|
+
console.warn('Please contact Searchcraft to enable AI summaries with your account');
|
|
1254
|
+
this.set({
|
|
1255
|
+
isSummaryLoading: false,
|
|
1256
|
+
isSummaryNotEnabled: true,
|
|
1257
|
+
});
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1248
1260
|
throw new Error(`HTTP ${fetchResponse.status}`);
|
|
1249
1261
|
}
|
|
1250
1262
|
const reader = fetchResponse.body.getReader();
|
|
@@ -1303,6 +1315,7 @@ const initialSearchcraftStateValues = {
|
|
|
1303
1315
|
hasSummaryBox: false,
|
|
1304
1316
|
summaryClient: undefined,
|
|
1305
1317
|
isSummaryLoading: false,
|
|
1318
|
+
isSummaryNotEnabled: false,
|
|
1306
1319
|
};
|
|
1307
1320
|
// const logger = new Logger({ logLevel: LogLevel.NONE });
|
|
1308
1321
|
const existingStores = {};
|
|
@@ -1362,12 +1375,12 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
|
|
|
1362
1375
|
adClientResponseItems: [...state.cachedAdClientResponseItems],
|
|
1363
1376
|
});
|
|
1364
1377
|
},
|
|
1365
|
-
search: async () => {
|
|
1378
|
+
search: async (options) => {
|
|
1366
1379
|
const state = get();
|
|
1367
1380
|
if (!state.core) {
|
|
1368
1381
|
throw new Error('Searchcraft instance is not initialized.');
|
|
1369
1382
|
}
|
|
1370
|
-
if (state.core.config.cortexURL) {
|
|
1383
|
+
if (state.core.config.cortexURL && !options?.skipSummary) {
|
|
1371
1384
|
state.summaryClient?.streamSummaryData();
|
|
1372
1385
|
}
|
|
1373
1386
|
if (!state.searchTerm.trim()) {
|
|
@@ -1431,11 +1444,11 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
|
|
|
1431
1444
|
setSearchResultsCount: (count) => set({ searchResultsCount: count }),
|
|
1432
1445
|
setSearchResultsPage: async (page) => {
|
|
1433
1446
|
set({ searchResultsPage: page });
|
|
1434
|
-
await functions.search();
|
|
1447
|
+
await functions.search({ skipSummary: true });
|
|
1435
1448
|
},
|
|
1436
1449
|
setSearchResultsPerPage: async (perPage) => {
|
|
1437
1450
|
set({ searchResultsPerPage: perPage });
|
|
1438
|
-
await functions.search();
|
|
1451
|
+
await functions.search({ skipSummary: true });
|
|
1439
1452
|
},
|
|
1440
1453
|
setHotKeyAndHotKeyModifier: (hotkey, hotkeyModifier) => {
|
|
1441
1454
|
const { hotkey: initialHotkey, hotkeyModifier: initialHotkeyModifier } = initialSearchcraftStateValues;
|
|
@@ -1483,8 +1496,11 @@ class SearchcraftCore {
|
|
|
1483
1496
|
if (!config.readKey) {
|
|
1484
1497
|
throw new Error('SDK Configuration Error: readKey not specified.');
|
|
1485
1498
|
}
|
|
1486
|
-
if (!config.indexName) {
|
|
1487
|
-
throw new Error('SDK Configuration Error: indexName
|
|
1499
|
+
if (!config.indexName && !config.federationName) {
|
|
1500
|
+
throw new Error('SDK Configuration Error: Either indexName or federationName must be specified.');
|
|
1501
|
+
}
|
|
1502
|
+
if (config.indexName && config.federationName) {
|
|
1503
|
+
throw new Error('SDK Configuration Error: Cannot specify both indexName and federationName. Please specify only one.');
|
|
1488
1504
|
}
|
|
1489
1505
|
this.config = {
|
|
1490
1506
|
...config,
|
|
@@ -1675,75 +1691,7 @@ class SearchcraftCore {
|
|
|
1675
1691
|
}
|
|
1676
1692
|
|
|
1677
1693
|
const name = "@searchcraft/javascript-sdk";
|
|
1678
|
-
const version = "0.
|
|
1679
|
-
const description = "Searchcraft Javascript SDK";
|
|
1680
|
-
const author = "Searchcraft Inc.";
|
|
1681
|
-
const license = "Apache-2.0";
|
|
1682
|
-
const module = "dist/components/index.js";
|
|
1683
|
-
const types = "dist/components/index.d.ts";
|
|
1684
|
-
const exports = {
|
|
1685
|
-
".": {
|
|
1686
|
-
"import": "./dist/components/index.js",
|
|
1687
|
-
types: "./dist/components/index.d.ts"
|
|
1688
|
-
},
|
|
1689
|
-
"./dist/components/*": {
|
|
1690
|
-
"import": "./dist/components/*",
|
|
1691
|
-
types: "./dist/components/*"
|
|
1692
|
-
},
|
|
1693
|
-
"./hydrate": {
|
|
1694
|
-
require: "./dist/hydrate/index.js",
|
|
1695
|
-
"import": "./dist/hydrate/index.mjs",
|
|
1696
|
-
types: "./dist/hydrate/index.d.ts"
|
|
1697
|
-
},
|
|
1698
|
-
"./themes/*.css": "./dist/themes/*.css"
|
|
1699
|
-
};
|
|
1700
|
-
const repository = {
|
|
1701
|
-
type: "git",
|
|
1702
|
-
url: "https://bitbucket.org/madebychalk/searchcraft-javascript-sdks/"
|
|
1703
|
-
};
|
|
1704
|
-
const files = [
|
|
1705
|
-
"dist/"
|
|
1706
|
-
];
|
|
1707
|
-
const scripts = {
|
|
1708
|
-
build: "stencil build",
|
|
1709
|
-
docs: "typedoc --options typedoc.json",
|
|
1710
|
-
dev: "stencil build --dev --watch",
|
|
1711
|
-
test: "stencil test --spec --e2e",
|
|
1712
|
-
"test.watch": "stencil test --spec --e2e --watchAll",
|
|
1713
|
-
generate: "stencil generate"
|
|
1714
|
-
};
|
|
1715
|
-
const dependencies = {
|
|
1716
|
-
classnames: "^2.3.2",
|
|
1717
|
-
dompurify: "^3.2.4",
|
|
1718
|
-
marked: "^15.0.12",
|
|
1719
|
-
nanoid: "^5.0.9"
|
|
1720
|
-
};
|
|
1721
|
-
const devDependencies = {
|
|
1722
|
-
"@stencil/core": "^4.7.0",
|
|
1723
|
-
"@stencil/react-output-target": "^0.8.2",
|
|
1724
|
-
"@stencil/sass": "^3.0.12",
|
|
1725
|
-
"@stencil/vue-output-target": "^0.9.2",
|
|
1726
|
-
"@thumbmarkjs/thumbmarkjs": "^0.16.1",
|
|
1727
|
-
"@types/node": "^16.18.11",
|
|
1728
|
-
nanoid: "^5.0.9",
|
|
1729
|
-
zustand: "^5.0.1"
|
|
1730
|
-
};
|
|
1731
|
-
const packageJson = {
|
|
1732
|
-
name: name,
|
|
1733
|
-
"private": false,
|
|
1734
|
-
version: version,
|
|
1735
|
-
description: description,
|
|
1736
|
-
author: author,
|
|
1737
|
-
license: license,
|
|
1738
|
-
module: module,
|
|
1739
|
-
types: types,
|
|
1740
|
-
exports: exports,
|
|
1741
|
-
repository: repository,
|
|
1742
|
-
files: files,
|
|
1743
|
-
scripts: scripts,
|
|
1744
|
-
dependencies: dependencies,
|
|
1745
|
-
devDependencies: devDependencies
|
|
1746
|
-
};
|
|
1694
|
+
const version = "0.12.0";
|
|
1747
1695
|
|
|
1748
1696
|
/**
|
|
1749
1697
|
* @fileoverview entry point for your component library
|
|
@@ -1760,8 +1708,8 @@ const packageJson = {
|
|
|
1760
1708
|
class Searchcraft extends SearchcraftCore {
|
|
1761
1709
|
constructor(config, searchcraftId = undefined) {
|
|
1762
1710
|
super(config, {
|
|
1763
|
-
sdkName:
|
|
1764
|
-
sdkVersion:
|
|
1711
|
+
sdkName: name,
|
|
1712
|
+
sdkVersion: version,
|
|
1765
1713
|
}, searchcraftId);
|
|
1766
1714
|
}
|
|
1767
1715
|
}
|