Skip to content

Commit

Permalink
fix(recommend): update recommended-for-you model type (#1500)
Browse files Browse the repository at this point in the history
* fix(recommend): update recommended-for-you model type

* fix RecommendedForYouQuery by removing model

* simplify getRecommendations

* RecommendedForYouParams
  • Loading branch information
raed667 authored Jan 9, 2024
1 parent 5a2a128 commit f94ce64
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
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>>>;
};

0 comments on commit f94ce64

Please sign in to comment.