Files
speckle-server/packages/server/modules/core/helpers/routeHelper.ts
T
Kristaps Fabians Geikins ede566eed9 feat(server): serverInvites refactor + workspace invites CRUD & GQL API (#2530)
* prep for new resources algo

* typescriptifying stuff

* minor types fix

* migrate to resources col

* repo & creation updated, WIP processing/retrieval

* WIP invite processing

* finished finalization refactor

* project invite management

* transformed all invites services

* fixed up projects & core serverinvites resolvers

* test fixes

* WIP workspace create GQL & test

* basic invite creation test works

* a buncha working tests

* more tests

* cancelation tests

* minor invite use refactor

* invite retrieval tasks

* invite use() works as expected

* filtering out broken invites

* enabled invite retrieval by token irregardless of who is it for

* minor adjustments

* tests fix

* test config improvements

* test env adjustment

* extra test case

* making resource access limits harder to ignore

* linter fixes

* eventBus type cleanup

* better generic names

* refactored serverinvites resource migration

* fix(server): better error message in project invite edge case
2024-07-29 14:37:54 +03:00

66 lines
2.1 KiB
TypeScript

import { InvalidArgumentError } from '@/modules/shared/errors'
import { getFrontendOrigin, useNewFrontend } from '@/modules/shared/helpers/envHelper'
import { MaybeNullOrUndefined } from '@/modules/shared/helpers/typeHelper'
/**
* Collection of functions for resolving relative routes from the backend, so that they aren't duplicated
* all over the place
*/
export function getWorkspaceRoute(workspaceId: string): string {
if (!useNewFrontend()) {
// TODO: This should throw, but tests run in FE1 mode, and if we switch FE2 mode on, a bunch of old auth tests fail
return '/'
// throw new LogicError('Workspaces are not supported in the old frontend')
}
return `/workspaces/${workspaceId}`
}
export function getStreamRoute(streamId: string): string {
return useNewFrontend() ? `/projects/${streamId}` : `/streams/${streamId}`
}
export function getRegistrationRoute(): string {
return useNewFrontend() ? `/authn/register` : '/authn/register'
}
export function getCommentRoute(
streamId: string,
commentId: string,
objectOrCommit: {
commitId?: MaybeNullOrUndefined<string>
objectId?: MaybeNullOrUndefined<string>
}
) {
const { commitId, objectId } = objectOrCommit
if (!commitId && !objectId) {
throw new InvalidArgumentError('Either object or commit ID must be specified!')
}
const objectOrCommitPart = commitId ? `commits/${commitId}` : `objects/${objectId}`
return `/streams/${streamId}/${objectOrCommitPart}?cId=${commentId}`
}
export function getPasswordResetFinalizationRoute(tokenId: string): string {
return useNewFrontend()
? `/authn/reset-password?token=${tokenId}`
: `/authn/resetpassword/finalize?t=${tokenId}`
}
export function getEmailVerificationFinalizationRoute(tokenId: string): string {
return `/auth/verifyemail?t=${tokenId}`
}
export function getStreamCollaboratorsRoute(streamId: string): string {
return `${getStreamRoute(streamId)}/collaborators`
}
export function buildAbsoluteFrontendUrlFromPath(route: string): string {
return new URL(route, getFrontendOrigin()).toString()
}
export function getFunctionsMarketplaceUrl() {
return new URL('/functions', getFrontendOrigin())
}