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,61 @@ 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, + ), + id: t.maybe(t.String), + }); -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, + ), + id: 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 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), + id: 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, + ), + id: t.maybe(t.String), + }); 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 +137,8 @@ ), preloadedState: t.Object, currentState: t.Object, - actions: t.list(t.union([t.Object, t.String])), + actions: t.list(t.Object), + id: t.maybe(t.String), }), threadInconsistencyReportCreationRequest, entryInconsistencyReportCreationRquest, @@ -159,35 +172,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/keyserver/src/shared/state-sync/users-state-sync-spec.js b/keyserver/src/shared/state-sync/users-state-sync-spec.js --- a/keyserver/src/shared/state-sync/users-state-sync-spec.js +++ b/keyserver/src/shared/state-sync/users-state-sync-spec.js @@ -1,7 +1,7 @@ // @flow import { usersStateSyncSpec as libSpec } from 'lib/shared/state-sync/users-state-sync-spec.js'; -import type { UserInconsistencyReportCreationRequest } from 'lib/types/report-types.js'; +import type { ClientUserInconsistencyReportCreationRequest } from 'lib/types/report-types.js'; import type { UserInfos, UserInfo } from 'lib/types/user-types.js'; import { userInfoValidator } from 'lib/types/user-types.js'; import { values, hash, combineUnorderedHashes } from 'lib/utils/objects.js'; @@ -15,7 +15,7 @@ UserInfos, $ReadOnlyArray, UserInfo, - $ReadOnlyArray, + $ReadOnlyArray, > = Object.freeze({ fetch, async fetchFullSocketSyncPayload(viewer: Viewer) { diff --git a/lib/reducers/report-store-reducer.test.js b/lib/reducers/report-store-reducer.test.js --- a/lib/reducers/report-store-reducer.test.js +++ b/lib/reducers/report-store-reducer.test.js @@ -7,8 +7,8 @@ import { type ReportStore, reportTypes, - type MediaMissionReportCreationRequest, - type ErrorReportCreationRequest, + type ClientMediaMissionReportCreationRequest, + type ClientErrorReportCreationRequest, type EnabledReports, type ClientThreadInconsistencyReportCreationRequest, } from '../types/report-types.js'; @@ -31,7 +31,7 @@ loadingInfo, }; -const mockErrorReport: ErrorReportCreationRequest = { +const mockErrorReport: ClientErrorReportCreationRequest = { type: reportTypes.ERROR, platformDetails: { platform: 'web' }, errors: [], @@ -53,7 +53,7 @@ id: '1-2', }; -const mockMediaReport: MediaMissionReportCreationRequest = { +const mockMediaReport: ClientMediaMissionReportCreationRequest = { type: reportTypes.MEDIA_MISSION, platformDetails: { platform: 'web' }, time: Date.now(), diff --git a/lib/reducers/user-reducer.js b/lib/reducers/user-reducer.js --- a/lib/reducers/user-reducer.js +++ b/lib/reducers/user-reducer.js @@ -20,7 +20,7 @@ import { stateSyncSpecs } from '../shared/state-sync/state-sync-specs.js'; import { updateSpecs } from '../shared/updates/update-specs.js'; import type { BaseAction } from '../types/redux-types.js'; -import type { UserInconsistencyReportCreationRequest } from '../types/report-types.js'; +import type { ClientUserInconsistencyReportCreationRequest } from '../types/report-types.js'; import { serverRequestTypes, processServerRequestsActionType, @@ -119,7 +119,7 @@ function reduceUserInfos( state: UserStore, action: BaseAction, -): [UserStore, $ReadOnlyArray] { +): [UserStore, $ReadOnlyArray] { if ( action.type === joinThreadActionTypes.success || action.type === newThreadActionTypes.success diff --git a/lib/shared/state-sync/users-state-sync-spec.js b/lib/shared/state-sync/users-state-sync-spec.js --- a/lib/shared/state-sync/users-state-sync-spec.js +++ b/lib/shared/state-sync/users-state-sync-spec.js @@ -7,7 +7,7 @@ import type { AppState } from '../../types/redux-types'; import { reportTypes, - type UserInconsistencyReportCreationRequest, + type ClientUserInconsistencyReportCreationRequest, } from '../../types/report-types.js'; import type { ProcessServerRequestAction } from '../../types/request-types.js'; import { type UserInfo, type UserInfos } from '../../types/user-types.js'; @@ -22,7 +22,7 @@ ) => BoundStateSyncSpec< UserInfos, UserInfo, - $ReadOnlyArray, + $ReadOnlyArray, > = createSelector( (state: AppState) => state.userStore.userInfos, (userInfos: UserInfos) => ({ @@ -37,7 +37,7 @@ export const usersStateSyncSpec: StateSyncSpec< UserInfos, UserInfo, - $ReadOnlyArray, + $ReadOnlyArray, > = Object.freeze({ hashKey: 'userInfos', innerHashSpec: { @@ -72,4 +72,5 @@ selector, }); -const emptyArray: $ReadOnlyArray = []; +const emptyArray: $ReadOnlyArray = + []; 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 = { @@ -106,15 +106,17 @@ +preloadedState: AppState, +currentState: AppState, +actions: $ReadOnlyArray, - +id: string, + +id?: ?string, }; export type ThreadInconsistencyReportCreationRequest = { ...ThreadInconsistencyReportShape, +type: 1, + +id?: ?string, }; export type EntryInconsistencyReportCreationRequest = { ...EntryInconsistencyReportShape, +type: 2, + +id?: ?string, }; export type MediaMissionReportCreationRequest = { +type: 3, @@ -126,12 +128,12 @@ +mediaLocalID?: ?string, // deprecated +messageServerID?: ?string, +messageLocalID?: ?string, - +id: string, + +id?: ?string, }; export type UserInconsistencyReportCreationRequest = { ...UserInconsistencyReportShape, +type: 4, - +id: string, + +id?: ?string, }; export type ReportCreationRequest = | ErrorReportCreationRequest @@ -158,6 +160,10 @@ +time: number, }; +export type ClientErrorReportCreationRequest = { + ...ErrorReportCreationRequest, + +id: string, +}; export type ClientThreadInconsistencyReportCreationRequest = { ...ClientThreadInconsistencyReportShape, +type: 1, @@ -168,13 +174,21 @@ +type: 2, +id: string, }; +export type ClientMediaMissionReportCreationRequest = { + ...MediaMissionReportCreationRequest, + +id: string, +}; +export type ClientUserInconsistencyReportCreationRequest = { + ...UserInconsistencyReportCreationRequest, + +id: string, +}; export type ClientReportCreationRequest = - | ErrorReportCreationRequest + | ClientErrorReportCreationRequest | ClientThreadInconsistencyReportCreationRequest | ClientEntryInconsistencyReportCreationRequest - | MediaMissionReportCreationRequest - | UserInconsistencyReportCreationRequest; + | ClientMediaMissionReportCreationRequest + | ClientUserInconsistencyReportCreationRequest; export type QueueReportsPayload = { +reports: $ReadOnlyArray,