Skip to content

Commit 3a96ede

Browse files
author
Jonas Berlin
committed
Fix browse types based on empirical testing
1 parent 5ec0ea7 commit 3a96ede

File tree

2 files changed

+63
-33
lines changed

2 files changed

+63
-33
lines changed

src/types/browse.d.ts

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
BrowseFacet,
23
Collection,
34
ConstructorClientOptions,
45
Facet,
@@ -31,7 +32,7 @@ export interface IBrowseParameters {
3132
hiddenFacets?: string[];
3233
variationsMap?: VariationsMap;
3334
qsParam?: Record<string, any>;
34-
filterMatchTypes?: Record<string, 'all'| 'any' | 'none'>
35+
filterMatchTypes?: Record<string, 'all' | 'any' | 'none'>;
3536
}
3637

3738
declare class Browse {
@@ -77,40 +78,52 @@ declare class Browse {
7778
/** *********
7879
* Browse results returned from server
7980
********** */
80-
export interface BrowseResponse<ResponseType> extends Record<string, any> {
81-
request?: Partial<BrowseRequestType>;
82-
response?: Partial<ResponseType>;
83-
result_id?: string;
81+
export interface BrowseResponse<ResponseType, OmittedRequestFields extends keyof BrowseRequestType>
82+
extends Record<string, any> {
83+
84+
request: Omit<BrowseRequestType, OmittedRequestFields>;
85+
response: ResponseType;
86+
result_id: string;
8487
ad_based?: boolean;
8588
}
8689

8790
export type GetBrowseResultsResponse =
88-
BrowseResponse<GetBrowseResultsResponseData>;
91+
BrowseResponse<GetBrowseResultsResponseData, 'facet_name'>;
8992
export type GetBrowseResultsForItemIdsResponse =
90-
BrowseResponse<GetBrowseResultsResponseData>;
93+
BrowseResponse<GetBrowseResultsResponseData, 'facet_name'>;
9194
export type GetBrowseGroupsResponse = BrowseResponse<
9295
Pick<
9396
GetBrowseResultsResponseData,
9497
'result_sources' | 'groups' | 'refined_content'
95-
>
98+
>,
99+
'browse_filter_name' | 'browse_filter_value' | 'searchandized_items' | 'facet_name'
96100
>;
97101
export type GetBrowseFacetsResponse = BrowseResponse<
98-
Pick<GetBrowseResultsResponseData, 'facets' | 'total_num_results'>
102+
GetBrowseFacetsResultsResponseData,
103+
'browse_filter_name' | 'browse_filter_value' | 'searchandized_items' | 'facet_name'
99104
>;
100105
export type GetBrowseFacetOptionsResponse = BrowseResponse<
101-
Pick<GetBrowseResultsResponseData, 'facets'>
106+
Pick<GetBrowseResultsResponseData, 'facets' | 'total_num_results'>,
107+
'browse_filter_name' | 'browse_filter_value' | 'searchandized_items'
102108
>;
103109

104110
export interface GetBrowseResultsResponseData extends Record<string, any> {
105-
result_sources: Partial<ResultSources>;
106-
facets: Partial<Facet>[];
107-
groups: Partial<Group>[];
108-
results: Partial<BrowseResultData>[];
109-
sort_options: Partial<SortOption>[];
111+
result_sources: ResultSources;
112+
facets: Facet[];
113+
groups: Group[];
114+
results: BrowseResultData[];
115+
sort_options: SortOption[];
110116
refined_content: Record<string, any>[];
111117
total_num_results: number;
112-
features: Partial<Feature>[];
113-
collection: Partial<Collection>;
118+
features: Feature[];
119+
collection?: Partial<Collection>;
120+
related_searches: Record<string, any>[];
121+
related_browse_pages: Record<string, any>[];
122+
}
123+
124+
export interface GetBrowseFacetsResultsResponseData extends Record<string, any> {
125+
facets: BrowseFacet[];
126+
total_num_results: number;
114127
}
115128

116129
export interface BrowseResultData extends Record<string, any> {
@@ -122,23 +135,24 @@ export interface BrowseResultData extends Record<string, any> {
122135
value: string;
123136
is_slotted: false;
124137
labels: Record<string, any>;
125-
variations: Record<string, any>[];
126-
variations_map: Record<string, any> | Record<string, any>[];
138+
variations?: Record<string, any>[];
139+
variations_map?: Record<string, any> | Record<string, any>[];
127140
}
128141

129142
export interface BrowseRequestType extends Record<string, any> {
130143
browse_filter_name: string;
131144
browse_filter_value: string;
132-
filter_match_types: Record<string, any>;
133-
filters: Record<string, any>;
134-
fmt_options: Record<string, any>;
145+
filter_match_types?: Record<string, any>;
146+
filters?: Record<string, any>;
147+
fmt_options: FmtOptions;
148+
facet_name: string;
135149
num_results_per_page: number;
136150
page: number;
137151
section: string;
138152
sort_by: string;
139153
sort_order: string;
140154
term: string;
141-
query: string;
155+
query?: string;
142156
features: Partial<RequestFeature>;
143157
feature_variants: Partial<RequestFeatureVariant>;
144158
searchandized_items: Record<string, any>;

src/types/index.d.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export interface SortOption extends Record<string, any> {
9494
display_name: string;
9595
sort_order: string;
9696
status: string;
97+
hidden: boolean;
9798
}
9899

99100
export interface Feature extends Record<string, any> {
@@ -107,44 +108,59 @@ export interface Feature extends Record<string, any> {
107108
} | null;
108109
}
109110

110-
export type Facet = RangeFacet | OptionFacet;
111+
export type Facet = RangeFacet | OptionFacet | HierarchialOptionFacet;
112+
113+
export type BrowseFacet = Pick<Facet, keyof BaseFacet | 'type'>;
111114

112115
export interface BaseFacet extends Record<string, any> {
113116
data: Record<string, any>;
114-
status: Record<string, any>;
115117
display_name: string;
116118
name: string;
117119
hidden: boolean;
118120
}
119121

120122
export interface RangeFacet extends BaseFacet, Record<string, any> {
121-
max: number;
122-
min: number;
123+
status?: { min: RangeMin, max: RangeMax };
124+
max: RangeMax;
125+
min: RangeMin;
123126
type: 'range';
124127
}
125128

126129
export interface OptionFacet extends BaseFacet, Record<string, any> {
127130
options: FacetOption[];
128-
type: 'multiple' | 'single' | 'hierarchical';
131+
type: 'multiple' | 'single';
132+
}
133+
134+
export interface HierarchialOptionFacet extends BaseFacet, Record<string, any> {
135+
options: HierarchialFacetOption[];
136+
type: 'hierarchical';
129137
}
130138

131139
export interface FacetOption extends Record<string, any> {
132140
count: number;
133141
display_name: string;
134142
value: string;
135-
options?: FacetOption[];
136-
range?: ['-inf' | number, 'inf' | number];
143+
range?: [RangeMin, RangeMax];
137144
status: string;
145+
data: Record<string, any>;
138146
}
139147

148+
export interface HierarchialFacetOption extends FacetOption {
149+
options?: HierarchialFacetOption[];
150+
}
151+
152+
export type RangeMin = '-inf' | number;
153+
export type RangeMax = '+inf' | 'inf' | number
154+
140155
export interface Group extends BaseGroup, Record<string, any> {
141-
count?: number;
156+
count: number;
142157
data?: Record<string, any>;
143-
parents?: BaseGroup[];
144-
children?: Group[];
158+
parents: BaseGroup[];
159+
children: Group[];
145160
}
146161

147162
export interface Collection extends Record<string, any> {
163+
// documentation says this field is called `id`
148164
collection_id: string;
149165
display_name: string;
150166
data: Record<string, any>;

0 commit comments

Comments
 (0)