diff --git a/keyserver/src/endpoints.js b/keyserver/src/endpoints.js --- a/keyserver/src/endpoints.js +++ b/keyserver/src/endpoints.js @@ -6,6 +6,7 @@ import { baseLegalPolicies } from 'lib/facts/policies.js'; import type { PolicyType } from 'lib/facts/policies.js'; import type { Endpoint } from 'lib/types/endpoints.js'; +import { calendarQueryValidator } from 'lib/types/entry-types.js'; import { endpointValidators } from 'lib/types/validators/endpoint-validators.js'; import { updateUserAvatarRequestValidator } from 'lib/utils/avatar-utils.js'; @@ -32,7 +33,6 @@ deleteEntryRequestInputValidator, entryQueryInputValidator, entryRevisionHistoryFetchInputValidator, - newEntryQueryInputValidator, restoreEntryRequestInputValidator, saveEntryRequestInputValidator, } from './responders/entry-responders.js'; @@ -396,7 +396,7 @@ }, update_calendar_query: { responder: calendarQueryUpdateResponder, - inputValidator: newEntryQueryInputValidator, + inputValidator: calendarQueryValidator, policies: baseLegalPolicies, }, update_user_settings: { diff --git a/keyserver/src/responders/entry-responders.js b/keyserver/src/responders/entry-responders.js --- a/keyserver/src/responders/entry-responders.js +++ b/keyserver/src/responders/entry-responders.js @@ -15,17 +15,19 @@ type FetchEntryInfosResponse, type DeltaEntryInfosResult, type SaveEntryResponse, + calendarQueryValidator, } from 'lib/types/entry-types.js'; import { type CalendarFilter, calendarThreadFilterTypes, + calendarFilterValidator, } from 'lib/types/filter-types.js'; import { type FetchEntryRevisionInfosResult, type FetchEntryRevisionInfosRequest, } from 'lib/types/history-types.js'; import { ServerError } from 'lib/utils/errors.js'; -import { tString, tShape, tDate, tID } from 'lib/utils/validation-utils.js'; +import { tShape, tDate, tID } from 'lib/utils/validation-utils.js'; import createEntry from '../creators/entry-creator.js'; import { deleteEntry, restoreEntry } from '../deleters/entry-deleters.js'; @@ -55,37 +57,9 @@ startDate: tDate, endDate: tDate, includeDeleted: t.maybe(t.Boolean), - filters: t.maybe( - t.list( - t.union([ - tShape({ - type: tString(calendarThreadFilterTypes.NOT_DELETED), - }), - tShape({ - type: tString(calendarThreadFilterTypes.THREAD_LIST), - threadIDs: t.list(tID), - }), - ]), - ), - ), + filters: t.maybe(t.list(calendarFilterValidator)), }); -const newEntryQueryInputValidator: TInterface = tShape({ - startDate: tDate, - endDate: tDate, - filters: t.list( - t.union([ - tShape({ - type: tString(calendarThreadFilterTypes.NOT_DELETED), - }), - tShape({ - type: tString(calendarThreadFilterTypes.THREAD_LIST), - threadIDs: t.list(tID), - }), - ]), - ), -}); - function normalizeCalendarQuery(input: any): CalendarQuery { if (input.filters) { return { @@ -159,7 +133,7 @@ date: tDate, threadID: tID, localID: t.maybe(t.String), - calendarQuery: t.maybe(newEntryQueryInputValidator), + calendarQuery: t.maybe(calendarQueryValidator), }); async function entryCreationResponder( @@ -176,7 +150,7 @@ prevText: t.String, sessionID: t.maybe(t.String), timestamp: t.Number, - calendarQuery: t.maybe(newEntryQueryInputValidator), + calendarQuery: t.maybe(calendarQueryValidator), }); async function entryUpdateResponder( @@ -192,7 +166,7 @@ prevText: t.String, sessionID: t.maybe(t.String), timestamp: t.Number, - calendarQuery: t.maybe(newEntryQueryInputValidator), + calendarQuery: t.maybe(calendarQueryValidator), }); async function entryDeletionResponder( @@ -207,7 +181,7 @@ entryID: tID, sessionID: t.maybe(t.String), timestamp: t.Number, - calendarQuery: t.maybe(newEntryQueryInputValidator), + calendarQuery: t.maybe(calendarQueryValidator), }); async function entryRestorationResponder( @@ -244,7 +218,6 @@ export { entryQueryInputValidator, - newEntryQueryInputValidator, normalizeCalendarQuery, verifyCalendarQueryThreadIDs, entryFetchResponder, diff --git a/keyserver/src/responders/report-responders.js b/keyserver/src/responders/report-responders.js --- a/keyserver/src/responders/report-responders.js +++ b/keyserver/src/responders/report-responders.js @@ -4,6 +4,7 @@ import t from 'tcomb'; import type { TInterface, TStructProps, TUnion } from 'tcomb'; +import { calendarQueryValidator } from 'lib/types/entry-types.js'; import type { BaseAction } from 'lib/types/redux-types.js'; import { type ReportCreationResponse, @@ -22,7 +23,6 @@ import { ServerError } from 'lib/utils/errors.js'; import { tShape, tPlatformDetails } from 'lib/utils/validation-utils.js'; -import { newEntryQueryInputValidator } from './entry-responders.js'; import createReport from '../creators/report-creator.js'; import { fetchErrorReportInfos, @@ -55,7 +55,7 @@ platformDetails: tPlatformDetails, beforeAction: t.Object, action: t.Object, - calendarQuery: newEntryQueryInputValidator, + calendarQuery: calendarQueryValidator, pollResult: t.maybe(t.Object), pushResult: t.Object, lastActionTypes: t.maybe(t.list(tActionType)), diff --git a/keyserver/src/responders/user-responders.js b/keyserver/src/responders/user-responders.js --- a/keyserver/src/responders/user-responders.js +++ b/keyserver/src/responders/user-responders.js @@ -51,6 +51,7 @@ import { type CalendarQuery, type FetchEntryInfosBase, + calendarQueryValidator, } from 'lib/types/entry-types.js'; import { defaultNumberPerThread } from 'lib/types/message-types.js'; import type { @@ -89,7 +90,6 @@ import { entryQueryInputValidator, - newEntryQueryInputValidator, normalizeCalendarQuery, verifyCalendarQueryThreadIDs, } from './entry-responders.js'; @@ -229,7 +229,7 @@ username: t.String, email: t.maybe(tEmail), password: tPassword, - calendarQuery: t.maybe(newEntryQueryInputValidator), + calendarQuery: t.maybe(calendarQueryValidator), deviceTokenUpdateRequest: t.maybe(deviceTokenUpdateRequestInputValidator), platformDetails: tPlatformDetails, // We include `primaryIdentityPublicKey` to avoid breaking diff --git a/keyserver/src/socket/socket.js b/keyserver/src/socket/socket.js --- a/keyserver/src/socket/socket.js +++ b/keyserver/src/socket/socket.js @@ -17,7 +17,10 @@ import { mostRecentUpdateTimestamp } from 'lib/shared/update-utils.js'; import { hasMinCodeVersion } from 'lib/shared/version-utils.js'; import { endpointIsSocketSafe } from 'lib/types/endpoints.js'; -import type { RawEntryInfo } from 'lib/types/entry-types.js'; +import { + type RawEntryInfo, + calendarQueryValidator, +} from 'lib/types/entry-types.js'; import { defaultNumberPerThread } from 'lib/types/message-types.js'; import { redisMessageTypes, type RedisMessage } from 'lib/types/redis-types.js'; import { serverRequestTypes } from 'lib/types/request-types.js'; @@ -67,10 +70,7 @@ getMessageFetchResultFromRedisMessages, } from '../fetchers/message-fetchers.js'; import { fetchUpdateInfos } from '../fetchers/update-fetchers.js'; -import { - newEntryQueryInputValidator, - verifyCalendarQueryThreadIDs, -} from '../responders/entry-responders.js'; +import { verifyCalendarQueryThreadIDs } from '../responders/entry-responders.js'; import { fetchViewerForSocket, updateCookie, @@ -105,7 +105,7 @@ sessionID: t.maybe(t.String), }), sessionState: tShape({ - calendarQuery: newEntryQueryInputValidator, + calendarQuery: calendarQueryValidator, messagesCurrentAsOf: t.Number, updatesCurrentAsOf: t.Number, watchedIDs: t.list(t.String), diff --git a/lib/types/filter-types.js b/lib/types/filter-types.js --- a/lib/types/filter-types.js +++ b/lib/types/filter-types.js @@ -22,10 +22,12 @@ export const calendarFilterValidator: TUnion = t.union([ tShape({ - type: tString('threads'), + type: tString(calendarThreadFilterTypes.THREAD_LIST), threadIDs: t.list(tID), }), - tShape({ type: tString('not_deleted') }), + tShape({ + type: tString(calendarThreadFilterTypes.NOT_DELETED), + }), ]); export const defaultCalendarFilters: $ReadOnlyArray = [