@lableb/javascript-sdk
Version:
Lableb cloud search client for javascript
53 lines (38 loc) • 1.55 kB
text/typescript
import { LablebHttpClient } from "../../http-client";
import { SearchRequestParams } from "../../request/search/search.request.type";
import { camelCaseToSnackCaseObject, } from "../../utils";
import { LablebAPIResponseWrapper, LablebSDKContext } from "../lableb-client/lableb-client.type";
import { injectFeedbackDataIntoSearchResponse } from "./search.injector";
import { SearchResponse, SearchResponseWithFeedback } from "./search.type";
/**
* call the api(including creating the request and intercept the response)
* then inject the feedback data in
*/
export async function lablebClientSearch(
this: LablebSDKContext,
searchOptions: SearchRequestParams
): Promise<LablebAPIResponseWrapper<SearchResponseWithFeedback>> {
return injectFeedbackDataIntoSearchResponse({
searchOptions,
searchResponse: await lablebClientNativeSearch.bind(this)(searchOptions),
globalOptions: this.globalOptions
});
}
/**
* use request builder to form the search request
* call any interceptor before doing the request
* call the api
*/
async function lablebClientNativeSearch(
this: LablebSDKContext,
searchOptions: SearchRequestParams
): Promise<LablebAPIResponseWrapper<SearchResponse>> {
const { url, headers, method, params } = await this.requestBuilder.search(searchOptions);
const interceptedRequestParams = ({
method,
url,
headers,
params: camelCaseToSnackCaseObject(params),
});
return await LablebHttpClient(interceptedRequestParams);
}