🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@searchkit/api

Package Overview
Dependencies
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@searchkit/api - npm Package Compare versions

Comparing version

to
4.0.0-next.6

10

dist/index.d.ts

@@ -79,7 +79,11 @@ import { MultipleQueriesQuery } from '@algolia/client-search';

}
interface AppSettings {
debug: boolean;
}
declare class Client {
private config;
private settings;
transporter: Transporter;
constructor(config: ClientConfig);
constructor(config: ClientConfig, settings?: AppSettings);
private performSearch;

@@ -165,4 +169,4 @@ handleRequest(body: any, requestOptions?: RequestOptions): Promise<{

}
declare const createClient: (config: ClientConfig) => Client;
declare const createClient: (config: ClientConfig, settings?: AppSettings) => Client;
export { ClientConfig, ClientConfigConnection, ElasticsearchHit, ElasticsearchQuery, ElasticsearchResponseBody, FacetAttribute, FacetFieldConfig, QueryRule, QueryRuleAction, QueryRuleCondition, RequestOptions, SearchRequest, SearchSettingsConfig, Transporter, createClient as default };
export { AppSettings, ClientConfig, ClientConfigConnection, ElasticsearchHit, ElasticsearchQuery, ElasticsearchResponseBody, FacetAttribute, FacetFieldConfig, QueryRule, QueryRuleAction, QueryRuleCondition, RequestOptions, SearchRequest, SearchSettingsConfig, Transporter, createClient as default };

@@ -583,15 +583,19 @@ "use strict";

function transformResponse(response, instantsearchRequest, config, queryRuleActions) {
return {
exhaustiveNbHits: true,
exhaustiveFacetsCount: true,
exhaustiveTypo: true,
exhaustive: { facetsCount: true, nbHits: true, typo: true },
...getPageDetails(response, instantsearchRequest, config),
...getRenderingContent(config, queryRuleActions),
...getFacets(response, config),
hits: getHits(response, config),
index: instantsearchRequest.indexName,
params: (0, import_querystring.stringify)(instantsearchRequest.params),
...queryRuleActions.userData.length > 0 ? { userData: queryRuleActions.userData } : {}
};
try {
return {
exhaustiveNbHits: true,
exhaustiveFacetsCount: true,
exhaustiveTypo: true,
exhaustive: { facetsCount: true, nbHits: true, typo: true },
...getPageDetails(response, instantsearchRequest, config),
...getRenderingContent(config, queryRuleActions),
...getFacets(response, config),
hits: getHits(response, config),
index: instantsearchRequest.indexName,
params: (0, import_querystring.stringify)(instantsearchRequest.params),
...queryRuleActions.userData.length > 0 ? { userData: queryRuleActions.userData } : {}
};
} catch (e) {
throw new Error(`Error transforming Elasticsearch response for index`);
}
}

@@ -620,21 +624,47 @@ var transformFacetValuesResponse = (response, instantsearchRequest) => {

async msearch(requests) {
const response = await fetch(`${this.config.host}/_msearch`, {
headers: {
...this.config.apiKey ? { authorization: `ApiKey ${this.config.apiKey}` } : {},
"content-type": "application/json"
},
body: requests.reduce(
(sum, request) => [
...sum,
JSON.stringify({ index: request.indexName }),
"\n",
JSON.stringify(request.body),
"\n"
],
[]
).join(""),
method: "POST"
});
const responses = await response.json();
return responses.responses;
var _a, _b, _c, _d;
try {
const response = await fetch(`${this.config.host}/_msearch`, {
headers: {
...this.config.apiKey ? { authorization: `ApiKey ${this.config.apiKey}` } : {},
"content-type": "application/json"
},
body: requests.reduce(
(sum, request) => [
...sum,
JSON.stringify({ index: request.indexName }),
"\n",
JSON.stringify(request.body),
"\n"
],
[]
).join(""),
method: "POST"
});
const responses = await response.json();
if (responses.status >= 500) {
throw new Error(
"Elasticsearch Internal Error: Check your elasticsearch instance to make sure it can recieve requests."
);
} else if (responses.status === 401) {
throw new Error(
"Cannot connect to Elasticsearch. Check your connection host and API Key. You can also provide a custom Elasticsearch transporter to the API Client. See docs for more information."
);
} else if (((_b = (_a = responses.responses) == null ? void 0 : _a[0]) == null ? void 0 : _b.status) === 403) {
throw new Error(
"Auth Error: You do not have permission to access this index. Check you are calling the right index (specified in frontend) and your API Key permissions has access to the index."
);
} else if (responses.status === 404 || ((_d = (_c = responses.responses) == null ? void 0 : _c[0]) == null ? void 0 : _d.status) === 404) {
throw new Error(
"Elasticsearch index not found. Check your index name and make sure it exists."
);
} else if (responses.status === 400) {
throw new Error(
"Elasticsearch Bad Request. Check your query and make sure it is valid. Turn on debug mode to see the Elasticsearch query."
);
}
return responses.responses;
} catch (error) {
throw error;
}
}

@@ -699,7 +729,12 @@ };

var Client = class {
constructor(config) {
constructor(config, settings = { debug: false }) {
this.config = config;
this.settings = settings;
this.transporter = "msearch" in config.connection ? config.connection : new ESTransporter(config.connection);
}
async performSearch(requests) {
if (this.settings.debug) {
console.log("Performing search with requests:");
console.log(JSON.stringify(requests, null, 2));
}
const responses = await this.transporter.msearch(requests);

@@ -748,3 +783,3 @@ return responses;

};
var createClient = (config) => new Client(config);
var createClient = (config, settings) => new Client(config, settings);
var src_default = createClient;

@@ -751,0 +786,0 @@ // Annotate the CommonJS export names for ESM import in node:

{
"name": "@searchkit/api",
"version": "4.0.0-next.5",
"version": "4.0.0-next.6",
"main": "./dist/index.js",

@@ -5,0 +5,0 @@ "description": "",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet