Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/responders/report-responders.js
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | |||||
const userInconsistencyReportCreationRequest = tShape({ | const userInconsistencyReportCreationRequest = tShape({ | ||||
...userInconsistencyReportValidatorShape, | ...userInconsistencyReportValidatorShape, | ||||
type: t.irreducible( | type: t.irreducible( | ||||
'reportTypes.USER_INCONSISTENCY', | 'reportTypes.USER_INCONSISTENCY', | ||||
x => x === reportTypes.USER_INCONSISTENCY, | x => x === reportTypes.USER_INCONSISTENCY, | ||||
), | ), | ||||
}); | }); | ||||
const reportCreationRequestInputValidator = t.union([ | const reportCreationRequestInputValidator = t.union<ReportCreationRequest>([ | ||||
tShape({ | tShape({ | ||||
type: t.maybe( | type: t.maybe( | ||||
t.irreducible('reportTypes.ERROR', x => x === reportTypes.ERROR), | t.irreducible('reportTypes.ERROR', x => x === reportTypes.ERROR), | ||||
), | ), | ||||
platformDetails: t.maybe(tPlatformDetails), | platformDetails: t.maybe(tPlatformDetails), | ||||
deviceType: t.maybe(tPlatform), | deviceType: t.maybe(tPlatform), | ||||
codeVersion: t.maybe(t.Number), | codeVersion: t.maybe(t.Number), | ||||
stateVersion: t.maybe(t.Number), | stateVersion: t.maybe(t.Number), | ||||
Show All 14 Lines | const reportCreationRequestInputValidator = t.union<ReportCreationRequest>([ | ||||
userInconsistencyReportCreationRequest, | userInconsistencyReportCreationRequest, | ||||
]); | ]); | ||||
export const reportCreationResponseValidator: TInterface<ReportCreationResponse> = | export const reportCreationResponseValidator: TInterface<ReportCreationResponse> = | ||||
tShape<ReportCreationResponse>({ id: t.String }); | tShape<ReportCreationResponse>({ id: t.String }); | ||||
async function reportCreationResponder( | async function reportCreationResponder( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
input: any, | input: mixed, | ||||
): Promise<ReportCreationResponse> { | ): Promise<ReportCreationResponse> { | ||||
await validateInput(viewer, reportCreationRequestInputValidator, input); | let request = await validateInput( | ||||
if (input.type === null || input.type === undefined) { | viewer, | ||||
input.type = reportTypes.ERROR; | reportCreationRequestInputValidator, | ||||
input, | |||||
); | |||||
if (request.type === null || request.type === undefined) { | |||||
request.type = reportTypes.ERROR; | |||||
} | } | ||||
if (!input.platformDetails && input.deviceType) { | if (!request.platformDetails && request.deviceType) { | ||||
const { deviceType, codeVersion, stateVersion, ...rest } = input; | const { deviceType, codeVersion, stateVersion, ...rest } = request; | ||||
input = { | request = { | ||||
...rest, | ...rest, | ||||
platformDetails: { platform: deviceType, codeVersion, stateVersion }, | platformDetails: { platform: deviceType, codeVersion, stateVersion }, | ||||
}; | }; | ||||
} | } | ||||
const request: ReportCreationRequest = input; | |||||
const response = await createReport(viewer, request); | const response = await createReport(viewer, request); | ||||
if (!response) { | if (!response) { | ||||
throw new ServerError('ignored_report'); | throw new ServerError('ignored_report'); | ||||
} | } | ||||
return validateOutput(viewer, reportCreationResponseValidator, response); | return validateOutput(viewer, reportCreationResponseValidator, response); | ||||
} | } | ||||
const reportMultiCreationRequestInputValidator = tShape({ | const reportMultiCreationRequestInputValidator = | ||||
tShape<ReportMultiCreationRequest>({ | |||||
reports: t.list( | reports: t.list( | ||||
t.union([ | t.union([ | ||||
tShape({ | tShape({ | ||||
type: t.irreducible('reportTypes.ERROR', x => x === reportTypes.ERROR), | type: t.irreducible( | ||||
'reportTypes.ERROR', | |||||
x => x === reportTypes.ERROR, | |||||
), | |||||
platformDetails: tPlatformDetails, | platformDetails: tPlatformDetails, | ||||
errors: t.list( | errors: t.list( | ||||
tShape({ | tShape({ | ||||
errorMessage: t.String, | errorMessage: t.String, | ||||
stack: t.maybe(t.String), | stack: t.maybe(t.String), | ||||
componentStack: t.maybe(t.String), | componentStack: t.maybe(t.String), | ||||
}), | }), | ||||
), | ), | ||||
preloadedState: t.Object, | preloadedState: t.Object, | ||||
currentState: t.Object, | currentState: t.Object, | ||||
actions: t.list(t.union([t.Object, t.String])), | actions: t.list(t.union([t.Object, t.String])), | ||||
}), | }), | ||||
threadInconsistencyReportCreationRequest, | threadInconsistencyReportCreationRequest, | ||||
entryInconsistencyReportCreationRquest, | entryInconsistencyReportCreationRquest, | ||||
mediaMissionReportCreationRequest, | mediaMissionReportCreationRequest, | ||||
userInconsistencyReportCreationRequest, | userInconsistencyReportCreationRequest, | ||||
]), | ]), | ||||
), | ), | ||||
}); | }); | ||||
type ReportMultiCreationRequest = { | type ReportMultiCreationRequest = { | ||||
reports: $ReadOnlyArray<ReportCreationRequest>, | reports: $ReadOnlyArray<ReportCreationRequest>, | ||||
}; | }; | ||||
async function reportMultiCreationResponder( | async function reportMultiCreationResponder( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
input: any, | input: mixed, | ||||
): Promise<void> { | ): Promise<void> { | ||||
const request: ReportMultiCreationRequest = input; | const request = await validateInput( | ||||
await validateInput( | |||||
viewer, | viewer, | ||||
reportMultiCreationRequestInputValidator, | reportMultiCreationRequestInputValidator, | ||||
request, | input, | ||||
); | ); | ||||
await Promise.all( | await Promise.all( | ||||
request.reports.map(reportCreationRequest => | request.reports.map(reportCreationRequest => | ||||
createReport(viewer, reportCreationRequest), | createReport(viewer, reportCreationRequest), | ||||
), | ), | ||||
); | ); | ||||
} | } | ||||
const fetchErrorReportInfosRequestInputValidator = tShape({ | const fetchErrorReportInfosRequestInputValidator = | ||||
tShape<FetchErrorReportInfosRequest>({ | |||||
cursor: t.maybe(t.String), | cursor: t.maybe(t.String), | ||||
}); | }); | ||||
export const fetchErrorReportInfosResponseValidator: TInterface<FetchErrorReportInfosResponse> = | export const fetchErrorReportInfosResponseValidator: TInterface<FetchErrorReportInfosResponse> = | ||||
tShape<FetchErrorReportInfosResponse>({ | tShape<FetchErrorReportInfosResponse>({ | ||||
reports: t.list(reportInfoValidator), | reports: t.list(reportInfoValidator), | ||||
userInfos: t.list(userInfoValidator), | userInfos: t.list(userInfoValidator), | ||||
}); | }); | ||||
async function errorReportFetchInfosResponder( | async function errorReportFetchInfosResponder( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
input: any, | input: mixed, | ||||
): Promise<FetchErrorReportInfosResponse> { | ): Promise<FetchErrorReportInfosResponse> { | ||||
const request: FetchErrorReportInfosRequest = input; | const request = await validateInput( | ||||
await validateInput( | |||||
viewer, | viewer, | ||||
fetchErrorReportInfosRequestInputValidator, | fetchErrorReportInfosRequestInputValidator, | ||||
request, | input, | ||||
); | ); | ||||
const response = await fetchErrorReportInfos(viewer, request); | const response = await fetchErrorReportInfos(viewer, request); | ||||
return validateOutput( | return validateOutput( | ||||
viewer, | viewer, | ||||
fetchErrorReportInfosResponseValidator, | fetchErrorReportInfosResponseValidator, | ||||
response, | response, | ||||
); | ); | ||||
} | } | ||||
Show All 26 Lines |