Files
speckle-server/packages/server/modules/core/helpers/routeHelper.ts
T
Iain Sproat ec98f8d4cb chore(fe1): remove deprecated frontend (#3998)
---------

Co-authored-by: Kristaps Fabians Geikins <fabis94@live.com>
2025-02-18 12:36:52 +00:00

59 lines
1.8 KiB
TypeScript

import { InvalidArgumentError } from '@/modules/shared/errors'
import { getFrontendOrigin } 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(workspaceSlug: string): string {
return `/workspaces/${workspaceSlug}`
}
export function getStreamRoute(streamId: string): string {
return `/projects/${streamId}`
}
export function getRegistrationRoute(): string {
return '/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 `/authn/reset-password?token=${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(workspaceSlug?: string) {
const path = workspaceSlug ? `/workspaces/${workspaceSlug}/functions` : '/functions'
return new URL(path, getFrontendOrigin())
}