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, | ||||
type InviteLink, | |||||
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 { 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 All 36 Lines | async function fetchPrimaryInviteLinksResponder( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
): Promise<FetchInviteLinksResponse> { | ): Promise<FetchInviteLinksResponse> { | ||||
const primaryLinks = await fetchPrimaryInviteLinks(viewer); | const primaryLinks = await fetchPrimaryInviteLinks(viewer); | ||||
return { | return { | ||||
links: primaryLinks, | links: primaryLinks, | ||||
}; | }; | ||||
} | } | ||||
export { inviteLinkVerificationResponder, fetchPrimaryInviteLinksResponder }; | const createOrUpdatePublicLinkInputValidator = tShape({ | ||||
name: t.String, | |||||
communityID: tID, | |||||
}); | |||||
async function createOrUpdatePublicLinkResponder( | |||||
viewer: Viewer, | |||||
input: any, | |||||
): 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, | |||||
}; |