Skip to content

Commit f94ce64

Browse files
authored
fix(recommend): update recommended-for-you model type (#1500)
* fix(recommend): update recommended-for-you model type * fix RecommendedForYouQuery by removing model * simplify getRecommendations * RecommendedForYouParams
1 parent 5a2a128 commit f94ce64

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

packages/recommend/src/methods/getRecommendations.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import {
44
BaseRecommendClient,
55
RecommendationsQuery,
66
RecommendedForYouQuery,
7+
TrendingQuery,
78
WithRecommendMethods,
89
} from '../types';
9-
import { TrendingQuery } from '../types/TrendingQuery';
1010

1111
type GetRecommendations = (
1212
base: BaseRecommendClient
1313
) => WithRecommendMethods<BaseRecommendClient>['getRecommendations'];
1414

1515
export const getRecommendations: GetRecommendations = base => {
16-
return (queries: ReadonlyArray<RecommendationsQuery | TrendingQuery>, requestOptions) => {
16+
return (queries, requestOptions) => {
1717
const requests: ReadonlyArray<
1818
RecommendationsQuery | TrendingQuery | RecommendedForYouQuery
1919
> = queries.map(query => ({

packages/recommend/src/methods/getRecommendedForYou.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { MethodEnum } from '@algolia/requester-common';
22

3-
import { BaseRecommendClient, RecommendedForYouQuery, WithRecommendMethods } from '../types';
3+
import {
4+
BaseRecommendClient,
5+
RecommendedForYouParams,
6+
RecommendedForYouQuery,
7+
WithRecommendMethods,
8+
} from '../types';
49

510
type GetRecommendedForYou = (
611
base: BaseRecommendClient
712
) => WithRecommendMethods<BaseRecommendClient>['getRecommendedForYou'];
813

914
export const getRecommendedForYou: GetRecommendedForYou = base => {
10-
return (queries: readonly RecommendedForYouQuery[], requestOptions) => {
15+
return (queries: readonly RecommendedForYouParams[], requestOptions) => {
1116
const requests: readonly RecommendedForYouQuery[] = queries.map(query => ({
1217
...query,
1318
model: 'recommended-for-you',

packages/recommend/src/types/RecommendationsQuery.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { RecommendModel } from './RecommendModel';
21
import { RecommendSearchOptions } from './RecommendSearchOptions';
32

43
export type RecommendationsQuery = {
@@ -10,7 +9,7 @@ export type RecommendationsQuery = {
109
/**
1110
* The name of the Recommendation model to use.
1211
*/
13-
readonly model: RecommendModel;
12+
readonly model: 'related-products' | 'bought-together' | 'looking-similar';
1413

1514
/**
1615
* The `objectID` of the item to get recommendations for.

packages/recommend/src/types/RecommendedForYouQuery.ts

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type RecommendedForYouQuery = Omit<
55
RecommendationsQuery,
66
'model' | 'objectID' | '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
*/
@@ -17,3 +18,8 @@ export type RecommendedForYouQuery = Omit<
1718
readonly userToken: string;
1819
};
1920
};
21+
22+
/**
23+
* The parameters used for `getRecommendedForYou` method.
24+
*/
25+
export type RecommendedForYouParams = Omit<RecommendedForYouQuery, 'model'>;

packages/recommend/src/types/WithRecommendMethods.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SearchOptions, SearchResponse } from '@algolia/client-search';
22
import { RequestOptions } from '@algolia/transporter';
33

4-
import { RecommendedForYouQuery } from '../builds/node';
4+
import { RecommendedForYouParams, RecommendedForYouQuery } from '../builds/node';
55
import { FrequentlyBoughtTogetherQuery } from './FrequentlyBoughtTogetherQuery';
66
import { LookingSimilarQuery } from './LookingSimilarQuery';
77
import { RecommendationsQuery } from './RecommendationsQuery';
@@ -30,7 +30,7 @@ export type WithRecommendMethods<TType> = TType & {
3030
* Returns recommendations.
3131
*/
3232
readonly getRecommendations: <TObject>(
33-
queries: ReadonlyArray<RecommendationsQuery | TrendingQuery>,
33+
queries: ReadonlyArray<RecommendationsQuery | TrendingQuery | RecommendedForYouQuery>,
3434
requestOptions?: RequestOptions & SearchOptions
3535
) => Readonly<Promise<RecommendQueriesResponse<TObject>>>;
3636

@@ -78,7 +78,7 @@ export type WithRecommendMethods<TType> = TType & {
7878
* Returns Recommended for you
7979
*/
8080
readonly getRecommendedForYou: <TObject>(
81-
queries: readonly RecommendedForYouQuery[],
81+
queries: readonly RecommendedForYouParams[],
8282
requestOptions?: RequestOptions & SearchOptions
8383
) => Readonly<Promise<RecommendQueriesResponse<TObject>>>;
8484
};

0 commit comments

Comments
 (0)