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 type { BaseAction } from 'lib/types/redux-types.js'; import { type ReportCreationResponse, type ReportCreationRequest, @@ -11,16 +12,17 @@ type FetchErrorReportInfosRequest, type ThreadInconsistencyReportShape, type EntryInconsistencyReportShape, + type ActionSummary, + type ThreadInconsistencyReportCreationRequest, + type EntryInconsistencyReportCreationRequest, + type MediaMissionReportCreationRequest, + type UserInconsistencyReportCreationRequest, reportTypes, reportInfoValidator, } from 'lib/types/report-types.js'; import { userInfoValidator } from 'lib/types/user-types.js'; import { ServerError } from 'lib/utils/errors.js'; -import { - tShape, - tPlatform, - tPlatformDetails, -} from 'lib/utils/validation-utils.js'; +import { tShape, tPlatformDetails } from 'lib/utils/validation-utils.js'; import { newEntryQueryInputValidator } from './entry-responders.js'; import createReport from '../creators/report-creator.js'; @@ -30,11 +32,15 @@ } from '../fetchers/report-fetchers.js'; import type { Viewer } from '../session/viewer.js'; -const tActionSummary = tShape({ +const tActionSummary = tShape({ type: t.String, time: t.Number, summary: t.String, }); +const tActionType = t.irreducible<$PropertyType>( + 'ActionType', + x => typeof x === 'string', +); const threadInconsistencyReportValidatorShape: TStructProps = { platformDetails: tPlatformDetails, @@ -42,7 +48,7 @@ action: t.Object, pollResult: t.maybe(t.Object), pushResult: t.Object, - lastActionTypes: t.maybe(t.list(t.String)), + lastActionTypes: t.maybe(t.list(tActionType)), lastActions: t.maybe(t.list(tActionSummary)), time: t.maybe(t.Number), }; @@ -54,7 +60,7 @@ calendarQuery: newEntryQueryInputValidator, pollResult: t.maybe(t.Object), pushResult: t.Object, - lastActionTypes: t.maybe(t.list(t.String)), + lastActionTypes: t.maybe(t.list(tActionType)), lastActions: t.maybe(t.list(tActionSummary)), time: t.Number, }; @@ -67,55 +73,57 @@ time: t.Number, }; -const threadInconsistencyReportCreationRequest = tShape({ - ...threadInconsistencyReportValidatorShape, - type: t.irreducible( - 'reportTypes.THREAD_INCONSISTENCY', - x => x === reportTypes.THREAD_INCONSISTENCY, - ), -}); +const threadInconsistencyReportCreationRequest = + tShape({ + ...threadInconsistencyReportValidatorShape, + type: t.irreducible( + 'reportTypes.THREAD_INCONSISTENCY', + x => x === reportTypes.THREAD_INCONSISTENCY, + ), + }); -const entryInconsistencyReportCreationRquest = tShape({ - ...entryInconsistencyReportValidatorShape, - type: t.irreducible( - 'reportTypes.ENTRY_INCONSISTENCY', - x => x === reportTypes.ENTRY_INCONSISTENCY, - ), -}); +const entryInconsistencyReportCreationRquest = + tShape({ + ...entryInconsistencyReportValidatorShape, + type: t.irreducible( + 'reportTypes.ENTRY_INCONSISTENCY', + x => x === reportTypes.ENTRY_INCONSISTENCY, + ), + }); -const mediaMissionReportCreationRequest = tShape({ - type: t.irreducible( - 'reportTypes.MEDIA_MISSION', - x => x === reportTypes.MEDIA_MISSION, - ), - platformDetails: tPlatformDetails, - time: t.Number, - mediaMission: t.Object, - uploadServerID: t.maybe(t.String), - uploadLocalID: t.maybe(t.String), - mediaLocalID: t.maybe(t.String), - messageServerID: t.maybe(t.String), - messageLocalID: t.maybe(t.String), -}); +const mediaMissionReportCreationRequest = + tShape({ + type: t.irreducible( + 'reportTypes.MEDIA_MISSION', + x => x === reportTypes.MEDIA_MISSION, + ), + platformDetails: tPlatformDetails, + time: t.Number, + mediaMission: t.Object, + uploadServerID: t.maybe(t.String), + uploadLocalID: t.maybe(t.String), + mediaLocalID: t.maybe(t.String), + messageServerID: t.maybe(t.String), + messageLocalID: t.maybe(t.String), + }); -const userInconsistencyReportCreationRequest = tShape({ - ...userInconsistencyReportValidatorShape, - type: t.irreducible( - 'reportTypes.USER_INCONSISTENCY', - x => x === reportTypes.USER_INCONSISTENCY, - ), -}); +const userInconsistencyReportCreationRequest = + tShape({ + ...userInconsistencyReportValidatorShape, + type: t.irreducible( + 'reportTypes.USER_INCONSISTENCY', + x => x === reportTypes.USER_INCONSISTENCY, + ), + }); export const reportCreationRequestInputValidator: TUnion = t.union([ tShape({ - type: t.maybe( - t.irreducible('reportTypes.ERROR', x => x === reportTypes.ERROR), + type: t.irreducible( + 'reportTypes.ERROR', + x => x === reportTypes.ERROR, ), - platformDetails: t.maybe(tPlatformDetails), - deviceType: t.maybe(tPlatform), - codeVersion: t.maybe(t.Number), - stateVersion: t.maybe(t.Number), + platformDetails: tPlatformDetails, errors: t.list( tShape({ errorMessage: t.String, @@ -125,7 +133,7 @@ ), preloadedState: t.Object, currentState: t.Object, - actions: t.list(t.union([t.Object, t.String])), + actions: t.list(t.Object), }), threadInconsistencyReportCreationRequest, entryInconsistencyReportCreationRquest, @@ -159,35 +167,11 @@ export const reportMultiCreationRequestInputValidator: TInterface = tShape({ - reports: t.list( - t.union([ - tShape({ - type: t.irreducible( - 'reportTypes.ERROR', - x => x === reportTypes.ERROR, - ), - platformDetails: tPlatformDetails, - errors: t.list( - tShape({ - errorMessage: t.String, - stack: t.maybe(t.String), - componentStack: t.maybe(t.String), - }), - ), - preloadedState: t.Object, - currentState: t.Object, - actions: t.list(t.union([t.Object, t.String])), - }), - threadInconsistencyReportCreationRequest, - entryInconsistencyReportCreationRquest, - mediaMissionReportCreationRequest, - userInconsistencyReportCreationRequest, - ]), - ), + reports: t.list(reportCreationRequestInputValidator), }); type ReportMultiCreationRequest = { - reports: $ReadOnlyArray, + +reports: $ReadOnlyArray, }; async function reportMultiCreationResponder( viewer: Viewer, diff --git a/lib/types/device-types.js b/lib/types/device-types.js --- a/lib/types/device-types.js +++ b/lib/types/device-types.js @@ -37,8 +37,8 @@ export type PlatformDetails = { +platform: Platform, - +codeVersion?: number, - +stateVersion?: number, + +codeVersion?: ?number, + +stateVersion?: ?number, }; export type VersionResponse = { diff --git a/lib/types/report-types.js b/lib/types/report-types.js --- a/lib/types/report-types.js +++ b/lib/types/report-types.js @@ -73,21 +73,21 @@ +platformDetails: PlatformDetails, +beforeAction: RawThreadInfos, +action: BaseAction, - +pollResult?: RawThreadInfos, + +pollResult?: ?RawThreadInfos, +pushResult: RawThreadInfos, - +lastActionTypes?: $ReadOnlyArray<$PropertyType>, - +lastActions?: $ReadOnlyArray, - +time?: number, + +lastActionTypes?: ?$ReadOnlyArray<$PropertyType>, + +lastActions?: ?$ReadOnlyArray, + +time?: ?number, }; export type EntryInconsistencyReportShape = { +platformDetails: PlatformDetails, +beforeAction: { +[id: string]: RawEntryInfo }, +action: BaseAction, +calendarQuery: CalendarQuery, - +pollResult?: { +[id: string]: RawEntryInfo }, + +pollResult?: ?{ +[id: string]: RawEntryInfo }, +pushResult: { +[id: string]: RawEntryInfo }, - +lastActionTypes?: $ReadOnlyArray<$PropertyType>, - +lastActions?: $ReadOnlyArray, + +lastActionTypes?: ?$ReadOnlyArray<$PropertyType>, + +lastActions?: ?$ReadOnlyArray, +time: number, }; export type UserInconsistencyReportShape = {