diff --git a/packages/client/package.json b/packages/client/package.json index d7fd710..82c0db1 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,6 +1,6 @@ { "name": "@relewise/client", - "version": "2.4.0", + "version": "2.5.0-alpha.1", "description": "Relewise is a next generation personalization SaaS-platform, which offers functionality within product- and content recommendations and personalized search. This official SDK helps you interact with our API.", "repository": { "type": "git", @@ -32,7 +32,7 @@ "prebuild:types": "rimraf ./build", "build:types": "tsc -p ./tsconfig.json --outDir build --declaration true && api-extractor run", "clean": "rimraf ./build ./dist ./docs", - "gen-api": "swagger-typescript-api -p https://api.relewise.com/public/swagger.json -o src/models --modular --no-client --enum-names-as-values && node fix-exports.js", + "gen-api": "swagger-typescript-api -p https://stage01-api.relewise.com/public/swagger.json -o src/models --modular --no-client --enum-names-as-values && node fix-exports.js", "gen-api-dev": "swagger-typescript-api -p swagger.json -o src/models --modular --no-client --enum-names-as-values && node fix-exports.js", "publish": "npm run gen-api && npm run build && npm run build:types" }, diff --git a/packages/client/src/builders/search/contentHighlightingBuilder.ts b/packages/client/src/builders/search/contentHighlightingBuilder.ts index 0af95ae..8854aab 100644 --- a/packages/client/src/builders/search/contentHighlightingBuilder.ts +++ b/packages/client/src/builders/search/contentHighlightingBuilder.ts @@ -1,4 +1,4 @@ -import { ContentHighlightProps, ContentSearchSettingsHighlightSettings, HighlightSettings2ContentContentHighlightPropsHighlightSettings2Limits, HighlightSettings2ContentContentHighlightPropsHighlightSettings2ResponseShape, HighlightSettings2ContentContentHighlightPropsHighlightSettings2TextSnippetsSettings } from '../../models/data-contracts'; +import { ContentHighlightProps, ContentSearchSettingsHighlightSettings, HighlightSettings2ContentContentHighlightPropsHighlightSettings2Limits, HighlightSettings2ContentContentHighlightPropsHighlightSettings2ResponseShape } from '../../models/data-contracts'; export class ContentHighlightingBuilder { private enabledState: boolean = true; @@ -7,9 +7,7 @@ export class ContentHighlightingBuilder { displayName: false }; private limit: HighlightSettings2ContentContentHighlightPropsHighlightSettings2Limits = {}; - private shape: HighlightSettings2ContentContentHighlightPropsHighlightSettings2ResponseShape = { - includeOffsets: false - }; + private shape: HighlightSettings2ContentContentHighlightPropsHighlightSettings2ResponseShape = { }; public enabled(enabled: boolean): this { this.enabledState = enabled; @@ -30,9 +28,8 @@ export class ContentHighlightingBuilder { return this; } - public setShape(shape: { includeOffsets: boolean, textSnippets?: HighlightSettings2ContentContentHighlightPropsHighlightSettings2TextSnippetsSettings }): this { - this.shape.includeOffsets = shape.includeOffsets; - this.shape.textSnippets = shape.textSnippets; + public setShape(shape: HighlightSettings2ContentContentHighlightPropsHighlightSettings2ResponseShape): this { + this.shape = shape; return this; } diff --git a/packages/client/src/builders/search/productHighlightingBuilder.ts b/packages/client/src/builders/search/productHighlightingBuilder.ts index 3d017cb..1f1205a 100644 --- a/packages/client/src/builders/search/productHighlightingBuilder.ts +++ b/packages/client/src/builders/search/productHighlightingBuilder.ts @@ -1,4 +1,4 @@ -import { HighlightSettings2ProductProductHighlightPropsHighlightSettings2Limits, HighlightSettings2ProductProductHighlightPropsHighlightSettings2ResponseShape, HighlightSettings2ProductProductHighlightPropsHighlightSettings2TextSnippetsSettings, ProductHighlightProps, ProductSearchSettingsHighlightSettings } from '../../models/data-contracts'; +import { HighlightSettings2ProductProductHighlightPropsHighlightSettings2Limits, HighlightSettings2ProductProductHighlightPropsHighlightSettings2ResponseShape, ProductHighlightProps, ProductSearchSettingsHighlightSettings } from '../../models/data-contracts'; export class ProductHighlightingBuilder { private enabledState: boolean = true; @@ -8,7 +8,6 @@ export class ProductHighlightingBuilder { }; private limit: HighlightSettings2ProductProductHighlightPropsHighlightSettings2Limits = {}; private shape: HighlightSettings2ProductProductHighlightPropsHighlightSettings2ResponseShape = { - includeOffsets: false }; public enabled(enabled: boolean): this { @@ -30,9 +29,8 @@ export class ProductHighlightingBuilder { return this; } - public setShape(shape: { includeOffsets: boolean, textSnippets?: HighlightSettings2ProductProductHighlightPropsHighlightSettings2TextSnippetsSettings }): this { - this.shape.includeOffsets = shape.includeOffsets; - this.shape.textSnippets = shape.textSnippets; + public setShape(shape: HighlightSettings2ProductProductHighlightPropsHighlightSettings2ResponseShape): this { + this.shape = shape; return this; } diff --git a/packages/client/src/models/data-contracts.ts b/packages/client/src/models/data-contracts.ts index 8dafd3f..6bf5d20 100644 --- a/packages/client/src/models/data-contracts.ts +++ b/packages/client/src/models/data-contracts.ts @@ -423,7 +423,7 @@ export type BrandFacet = StringValueFacet; export type BrandFacetResult = StringBrandNameAndIdResultValueFacetResult; export type BrandIdFilter = Filter & { - brandIds: string[]; + brandIds?: string[] | null; }; export type BrandIdRelevanceModifier = RelevanceModifier & { @@ -2357,8 +2357,22 @@ export interface HighlightResultOffset { } export interface HighlightResultSnippet { - displayName: string[]; - data: StringStringArrayKeyValuePair[]; + displayName: HighlightResultSnippetDisplayNameSnippetMatch[]; + data: StringFieldSnippetMatchArrayKeyValuePair[]; +} + +export type HighlightResultSnippetDisplayNameSnippetMatch = HighlightResultSnippetSnippetMatch; + +export type HighlightResultSnippetFieldSnippetMatch = HighlightResultSnippetSnippetMatch; + +export interface HighlightResultSnippetMatchMatchedWord { + offset?: Int32Range | null; +} + +export interface HighlightResultSnippetSnippetMatch { + $type: string; + text: string; + matchedWords?: HighlightResultSnippetMatchMatchedWord[] | null; } export interface HighlightSettings2ContentContentHighlightPropsHighlightSettings2Limits { @@ -2378,14 +2392,19 @@ export interface HighlightSettings2ContentContentHighlightPropsHighlightSettings maxSentencesToIncludeAfterMatch?: number | null; } +export interface HighlightSettings2ContentContentHighlightPropsHighlightSettings2OffsetSettings { + include: boolean; +} + export interface HighlightSettings2ContentContentHighlightPropsHighlightSettings2ResponseShape { - includeOffsets: boolean; - textSnippets?: HighlightSettings2ContentContentHighlightPropsHighlightSettings2TextSnippetsSettings | null; + offsets?: HighlightSettings2ContentContentHighlightPropsHighlightSettings2OffsetSettings | null; + snippets?: HighlightSettings2ContentContentHighlightPropsHighlightSettings2SnippetsSettings | null; } -export interface HighlightSettings2ContentContentHighlightPropsHighlightSettings2TextSnippetsSettings { - includeTextSnippets: boolean; - includeEllipses: boolean; +export interface HighlightSettings2ContentContentHighlightPropsHighlightSettings2SnippetsSettings { + include: boolean; + useEllipses: boolean; + includeMatchedWords: boolean; } export interface HighlightSettings2ProductProductHighlightPropsHighlightSettings2Limits { @@ -2405,14 +2424,19 @@ export interface HighlightSettings2ProductProductHighlightPropsHighlightSettings maxSentencesToIncludeAfterMatch?: number | null; } +export interface HighlightSettings2ProductProductHighlightPropsHighlightSettings2OffsetSettings { + include: boolean; +} + export interface HighlightSettings2ProductProductHighlightPropsHighlightSettings2ResponseShape { - includeOffsets: boolean; - textSnippets?: HighlightSettings2ProductProductHighlightPropsHighlightSettings2TextSnippetsSettings | null; + offsets?: HighlightSettings2ProductProductHighlightPropsHighlightSettings2OffsetSettings | null; + snippets?: HighlightSettings2ProductProductHighlightPropsHighlightSettings2SnippetsSettings | null; } -export interface HighlightSettings2ProductProductHighlightPropsHighlightSettings2TextSnippetsSettings { - includeTextSnippets: boolean; - includeEllipses: boolean; +export interface HighlightSettings2ProductProductHighlightPropsHighlightSettings2SnippetsSettings { + include: boolean; + useEllipses: boolean; + includeMatchedWords: boolean; } export type HtmlParser = Parser; @@ -5324,6 +5348,11 @@ export interface StringDataObjectValueFacetResult { field: "Category" | "Assortment" | "ListPrice" | "SalesPrice" | "Brand" | "Data" | "VariantSpecification" | "User"; } +export interface StringFieldSnippetMatchArrayKeyValuePair { + key: string; + value: HighlightResultSnippetFieldSnippetMatch[]; +} + export interface StringProductCategoryDataValueFacet { $type: string; key: string; @@ -5367,11 +5396,6 @@ export interface StringRange1ArrayKeyValuePair { value: Int32Range[]; } -export interface StringStringArrayKeyValuePair { - key: string; - value: string[]; -} - export interface StringStringKeyValuePair { key: string; value: string; diff --git a/packages/client/tests/integration-tests/contentSearch.integration.test.ts b/packages/client/tests/integration-tests/contentSearch.integration.test.ts index 0cfcc3a..da364e1 100644 --- a/packages/client/tests/integration-tests/contentSearch.integration.test.ts +++ b/packages/client/tests/integration-tests/contentSearch.integration.test.ts @@ -45,11 +45,14 @@ test('Highlighting', async() => { h.setLimit({ maxWordsBeforeMatch: 3 }) // You have to specify to include the offset. // Currently offset is the only way to get a result, so if not set, you won't get a result. - h.setShape({ includeOffsets: true, textSnippets: { includeTextSnippets: true, includeEllipses: true } }) + h.setShape({ + offsets: { include: true }, + snippets: { include: true, includeMatchedWords: true, useEllipses: true } + }) }).build(); const result = await searcher.searchContents(request); expect(result?.results![0].highlight?.offsets?.data[0].value.length).toBeGreaterThan(0); - expect(result?.results![0].highlight?.snippets?.data[0].value[0]).toBe("...word should be highlighted"); + expect(result?.results![0].highlight?.snippets?.data[0].value[0].text).toBe("...word should be highlighted"); }) \ No newline at end of file diff --git a/packages/client/tests/integration-tests/productSearch.integration.test.ts b/packages/client/tests/integration-tests/productSearch.integration.test.ts index c2ce34c..853621c 100644 --- a/packages/client/tests/integration-tests/productSearch.integration.test.ts +++ b/packages/client/tests/integration-tests/productSearch.integration.test.ts @@ -102,10 +102,13 @@ test('Highlighting', async() => { h.setHighlightable({ dataKeys: ['SomeString'] }) // You have to specify to include the offset. // Currently offset is the only way to get a result, so if not set, you won't get a result. - h.setShape({ includeOffsets: true, textSnippets: { includeTextSnippets: true, includeEllipses: true } }) + h.setShape({ + offsets: { include: true }, + snippets: { include: true, includeMatchedWords: true, useEllipses: true } + }) }).build(); const result = await searcher.searchProducts(request); expect(result?.results![0].highlight?.offsets?.data[0].value.length).toBeGreaterThan(0); - expect(result?.results![0].highlight?.snippets?.data[0].value[0]).toBe("SomeValue"); + expect(result?.results![0].highlight?.snippets?.data[0].value[0].text).toBe("SomeValue"); }) diff --git a/packages/client/tests/unit-tests/builders/search/contentSearchBuilder.unit.test.ts b/packages/client/tests/unit-tests/builders/search/contentSearchBuilder.unit.test.ts index baca30a..77e5107 100644 --- a/packages/client/tests/unit-tests/builders/search/contentSearchBuilder.unit.test.ts +++ b/packages/client/tests/unit-tests/builders/search/contentSearchBuilder.unit.test.ts @@ -26,11 +26,8 @@ test('searchHightlighting', () => { maxSnippetsPerField: 3 }); h.setShape({ - includeOffsets: true, - textSnippets: { - includeEllipses: true, - includeTextSnippets: true - } + offsets: { include: true }, + snippets: { include: true, includeMatchedWords: true, useEllipses: true } }); }).build(); @@ -41,6 +38,6 @@ test('searchHightlighting', () => { expect(subject.settings?.highlight?.limit.maxEntryLimit).toBe(1); expect(subject.settings?.highlight?.limit.maxSnippetsPerEntry).toBe(2); expect(subject.settings?.highlight?.limit.maxSnippetsPerField).toBe(3); - expect(subject.settings?.highlight?.shape.includeOffsets).toBe(true); - expect(subject.settings?.highlight?.shape.textSnippets?.includeTextSnippets).toBe(true); + expect(subject.settings?.highlight?.shape.offsets?.include).toBe(true); + expect(subject.settings?.highlight?.shape.snippets?.include).toBe(true); }); \ No newline at end of file diff --git a/packages/client/tests/unit-tests/builders/search/productSearchBuilder.unit.test.ts b/packages/client/tests/unit-tests/builders/search/productSearchBuilder.unit.test.ts index ae8fd93..0662ec6 100644 --- a/packages/client/tests/unit-tests/builders/search/productSearchBuilder.unit.test.ts +++ b/packages/client/tests/unit-tests/builders/search/productSearchBuilder.unit.test.ts @@ -120,11 +120,8 @@ test('searchHightlighting', () => { maxSnippetsPerField: 3 }); h.setShape({ - includeOffsets: true, - textSnippets: { - includeEllipses: true, - includeTextSnippets: true, - } + offsets: { include: true }, + snippets: { include: true, includeMatchedWords: true, useEllipses: true } }); }).build(); @@ -135,8 +132,8 @@ test('searchHightlighting', () => { expect(subject.settings?.highlight?.limit.maxEntryLimit).toBe(1); expect(subject.settings?.highlight?.limit.maxSnippetsPerEntry).toBe(2); expect(subject.settings?.highlight?.limit.maxSnippetsPerField).toBe(3); - expect(subject.settings?.highlight?.shape.includeOffsets).toBe(true); - expect(subject.settings?.highlight?.shape.textSnippets?.includeTextSnippets).toBe(true); + expect(subject.settings?.highlight?.shape.offsets?.include).toBe(true); + expect(subject.settings?.highlight?.shape.snippets?.include).toBe(true); }); test('includeDisabled in ProductHasVariantsFilter', () => {