From 3758a43ad298d02cee6a6f68b1c82e9b6db82545 Mon Sep 17 00:00:00 2001 From: Kat Schelonka Date: Tue, 7 Jan 2025 11:01:16 -0800 Subject: [PATCH] fix(v3proxy): update default page size for since queries to 5000 Fix incorrect state name (archived/archive) and access using typescript-checkable method --- .../v3-proxy-api/src/graph/get/toGraphQL.ts | 4 +-- .../src/routes/v3Get.integration.ts | 25 +++++++++++++ .../src/routes/validations/GetSchema.ts | 36 ++++++++++++------- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/servers/v3-proxy-api/src/graph/get/toGraphQL.ts b/servers/v3-proxy-api/src/graph/get/toGraphQL.ts index 91dfeccaa..d364c3abd 100644 --- a/servers/v3-proxy-api/src/graph/get/toGraphQL.ts +++ b/servers/v3-proxy-api/src/graph/get/toGraphQL.ts @@ -41,8 +41,8 @@ export function SavedItemsSortFactory(params: V3GetParams) { if (params.favorite != null) { sortBy = SavedItemsSortBy.FavoritedAt; } else if ( - params.state && - ['read', 'archived'].indexOf(params.state) > -1 + (params.state && params.state === 'read') || + params.state === 'archive' ) { sortBy = SavedItemsSortBy.ArchivedAt; } diff --git a/servers/v3-proxy-api/src/routes/v3Get.integration.ts b/servers/v3-proxy-api/src/routes/v3Get.integration.ts index 042a9337e..4652b3d22 100644 --- a/servers/v3-proxy-api/src/routes/v3Get.integration.ts +++ b/servers/v3-proxy-api/src/routes/v3Get.integration.ts @@ -1266,6 +1266,31 @@ describe('v3Get', () => { expect(apiSpy.mock.lastCall?.[3].filter?.updatedSince).toEqual(123123); expect(response.headers['x-source']).toBe(expectedHeaders['X-Source']); }); + it('should set count to 5000 if `since` parameter is passed', async () => { + const apiSpy = jest + .spyOn(GraphQLCalls, 'callSavedItemsByOffsetComplete') + .mockImplementation(() => Promise.resolve(mockGraphGetComplete)); + const response = await request(app).get('/v3/get').query({ + consumer_key: 'test', + access_token: 'test', + since: '123123', + detailType: 'complete', + }); + expect(apiSpy.mock.lastCall?.[3].pagination?.limit).toEqual(5000); + expect(response.headers['x-source']).toBe(expectedHeaders['X-Source']); + }); + it('should set count to 30 if no `since` parameter', async () => { + const apiSpy = jest + .spyOn(GraphQLCalls, 'callSavedItemsByOffsetComplete') + .mockImplementation(() => Promise.resolve(mockGraphGetComplete)); + const response = await request(app).get('/v3/get').query({ + consumer_key: 'test', + access_token: 'test', + detailType: 'complete', + }); + expect(apiSpy.mock.lastCall?.[3].pagination?.limit).toEqual(30); + expect(response.headers['x-source']).toBe(expectedHeaders['X-Source']); + }); it('should not add contentType filter if value="all"', async () => { const apiSpy = jest .spyOn(GraphQLCalls, 'callSavedItemsByOffsetComplete') diff --git a/servers/v3-proxy-api/src/routes/validations/GetSchema.ts b/servers/v3-proxy-api/src/routes/validations/GetSchema.ts index 78a89cc63..bbdc963c9 100644 --- a/servers/v3-proxy-api/src/routes/validations/GetSchema.ts +++ b/servers/v3-proxy-api/src/routes/validations/GetSchema.ts @@ -89,18 +89,6 @@ export const V3GetSchema: Schema = { }, toInt: true, }, - count: { - default: { - options: 30, - }, - isInt: { - options: { - min: 1, - max: 5000, - }, - }, - toInt: true, - }, tag: { optional: true, isString: true, @@ -116,6 +104,30 @@ export const V3GetSchema: Schema = { options: (value) => timeSeconds(value), }, }, + count: { + toInt: true, + customSanitizer: { + options: (value, { req }) => { + const hasSince = + req.body.since != null || req.query?.since != null ? true : false; + // Android client does not paginate results for 'since' + if (value == null || value === '' || Number.isNaN(value)) { + if (hasSince) { + return 5000; + } else { + return 30; + } + } + return value; + }, + }, + isInt: { + options: { + min: 1, + max: 5000, + }, + }, + }, updatedBefore: { optional: true, isInt: {