Skip to content

fix(recommend): update recommended-for-you model type #1500

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

Merged
merged 4 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/recommend/src/methods/getRecommendations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import {
BaseRecommendClient,
RecommendationsQuery,
RecommendedForYouQuery,
TrendingQuery,
WithRecommendMethods,
} from '../types';
import { TrendingQuery } from '../types/TrendingQuery';

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

export const getRecommendations: GetRecommendations = base => {
return (queries: ReadonlyArray<RecommendationsQuery | TrendingQuery>, requestOptions) => {
return (queries, requestOptions) => {
const requests: ReadonlyArray<
RecommendationsQuery | TrendingQuery | RecommendedForYouQuery
> = queries.map(query => ({
Expand Down
9 changes: 7 additions & 2 deletions packages/recommend/src/methods/getRecommendedForYou.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { MethodEnum } from '@algolia/requester-common';

import { BaseRecommendClient, RecommendedForYouQuery, WithRecommendMethods } from '../types';
import {
BaseRecommendClient,
RecommendedForYouParams,
RecommendedForYouQuery,
WithRecommendMethods,
} from '../types';

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

export const getRecommendedForYou: GetRecommendedForYou = base => {
return (queries: readonly RecommendedForYouQuery[], requestOptions) => {
return (queries: readonly RecommendedForYouParams[], requestOptions) => {
const requests: readonly RecommendedForYouQuery[] = queries.map(query => ({
...query,
model: 'recommended-for-you',
Expand Down
3 changes: 1 addition & 2 deletions packages/recommend/src/types/RecommendationsQuery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { RecommendModel } from './RecommendModel';
import { RecommendSearchOptions } from './RecommendSearchOptions';

export type RecommendationsQuery = {
Expand All @@ -10,7 +9,7 @@ export type RecommendationsQuery = {
/**
* The name of the Recommendation model to use.
*/
readonly model: RecommendModel;
readonly model: 'related-products' | 'bought-together' | 'looking-similar';

/**
* The `objectID` of the item to get recommendations for.
Expand Down
6 changes: 6 additions & 0 deletions packages/recommend/src/types/RecommendedForYouQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type RecommendedForYouQuery = Omit<
RecommendationsQuery,
'model' | 'objectID' | 'queryParameters'
> & {
readonly model: 'recommended-for-you';
/**
* List of [search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/) to send.
*/
Expand All @@ -17,3 +18,8 @@ export type RecommendedForYouQuery = Omit<
readonly userToken: string;
};
};

/**
* The parameters used for `getRecommendedForYou` method.
*/
export type RecommendedForYouParams = Omit<RecommendedForYouQuery, 'model'>;
6 changes: 3 additions & 3 deletions packages/recommend/src/types/WithRecommendMethods.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SearchOptions, SearchResponse } from '@algolia/client-search';
import { RequestOptions } from '@algolia/transporter';

import { RecommendedForYouQuery } from '../builds/node';
import { RecommendedForYouParams, RecommendedForYouQuery } from '../builds/node';
import { FrequentlyBoughtTogetherQuery } from './FrequentlyBoughtTogetherQuery';
import { LookingSimilarQuery } from './LookingSimilarQuery';
import { RecommendationsQuery } from './RecommendationsQuery';
Expand Down Expand Up @@ -30,7 +30,7 @@ export type WithRecommendMethods<TType> = TType & {
* Returns recommendations.
*/
readonly getRecommendations: <TObject>(
queries: ReadonlyArray<RecommendationsQuery | TrendingQuery>,
queries: ReadonlyArray<RecommendationsQuery | TrendingQuery | RecommendedForYouQuery>,
requestOptions?: RequestOptions & SearchOptions
) => Readonly<Promise<RecommendQueriesResponse<TObject>>>;

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