@attraqt/search
Advanced tools
Comparing version 1.3.2 to 1.4.0
export * from './search'; | ||
export * from './suggest'; |
@@ -1,11 +0,10 @@ | ||
import { SearchOptions as SearchOptionsCommons, SearchRequest as SearchRequestCommons } from '@attraqt/search-commons'; | ||
/** | ||
* Search options. | ||
* | ||
* Every option is optional | ||
*/ | ||
export declare type SearchOptions = Partial<SearchOptionsCommons>; | ||
export declare type SearchRequest = Omit<SearchRequestCommons, 'options'> & { | ||
import { FacetRequestOptions as FacetRequestOptionsCommons, SearchOptions as SearchOptionsCommons, SearchRequest as SearchRequestCommons } from '@attraqt/search-commons'; | ||
declare type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; | ||
export declare type FacetRequestOptions = PartialBy<PartialBy<FacetRequestOptionsCommons, 'attribute'>, 'id'>; | ||
export declare type SearchOptions = Omit<Partial<SearchOptionsCommons>, 'facets'> & { | ||
facets?: FacetRequestOptions[]; | ||
}; | ||
export declare type SearchRequest = Omit<PartialBy<SearchRequestCommons, 'profileId'>, 'options'> & { | ||
options?: SearchOptions; | ||
}; | ||
export { DisableOptions, FacetRequestOptions, SortOptions, SearchResponseProduct, SearchResponseRedirectItem, SearchResponseItem, SearchResponseMetadata_Facet_Value, SearchResponseMetadata_Facet, SearchResponseMetadata, SearchResponse } from '@attraqt/search-commons'; | ||
export { DisableOptions, SortOptions, SearchResponseProduct, SearchResponseRedirectItem, SearchResponseItem, SearchResponseMetadata_Facet_Value, SearchResponseMetadata_Facet, SearchResponseMetadata, SearchResponse } from '@attraqt/search-commons'; |
import { HttpClient } from '@attraqt/http-client-common'; | ||
import { SearchOptions, SearchResponse } from './models'; | ||
import { ProductSuggestOptions, SearchOptions, SearchResponse } from './models'; | ||
/** | ||
@@ -7,3 +7,2 @@ * Search module. | ||
* Search for items using the xo-search API. | ||
* Supports pagination and faceting. | ||
*/ | ||
@@ -13,6 +12,7 @@ export declare class Search { | ||
private httpClient; | ||
private apiUrl; | ||
private token; | ||
init(options: SearchInitOptions, httpClient?: HttpClient): void; | ||
query(query: string, options?: SearchOptions, requestOptions?: SearchRequestOptions): Promise<SearchResponse>; | ||
suggest(query: string, options?: ProductSuggestOptions, requestOptions?: SearchRequestOptions): Promise<SearchResponse>; | ||
private sendRequest; | ||
private assertIsInit; | ||
@@ -19,0 +19,0 @@ } |
@@ -54,3 +54,4 @@ "use strict"; | ||
var http_client_common_1 = require("@attraqt/http-client-common"); | ||
var validateSchema_1 = __importDefault(require("./models/validateSchema")); | ||
var validateSearchOptionsSchema_1 = __importDefault(require("./models/validateSearchOptionsSchema")); | ||
var validateSuggestOptionsSchema_1 = __importDefault(require("./models/validateSuggestOptionsSchema")); | ||
/** | ||
@@ -60,3 +61,2 @@ * Search module. | ||
* Search for items using the xo-search API. | ||
* Supports pagination and faceting. | ||
*/ | ||
@@ -71,3 +71,2 @@ var Search = /** @class */ (function () { | ||
} | ||
this.apiUrl = 'https://api.early-birds.io/search'; | ||
this.token = options.token; | ||
@@ -79,2 +78,24 @@ this.httpClient = httpClient; | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
this.assertIsInit(); | ||
if (options && !validateSearchOptionsSchema_1.default(options)) { | ||
throw Error("The provided search options don't match the required format."); | ||
} | ||
return [2 /*return*/, this.sendRequest('/search', query, options, requestOptions)]; | ||
}); | ||
}); | ||
}; | ||
Search.prototype.suggest = function (query, options, requestOptions) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
this.assertIsInit(); | ||
if (options && !validateSuggestOptionsSchema_1.default(options)) { | ||
throw Error("The provided suggest options don't match the required format."); | ||
} | ||
return [2 /*return*/, this.sendRequest('/search/suggest', query, options, requestOptions)]; | ||
}); | ||
}); | ||
}; | ||
Search.prototype.sendRequest = function (path, query, options, requestOptions) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var request, response; | ||
@@ -84,7 +105,3 @@ return __generator(this, function (_a) { | ||
case 0: | ||
this.assertIsInit(); | ||
if (options && !validateSchema_1.default(options)) { | ||
throw Error("The provided search options don't match the required format."); | ||
} | ||
request = __assign({ method: http_client_common_1.Method.Post, headers: { 'Content-Type': 'application/json' }, url: this.apiUrl, body: JSON.stringify({ | ||
request = __assign({ method: http_client_common_1.Method.Post, headers: { 'Content-Type': 'application/json' }, url: "https://api-eu.attraqt.io" + path, body: JSON.stringify({ | ||
query: query, | ||
@@ -91,0 +108,0 @@ token: this.token, |
{ | ||
"name": "@attraqt/search", | ||
"version": "1.3.2", | ||
"version": "1.4.0", | ||
"license": "MIT", | ||
@@ -17,4 +17,8 @@ "repository": "git://github.com:Attraqt/attraqt-js.git", | ||
"scripts": { | ||
"generate-json-schemas": "typescript-json-schema ./src/models/search.ts SearchOptions --out ./src/models/search.schema.json --required --noExtraProps", | ||
"generate-validation": "ajv compile -s ./src/models/search.schema.json -o ./src/models/validateSchema.js --strict=true --all-errors --verbose --comment --code-es5 --allow-union-types", | ||
"generate-json-schemas-search": "typescript-json-schema ./src/models/search.ts SearchOptions --out ./src/models/search-options.schema.json --required --noExtraProps", | ||
"generate-json-schemas-suggest": "typescript-json-schema ./src/models/suggest.ts ProductSuggestOptions --out ./src/models/suggest-options.schema.json --required --noExtraProps", | ||
"generate-json-schemas": "npm run generate-json-schemas-search && npm run generate-json-schemas-suggest", | ||
"generate-validation-search": "ajv compile -s ./src/models/search-options.schema.json -o ./src/models/validateSearchOptionsSchema.js --strict=true --all-errors --verbose --comment --code-es5 --allow-union-types", | ||
"generate-validation-suggest": "ajv compile -s ./src/models/suggest-options.schema.json -o ./src/models/validateSuggestOptionsSchema.js --strict=true --all-errors --verbose --comment --code-es5 --allow-union-types", | ||
"generate-validation": "npm run generate-validation-search && npm run generate-validation-suggest", | ||
"copy-json-schemas": "cp ./src/models/*.schema.json ./dist/models", | ||
@@ -32,3 +36,3 @@ "build": "npm run generate-json-schemas && npm run generate-validation && npm run clean && npm run compile && npm run copy-json-schemas", | ||
"@attraqt/http-client-node": "^1.3.0", | ||
"@attraqt/search-commons": "^1.1.0" | ||
"@attraqt/search-commons": "^1.4.0" | ||
}, | ||
@@ -43,3 +47,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "c60984aca6a4c82266451dfc6164867a4bec12e2" | ||
"gitHead": "cd60ee30c760120ddff87f00d9068bb707343972" | ||
} |
@@ -18,3 +18,3 @@ # @attraqt/search | ||
const response = await search.query('T-Shirt', { | ||
const searchResponse = await search.query('T-Shirt', { | ||
offset: 10, | ||
@@ -25,4 +25,16 @@ limit: 30, | ||
console.log(response.items); | ||
console.log(response.metadata); | ||
console.log(searchResponse.items); | ||
console.log(searchResponse.metadata); | ||
const suggestResponse = await xo.search.suggest('T-Shirt', { | ||
filter: 'price < 50', | ||
groupBy: { | ||
attribute: 'kind', | ||
count: 10, | ||
values: ['product', 'shops', 'ads'] | ||
} | ||
}); | ||
console.log(suggestResponse.items); | ||
console.log(suggestResponse.metadata); | ||
``` | ||
@@ -32,6 +44,7 @@ | ||
| Method | Argument(s) | Result | Description | | ||
| ------ | ---------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- | ----------------------------- | | ||
| init | options: [`SearchInitOptions`](src/search.ts) | `void` | Initializes the search client | | ||
| query | query: `string`, options?: [`SearchOptions`](src/models/search.ts), requestOptions?: [`SearchRequestOptions`](src/search.ts) | [`Promise<SearchResponse>`](src/models/search.ts) | Searches for items | | ||
| Method | Argument(s) | Result | Description | | ||
| ------- | ------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- | -------------------------------------- | | ||
| init | options: [`SearchInitOptions`](src/search.ts) | `void` | Initializes the search client | | ||
| query | query: `string`, options?: [`SearchOptions`](src/models/search.ts), requestOptions?: [`SearchRequestOptions`](src/search.ts) | [`Promise<SearchResponse>`](src/models/search.ts) | Searches for items | | ||
| suggest | query: `string`, options?: [`ProductSuggestOptions`](src/models/suggest.ts), requestOptions?: [`SearchRequestOptions`](src/search.ts) | [`Promise<ProductSuggestResponse>`](src/models/suggest.ts) | Suggest and group a selection of items | | ||
@@ -51,1 +64,12 @@ ## Search options | ||
| `disable` | `DisableOptions[]` | Features to disable for this query | | ||
## Suggest options | ||
All options are optional. | ||
| Option | Type | Description | | ||
| -------------------- | --------------- | -------------------------------------------------------------------------- | | ||
| `filter` | `string` | Filter query string | | ||
| `sortBy` | `SortOptions[]` | Sort options, evaluated in order of appearance | | ||
| `customResponseMask` | `string` | Custom response mask. Allows to fetch only specific field from the catalog | | ||
| `groupBy` | `GroupOptions` | Group result by an attribute and its specified values | |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
100593
32
1133
72
1