Repository navigation
[CDX-619] Align browse types with JS SDK #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ export interface BrowseParameters { | |
| hiddenFacets?: string[]; | ||
| variationsMap?: VariationsMap; | ||
| qsParam?: Record<string, any>; | ||
| filterMatchTypes?: Record<string, 'all' | 'any' | 'none'>; | ||
| } | ||
|
|
||
| declare class Browse { | ||
|
|
@@ -78,9 +79,9 @@ declare class Browse { | |
|
|
||
| /* Browse results returned from server */ | ||
| interface BrowseResponse<ResponseType> extends Record<string, any> { | ||
| request?: Partial<BrowseRequestType>; | ||
| response?: Partial<ResponseType>; | ||
| result_id?: string; | ||
| request: Partial<BrowseRequestType>; | ||
| response: Partial<ResponseType>; | ||
| result_id: string; | ||
| ad_based?: boolean; | ||
| } | ||
|
|
||
|
|
@@ -110,7 +111,9 @@ export interface GetBrowseResultsResponseData extends Record<string, any> { | |
| refined_content: Record<string, any>[]; | ||
| total_num_results: number; | ||
| features: Partial<Feature>[]; | ||
| collection: Partial<Collection>; | ||
| collection?: Partial<Collection>; | ||
| related_searches?: Record<string, any>[]; | ||
| related_browse_pages?: Record<string, any>[]; | ||
| } | ||
|
|
||
| export interface BrowseResultData extends Record<string, any> { | ||
|
|
@@ -122,23 +125,23 @@ export interface BrowseResultData extends Record<string, any> { | |
| value: string; | ||
| is_slotted: false; | ||
| labels: Record<string, any>; | ||
| variations: Record<string, any>[]; | ||
| variations_map: Record<string, any> | Record<string, any>[]; | ||
| variations?: Record<string, any>[]; | ||
| variations_map?: Record<string, any> | Record<string, any>[]; | ||
| } | ||
|
|
||
| export interface BrowseRequestType extends Record<string, any> { | ||
| browse_filter_name: string; | ||
| browse_filter_value: string; | ||
| filter_match_types: Record<string, any>; | ||
| filters: Record<string, any>; | ||
| filter_match_types?: Record<string, any>; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Important Issue: Suggested fix: filter_match_types?: Record<string, 'all' | 'any' | 'none'>; |
||
| filters?: Record<string, any>; | ||
| fmt_options: Record<string, any>; | ||
| num_results_per_page: number; | ||
| page: number; | ||
| section: string; | ||
| sort_by: string; | ||
| sort_order: string; | ||
| term: string; | ||
| query: string; | ||
| query?: string; | ||
| features: Partial<RequestFeature>; | ||
| feature_variants: Partial<RequestFeatureVariant>; | ||
| searchandized_items: Record<string, any>; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,10 @@ export * from './tasks'; | |
| export * from './tracker'; | ||
| export * from './searchandising'; | ||
|
|
||
| type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Important Issue: Also note the utility type is defined after the |
||
| Pick<T, Exclude<keyof T, Keys>> & | ||
| { [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>> }[Keys]; | ||
|
|
||
| export interface NetworkParameters extends Record<string, any> { | ||
| timeout?: number; | ||
| } | ||
|
|
@@ -148,16 +152,48 @@ export interface Variation extends Record<string, any> { | |
| data?: ItemData; | ||
| } | ||
|
|
||
| export interface VariationsMapSingleFilter { | ||
| field: string; | ||
| value: string | number | boolean; | ||
| } | ||
|
|
||
| export interface VariationsMapRange { | ||
| field: string; | ||
| range: FilterExpressionRangeValue; | ||
| } | ||
|
|
||
| export type FilterNode = VariationsMapSingleFilter | VariationsMapRange; | ||
|
|
||
| export type FilterBy = RequireAtLeastOne<{ | ||
| and?: Array<FilterNode | FilterBy>; | ||
| or?: Array<FilterNode | FilterBy>; | ||
| not?: FilterNode | FilterBy; | ||
| }>; | ||
|
|
||
| export type Aggregation = 'first' | 'min' | 'max' | 'all' | 'count' | 'field_count' | 'value_count'; | ||
|
|
||
| export interface VariationsMapBaseValue { | ||
| aggregation: Aggregation; | ||
| field: string; | ||
| } | ||
|
|
||
| export interface VariationsMapValueCount extends VariationsMapBaseValue { | ||
| aggregation: 'value_count'; | ||
| value: boolean | number | string; | ||
| } | ||
|
|
||
| export interface VariationsMapStandardValue extends VariationsMapBaseValue { | ||
| aggregation: Exclude<Aggregation, 'value_count'>; | ||
| } | ||
|
|
||
| export interface VariationsMap { | ||
| group_by: Array<{ | ||
| name: string, | ||
| field: string | ||
| }>; | ||
| filter_by?: FilterBy; | ||
| values: { | ||
| [key: string]: { | ||
| aggregation: 'first' | 'min' | 'max' | 'all', | ||
| field: string | ||
| }, | ||
| [key: string]: VariationsMapValueCount | VariationsMapStandardValue, | ||
| }, | ||
| dtype: 'array' | 'object' | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ export interface SearchParameters { | |
| hiddenFacets?: string[]; | ||
| variationsMap?: VariationsMap; | ||
| qsParam?: Record<string, any>; | ||
| filterMatchTypes?: Record<string, 'all' | 'any' | 'none'>; | ||
| } | ||
|
|
||
| declare class Search { | ||
|
|
@@ -68,6 +69,8 @@ export interface Response extends Record<string, any> { | |
| refined_content: Record<string, any>[]; | ||
| total_num_results: number; | ||
| features: Partial<Feature>[]; | ||
| related_searches?: Record<string, any>[]; | ||
| related_browse_pages?: Record<string, any>[]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: |
||
| } | ||
|
|
||
| export interface SearchRequestType extends Record<string, any> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| import { expectAssignable } from 'tsd'; | ||
| import { GetBrowseResultsResponse } from '../browse'; | ||
| import { expectAssignable, expectNotAssignable } from 'tsd'; | ||
| import { | ||
| BrowseParameters, | ||
| BrowseResultData, | ||
| GetBrowseResultsResponse, | ||
| } from '../browse'; | ||
|
|
||
| expectAssignable<GetBrowseResultsResponse>({ | ||
| response: { | ||
|
|
@@ -118,3 +122,34 @@ expectAssignable<GetBrowseResultsResponse>({ | |
| }, | ||
| ad_based: true, | ||
| }); | ||
|
|
||
| expectAssignable<BrowseParameters>({ | ||
| filters: { size: 'medium' }, | ||
| filterMatchTypes: { size: 'all' }, | ||
| }); | ||
|
|
||
| expectNotAssignable<BrowseParameters>({ | ||
| filterMatchTypes: { size: 'some' }, | ||
| }); | ||
|
|
||
| expectNotAssignable<GetBrowseResultsResponse>({ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The |
||
| request: {}, | ||
| response: { results: [] }, | ||
| }); | ||
|
|
||
| expectAssignable<GetBrowseResultsResponse>({ | ||
| request: {}, | ||
| response: { | ||
| related_searches: [{ term: 'dog toys' }], | ||
| related_browse_pages: [{ filter_name: 'group_id', filter_value: 'toys' }], | ||
| }, | ||
| result_id: 'e5941e13-f4ca-4efb-9326-893fd49b4e71', | ||
| }); | ||
|
|
||
| expectAssignable<BrowseResultData>({ | ||
| matched_terms: [], | ||
| data: { id: '123' }, | ||
| value: 'Name', | ||
| is_slotted: false, | ||
| labels: {}, | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The new integration tests for
filterMatchTypesuse promise.then()+donecallback style, which is the existing pattern in this file. However, these tests are missing rejection handling — if the promise rejects the test will time out rather than fail with a useful error message. The surrounding existing tests share this pattern, but since new tests are being added, consider adding a.catch(done)or switching toasync/awaitwithtry/catchto align with more modern patterns and provide better failure diagnostics: