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 { | import { | ||||
type InviteLinkVerificationRequest, | type InviteLinkVerificationRequest, | ||||
type InviteLinkVerificationResponse, | type InviteLinkVerificationResponse, | ||||
type FetchInviteLinksResponse, | type FetchInviteLinksResponse, | ||||
type InviteLink, | |||||
inviteLinkValidator, | inviteLinkValidator, | ||||
type CreateOrUpdatePublicLinkRequest, | |||||
} 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 { createOrUpdatePublicLink } from '../creators/invite-link-creator.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'; | ||||
import { validateInput, validateOutput } from '../utils/validation-utils.js'; | import { validateInput, validateOutput } from '../utils/validation-utils.js'; | ||||
const inviteLinkVerificationRequestInputValidator: TInterface<InviteLinkVerificationRequest> = | const inviteLinkVerificationRequestInputValidator: TInterface<InviteLinkVerificationRequest> = | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | return validateOutput( | ||||
viewer.platformDetails, | viewer.platformDetails, | ||||
fetchInviteLinksResponseValidator, | fetchInviteLinksResponseValidator, | ||||
{ | { | ||||
links: primaryLinks, | links: primaryLinks, | ||||
}, | }, | ||||
); | ); | ||||
} | } | ||||
export { inviteLinkVerificationResponder, fetchPrimaryInviteLinksResponder }; | const createOrUpdatePublicLinkInputValidator: TInterface<CreateOrUpdatePublicLinkRequest> = | ||||
tShape({ | |||||
name: t.String, | |||||
communityID: tID, | |||||
}); | |||||
async function createOrUpdatePublicLinkResponder( | |||||
viewer: Viewer, | |||||
input: mixed, | |||||
): Promise<InviteLink> { | |||||
const request = await validateInput( | |||||
viewer, | |||||
createOrUpdatePublicLinkInputValidator, | |||||
input, | |||||
); | |||||
const response = await createOrUpdatePublicLink(viewer, request); | |||||
return validateOutput(viewer.platformDetails, inviteLinkValidator, response); | |||||
} | |||||
export { | |||||
inviteLinkVerificationResponder, | |||||
fetchPrimaryInviteLinksResponder, | |||||
createOrUpdatePublicLinkResponder, | |||||
}; |