From 781ca391ecfcdb02193c88b25d14004084979a75 Mon Sep 17 00:00:00 2001 From: aditya Date: Thu, 20 Feb 2025 13:43:59 +0100 Subject: [PATCH 1/2] chore: ranking vars now accept both string and maps --- src/client.ts | 12 ++++++++++-- src/feed.ts | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/client.ts b/src/client.ts index 73bbab46..39d8d944 100644 --- a/src/client.ts +++ b/src/client.ts @@ -503,7 +503,7 @@ export class StreamClient; + rankingVars?: string | Record; reactionKindsFilter?: string[]; reactions?: Record>; withOwnChildren?: boolean; @@ -522,7 +522,15 @@ export class StreamClient; + if (typeof options.reactions.ranking_vars === 'object') { + options.rankingVars = options.reactions.ranking_vars as Record; + } else if (typeof options.reactions.ranking_vars === 'string') { + options.rankingVars = options.reactions.ranking_vars as string; + } + } + // if ranking vars are Record, json stringify them + if (options.rankingVars && typeof options.rankingVars === 'object') { + options.rankingVars = JSON.stringify(options.rankingVars); } if (options.reactions.score_vars != null) { options.withScoreVars = options.reactions.score_vars as boolean; diff --git a/src/feed.ts b/src/feed.ts index 04d4d351..673a8d6a 100644 --- a/src/feed.ts +++ b/src/feed.ts @@ -41,7 +41,7 @@ export type FeedPaginationOptions = { export type RankedFeedOptions = { offset?: number; ranking?: string; - rankingVars?: Record; + rankingVars?: string | Record; session?: string; withScoreVars?: boolean; }; From 53e12083b99bfacf53d5820ec5a5353f2741e138 Mon Sep 17 00:00:00 2001 From: aditya Date: Thu, 20 Feb 2025 14:07:18 +0100 Subject: [PATCH 2/2] chore: ranking vars add tests --- test/integration/cloud/reaction.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/integration/cloud/reaction.js b/test/integration/cloud/reaction.js index 038a2355..b5f8343c 100644 --- a/test/integration/cloud/reaction.js +++ b/test/integration/cloud/reaction.js @@ -66,6 +66,36 @@ describe('Reaction pagination', () => { }); }); + describe('#withRankingVarsAsMap', () => { + ctx.requestShouldNotError(async () => { + ctx.response = await ctx.bob.feed('user', ctx.alice.userId).get({ + reactions: { score_vars: true }, + limit: 4, + offset: 2, + rankingVars: { popular: 1, music: 4 }, + }); + }); + }); + describe('#withRankingVarsShouldErr', () => { + ctx.requestShouldError(400, async () => { + ctx.response = await ctx.bob.feed('user', ctx.alice.userId).get({ + reactions: { score_vars: true }, + limit: 4, + offset: 2, + rankingVars: ['popular', 1], + }); + }); + }); + describe('#withRankingVarsAsString', () => { + ctx.requestShouldNotError(async () => { + ctx.response = await ctx.bob.feed('user', ctx.alice.userId).get({ + reactions: { score_vars: true }, + limit: 4, + offset: 2, + rankingVars: '{"sports":1,"music":4}', + }); + }); + }); describe('When bob reads alice her feed with all enrichment enabled', () => { ctx.requestShouldNotError(async () => { ctx.response = await ctx.bob.feed('user', ctx.alice.userId).get({