Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/responders/link-responders.js
// @flow | // @flow | ||||
import t, { type TUnion, type TInterface } from 'tcomb'; | import t, { type TUnion, type TInterface } from 'tcomb'; | ||||
import type { | import { | ||||
InviteLinkVerificationRequest, | type InviteLinkVerificationRequest, | ||||
InviteLinkVerificationResponse, | type InviteLinkVerificationResponse, | ||||
FetchInviteLinksResponse, | type FetchInviteLinksResponse, | ||||
inviteLinkValidator, | |||||
} from 'lib/types/link-types.js'; | } from 'lib/types/link-types.js'; | ||||
import { tShape, tID } from 'lib/utils/validation-utils.js'; | import { tShape, tID } from 'lib/utils/validation-utils.js'; | ||||
import { | import { | ||||
fetchPrimaryInviteLinks, | fetchPrimaryInviteLinks, | ||||
verifyInviteLink, | verifyInviteLink, | ||||
} from '../fetchers/link-fetchers.js'; | } from '../fetchers/link-fetchers.js'; | ||||
import { Viewer } from '../session/viewer.js'; | import { Viewer } from '../session/viewer.js'; | ||||
Show All 30 Lines | ): Promise<InviteLinkVerificationResponse> { | ||||
const response = await verifyInviteLink(viewer, request); | const response = await verifyInviteLink(viewer, request); | ||||
return validateOutput( | return validateOutput( | ||||
viewer.platformDetails, | viewer.platformDetails, | ||||
inviteLinkVerificationResponseValidator, | inviteLinkVerificationResponseValidator, | ||||
response, | response, | ||||
); | ); | ||||
} | } | ||||
export const fetchInviteLinksResponseValidator: TInterface<FetchInviteLinksResponse> = | |||||
tShape<FetchInviteLinksResponse>({ | |||||
links: t.list(inviteLinkValidator), | |||||
}); | |||||
async function fetchPrimaryInviteLinksResponder( | async function fetchPrimaryInviteLinksResponder( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
): Promise<FetchInviteLinksResponse> { | ): Promise<FetchInviteLinksResponse> { | ||||
const primaryLinks = await fetchPrimaryInviteLinks(viewer); | const primaryLinks = await fetchPrimaryInviteLinks(viewer); | ||||
return { | return validateOutput( | ||||
viewer.platformDetails, | |||||
fetchInviteLinksResponseValidator, | |||||
{ | |||||
links: primaryLinks, | links: primaryLinks, | ||||
}; | }, | ||||
); | |||||
} | } | ||||
export { inviteLinkVerificationResponder, fetchPrimaryInviteLinksResponder }; | export { inviteLinkVerificationResponder, fetchPrimaryInviteLinksResponder }; |