Skip to content

Commit 3ef82e9

Browse files
committed
fix(recommend): update recommended-for-you model type
1 parent 5a2a128 commit 3ef82e9

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

packages/recommend/src/methods/getRecommendations.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { MethodEnum } from '@algolia/requester-common';
33
import {
44
BaseRecommendClient,
55
RecommendationsQuery,
6-
RecommendedForYouQuery,
6+
RecommendationsQueryWithoutObjectID,
77
WithRecommendMethods,
88
} from '../types';
99
import { TrendingQuery } from '../types/TrendingQuery';
@@ -13,9 +13,14 @@ type GetRecommendations = (
1313
) => WithRecommendMethods<BaseRecommendClient>['getRecommendations'];
1414

1515
export const getRecommendations: GetRecommendations = base => {
16-
return (queries: ReadonlyArray<RecommendationsQuery | TrendingQuery>, requestOptions) => {
16+
return (
17+
queries: ReadonlyArray<
18+
RecommendationsQuery | TrendingQuery | RecommendationsQueryWithoutObjectID
19+
>,
20+
requestOptions
21+
) => {
1722
const requests: ReadonlyArray<
18-
RecommendationsQuery | TrendingQuery | RecommendedForYouQuery
23+
RecommendationsQuery | TrendingQuery | RecommendationsQueryWithoutObjectID
1924
> = queries.map(query => ({
2025
...query,
2126
// The `threshold` param is required by the endpoint to make it easier

packages/recommend/src/types/RecommendationsQuery.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,18 @@ export type RecommendationsQuery = {
3939
*/
4040
readonly fallbackParameters?: RecommendSearchOptions;
4141
};
42+
43+
/**
44+
* Base type for models that don't require an `objectID`.
45+
*
46+
* Currently the only model that doesn't require an `objectID` is `recommended-for-you`.
47+
*/
48+
export type RecommendationsQueryWithoutObjectID = Omit<
49+
RecommendationsQuery,
50+
'objectID' | 'model'
51+
> & {
52+
/**
53+
* The name of the Recommendation model to use.
54+
*/
55+
readonly model: 'recommended-for-you';
56+
};

packages/recommend/src/types/RecommendedForYouQuery.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { RecommendationsQuery } from './RecommendationsQuery';
1+
import { RecommendationsQueryWithoutObjectID } from './RecommendationsQuery';
22
import { RecommendSearchOptions } from './RecommendSearchOptions';
33

44
export type RecommendedForYouQuery = Omit<
5-
RecommendationsQuery,
6-
'model' | 'objectID' | 'queryParameters'
5+
RecommendationsQueryWithoutObjectID,
6+
'model' | 'queryParameters'
77
> & {
8+
readonly model: 'recommended-for-you';
89
/**
910
* List of [search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/) to send.
1011
*/

packages/recommend/src/types/WithRecommendMethods.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { RequestOptions } from '@algolia/transporter';
44
import { RecommendedForYouQuery } from '../builds/node';
55
import { FrequentlyBoughtTogetherQuery } from './FrequentlyBoughtTogetherQuery';
66
import { LookingSimilarQuery } from './LookingSimilarQuery';
7-
import { RecommendationsQuery } from './RecommendationsQuery';
7+
import { RecommendationsQuery, RecommendationsQueryWithoutObjectID } from './RecommendationsQuery';
88
import { RelatedProductsQuery } from './RelatedProductsQuery';
99
import { TrendingFacetsQuery } from './TrendingFacetsQuery';
1010
import { TrendingFacetsResponse } from './TrendingFacetsResponse';
@@ -30,7 +30,9 @@ export type WithRecommendMethods<TType> = TType & {
3030
* Returns recommendations.
3131
*/
3232
readonly getRecommendations: <TObject>(
33-
queries: ReadonlyArray<RecommendationsQuery | TrendingQuery>,
33+
queries: ReadonlyArray<
34+
RecommendationsQuery | TrendingQuery | RecommendationsQueryWithoutObjectID
35+
>,
3436
requestOptions?: RequestOptions & SearchOptions
3537
) => Readonly<Promise<RecommendQueriesResponse<TObject>>>;
3638

0 commit comments

Comments
 (0)