ede566eed9
* 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
84 lines
2.8 KiB
TypeScript
84 lines
2.8 KiB
TypeScript
import { TokenResourceIdentifier } from '@/modules/core/domain/tokens/types'
|
|
import { ServerInfo } from '@/modules/core/helpers/types'
|
|
import { UserWithOptionalRole } from '@/modules/core/repositories/users'
|
|
import { EmailTemplateParams } from '@/modules/emails/services/emailRendering'
|
|
import { CreateInviteParams } from '@/modules/serverinvites/domain/operations'
|
|
import {
|
|
InviteResourceTarget,
|
|
InviteResourceTargetType,
|
|
ServerInviteRecord
|
|
} from '@/modules/serverinvites/domain/types'
|
|
import { ResolvedTargetData } from '@/modules/serverinvites/helpers/core'
|
|
import { MaybeAsync, MaybeNullOrUndefined } from '@speckle/shared'
|
|
|
|
export type InviteResult = {
|
|
inviteId: string
|
|
token: string
|
|
}
|
|
export type CreateAndSendInvite = (
|
|
params: CreateInviteParams,
|
|
inviterResourceAccessLimits: MaybeNullOrUndefined<TokenResourceIdentifier[]>
|
|
) => Promise<InviteResult>
|
|
|
|
export type FinalizeInvite = (params: {
|
|
finalizerUserId: string
|
|
finalizerResourceAccessLimits: MaybeNullOrUndefined<TokenResourceIdentifier[]>
|
|
accept: boolean
|
|
token: string
|
|
resourceType?: InviteResourceTargetType
|
|
}) => Promise<void>
|
|
|
|
export type ResendInviteEmail = (params: { inviteId: string }) => Promise<void>
|
|
|
|
export type CollectAndValidateResourceTargets = (params: {
|
|
input: CreateInviteParams
|
|
inviter: UserWithOptionalRole
|
|
inviterResourceAccessLimits: MaybeNullOrUndefined<TokenResourceIdentifier[]>
|
|
target: ResolvedTargetData
|
|
targetUser: MaybeNullOrUndefined<UserWithOptionalRole>
|
|
serverInfo: ServerInfo
|
|
}) => MaybeAsync<InviteResourceTarget[]>
|
|
|
|
export type BuildInviteEmailContents = (params: {
|
|
invite: ServerInviteRecord
|
|
serverInfo: ServerInfo
|
|
inviter: UserWithOptionalRole
|
|
}) => MaybeAsync<{
|
|
emailParams: EmailTemplateParams
|
|
subject: string
|
|
}>
|
|
|
|
export enum InviteFinalizationAction {
|
|
ACCEPT = 'accept',
|
|
DECLINE = 'decline',
|
|
/**
|
|
* Cancel differs from decline in the way that only the resource owner can cancel the invite,
|
|
* invite target can only decline
|
|
*/
|
|
CANCEL = 'cancel'
|
|
}
|
|
|
|
/**
|
|
* This function should throw if there's validation issue
|
|
*/
|
|
export type ValidateResourceInviteBeforeFinalization = (params: {
|
|
invite: ServerInviteRecord
|
|
finalizerUserId: string
|
|
finalizerResourceAccessLimits: MaybeNullOrUndefined<TokenResourceIdentifier[]>
|
|
action: InviteFinalizationAction
|
|
}) => MaybeAsync<void>
|
|
|
|
/**
|
|
* Actually handle the invite being accepted or declined. The actual invite record
|
|
* is already deleted by this point and doesn't require handling.
|
|
*/
|
|
export type ProcessFinalizedResourceInvite = (params: {
|
|
invite: ServerInviteRecord
|
|
finalizerUserId: string
|
|
action: InviteFinalizationAction.ACCEPT | InviteFinalizationAction.DECLINE
|
|
}) => MaybeAsync<void>
|
|
|
|
export type GetInvitationTargetUsers = (params: {
|
|
invites: ServerInviteRecord[]
|
|
}) => Promise<{ [key: string]: UserWithOptionalRole }>
|