@sociate/sociate-api-sdk
Version:
Javascript client for Sociate AI APIs
51 lines (50 loc) • 1.81 kB
JavaScript
export class SearchAPI {
httpClient;
constructor(httpClient) {
this.httpClient = httpClient;
}
/**
* Performs a basic search using the provided parameters.
* @param params - The parameters for the basic search.
* @returns A promise that resolves to the search results.
*/
async basic(params) {
return await this.httpClient.post('/search', params);
}
/**
* Performs an advanced search using the provided parameters.
* @param params - The parameters for the advanced search.
* @returns A promise that resolves to the search results.
*/
async advanced(params) {
return await this.httpClient.post('/search/advanced', params);
}
/**
* Searches for products by image.
*
* @param {SearchCategoryProductRequest} params - The parameters for the search.
* @param {File} params.image - The image file to search with.
* @param {string} params.style - The style to filter the search results.
* @returns The search results.
*/
async searchByImage(params) {
const formData = new FormData();
formData.append('image', params.image);
const body = {
image: formData,
style: params.style,
};
// TODO - Test this method using form-data
return await this.httpClient.post('/search/by-image', body);
}
/**
* Executes a search request with the provided parameters.
*
* @param {SearchRequest} params - The search parameters to be used in the request.
* @returns A promise that resolves to the search product response.
*/
async get(params) {
const queryParams = new URLSearchParams(params).toString();
return await this.httpClient.get(`/v2/search?${queryParams}`);
}
}