@searchcraft/javascript-sdk 0.11.0 → 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 +36 -82
- 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.
|
|
@@ -1204,9 +1208,13 @@ class SummaryClient {
|
|
|
1204
1208
|
const begin = async () => {
|
|
1205
1209
|
const state = this.get();
|
|
1206
1210
|
const config = state.core?.config;
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1211
|
+
if (!config) {
|
|
1212
|
+
console.error('Could not stream summary data, no config found.');
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1215
|
+
if (!config.cortexURL) {
|
|
1216
|
+
console.error('Could not stream summary data, cortexURL was not specified in the config.');
|
|
1217
|
+
return;
|
|
1210
1218
|
}
|
|
1211
1219
|
const indexName = state.core?.config.indexName;
|
|
1212
1220
|
if (!state.hasSummaryBox || !indexName) {
|
|
@@ -1241,6 +1249,14 @@ class SummaryClient {
|
|
|
1241
1249
|
throw new Error('Invalid fetch response');
|
|
1242
1250
|
}
|
|
1243
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
|
+
}
|
|
1244
1260
|
throw new Error(`HTTP ${fetchResponse.status}`);
|
|
1245
1261
|
}
|
|
1246
1262
|
const reader = fetchResponse.body.getReader();
|
|
@@ -1299,6 +1315,7 @@ const initialSearchcraftStateValues = {
|
|
|
1299
1315
|
hasSummaryBox: false,
|
|
1300
1316
|
summaryClient: undefined,
|
|
1301
1317
|
isSummaryLoading: false,
|
|
1318
|
+
isSummaryNotEnabled: false,
|
|
1302
1319
|
};
|
|
1303
1320
|
// const logger = new Logger({ logLevel: LogLevel.NONE });
|
|
1304
1321
|
const existingStores = {};
|
|
@@ -1358,12 +1375,14 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
|
|
|
1358
1375
|
adClientResponseItems: [...state.cachedAdClientResponseItems],
|
|
1359
1376
|
});
|
|
1360
1377
|
},
|
|
1361
|
-
search: async () => {
|
|
1378
|
+
search: async (options) => {
|
|
1362
1379
|
const state = get();
|
|
1363
|
-
state.summaryClient?.streamSummaryData();
|
|
1364
1380
|
if (!state.core) {
|
|
1365
1381
|
throw new Error('Searchcraft instance is not initialized.');
|
|
1366
1382
|
}
|
|
1383
|
+
if (state.core.config.cortexURL && !options?.skipSummary) {
|
|
1384
|
+
state.summaryClient?.streamSummaryData();
|
|
1385
|
+
}
|
|
1367
1386
|
if (!state.searchTerm.trim()) {
|
|
1368
1387
|
state.core?.searchClient?.abortRequests();
|
|
1369
1388
|
set({
|
|
@@ -1425,11 +1444,11 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
|
|
|
1425
1444
|
setSearchResultsCount: (count) => set({ searchResultsCount: count }),
|
|
1426
1445
|
setSearchResultsPage: async (page) => {
|
|
1427
1446
|
set({ searchResultsPage: page });
|
|
1428
|
-
await functions.search();
|
|
1447
|
+
await functions.search({ skipSummary: true });
|
|
1429
1448
|
},
|
|
1430
1449
|
setSearchResultsPerPage: async (perPage) => {
|
|
1431
1450
|
set({ searchResultsPerPage: perPage });
|
|
1432
|
-
await functions.search();
|
|
1451
|
+
await functions.search({ skipSummary: true });
|
|
1433
1452
|
},
|
|
1434
1453
|
setHotKeyAndHotKeyModifier: (hotkey, hotkeyModifier) => {
|
|
1435
1454
|
const { hotkey: initialHotkey, hotkeyModifier: initialHotkeyModifier } = initialSearchcraftStateValues;
|
|
@@ -1477,8 +1496,11 @@ class SearchcraftCore {
|
|
|
1477
1496
|
if (!config.readKey) {
|
|
1478
1497
|
throw new Error('SDK Configuration Error: readKey not specified.');
|
|
1479
1498
|
}
|
|
1480
|
-
if (!config.indexName) {
|
|
1481
|
-
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.');
|
|
1482
1504
|
}
|
|
1483
1505
|
this.config = {
|
|
1484
1506
|
...config,
|
|
@@ -1669,75 +1691,7 @@ class SearchcraftCore {
|
|
|
1669
1691
|
}
|
|
1670
1692
|
|
|
1671
1693
|
const name = "@searchcraft/javascript-sdk";
|
|
1672
|
-
const version = "0.
|
|
1673
|
-
const description = "Searchcraft Javascript SDK";
|
|
1674
|
-
const author = "Searchcraft Inc.";
|
|
1675
|
-
const license = "Apache-2.0";
|
|
1676
|
-
const module = "dist/components/index.js";
|
|
1677
|
-
const types = "dist/components/index.d.ts";
|
|
1678
|
-
const exports = {
|
|
1679
|
-
".": {
|
|
1680
|
-
"import": "./dist/components/index.js",
|
|
1681
|
-
types: "./dist/components/index.d.ts"
|
|
1682
|
-
},
|
|
1683
|
-
"./dist/components/*": {
|
|
1684
|
-
"import": "./dist/components/*",
|
|
1685
|
-
types: "./dist/components/*"
|
|
1686
|
-
},
|
|
1687
|
-
"./hydrate": {
|
|
1688
|
-
require: "./dist/hydrate/index.js",
|
|
1689
|
-
"import": "./dist/hydrate/index.mjs",
|
|
1690
|
-
types: "./dist/hydrate/index.d.ts"
|
|
1691
|
-
},
|
|
1692
|
-
"./themes/*.css": "./dist/themes/*.css"
|
|
1693
|
-
};
|
|
1694
|
-
const repository = {
|
|
1695
|
-
type: "git",
|
|
1696
|
-
url: "https://bitbucket.org/madebychalk/searchcraft-javascript-sdks/"
|
|
1697
|
-
};
|
|
1698
|
-
const files = [
|
|
1699
|
-
"dist/"
|
|
1700
|
-
];
|
|
1701
|
-
const scripts = {
|
|
1702
|
-
build: "stencil build",
|
|
1703
|
-
docs: "typedoc --options typedoc.json",
|
|
1704
|
-
dev: "stencil build --dev --watch",
|
|
1705
|
-
test: "stencil test --spec --e2e",
|
|
1706
|
-
"test.watch": "stencil test --spec --e2e --watchAll",
|
|
1707
|
-
generate: "stencil generate"
|
|
1708
|
-
};
|
|
1709
|
-
const dependencies = {
|
|
1710
|
-
classnames: "^2.3.2",
|
|
1711
|
-
dompurify: "^3.2.4",
|
|
1712
|
-
marked: "^15.0.12",
|
|
1713
|
-
nanoid: "^5.0.9"
|
|
1714
|
-
};
|
|
1715
|
-
const devDependencies = {
|
|
1716
|
-
"@stencil/core": "^4.7.0",
|
|
1717
|
-
"@stencil/react-output-target": "^0.8.2",
|
|
1718
|
-
"@stencil/sass": "^3.0.12",
|
|
1719
|
-
"@stencil/vue-output-target": "^0.9.2",
|
|
1720
|
-
"@thumbmarkjs/thumbmarkjs": "^0.16.1",
|
|
1721
|
-
"@types/node": "^16.18.11",
|
|
1722
|
-
nanoid: "^5.0.9",
|
|
1723
|
-
zustand: "^5.0.1"
|
|
1724
|
-
};
|
|
1725
|
-
const packageJson = {
|
|
1726
|
-
name: name,
|
|
1727
|
-
"private": false,
|
|
1728
|
-
version: version,
|
|
1729
|
-
description: description,
|
|
1730
|
-
author: author,
|
|
1731
|
-
license: license,
|
|
1732
|
-
module: module,
|
|
1733
|
-
types: types,
|
|
1734
|
-
exports: exports,
|
|
1735
|
-
repository: repository,
|
|
1736
|
-
files: files,
|
|
1737
|
-
scripts: scripts,
|
|
1738
|
-
dependencies: dependencies,
|
|
1739
|
-
devDependencies: devDependencies
|
|
1740
|
-
};
|
|
1694
|
+
const version = "0.12.0";
|
|
1741
1695
|
|
|
1742
1696
|
/**
|
|
1743
1697
|
* @fileoverview entry point for your component library
|
|
@@ -1754,8 +1708,8 @@ const packageJson = {
|
|
|
1754
1708
|
class Searchcraft extends SearchcraftCore {
|
|
1755
1709
|
constructor(config, searchcraftId = undefined) {
|
|
1756
1710
|
super(config, {
|
|
1757
|
-
sdkName:
|
|
1758
|
-
sdkVersion:
|
|
1711
|
+
sdkName: name,
|
|
1712
|
+
sdkVersion: version,
|
|
1759
1713
|
}, searchcraftId);
|
|
1760
1714
|
}
|
|
1761
1715
|
}
|