import { WorkspaceEvents } from '@/modules/workspacesCore/domain/events' import { StreamRecord } from '@/modules/core/helpers/types' import { Workspace, WorkspaceAcl, WorkspaceDomain, WorkspaceJoinRequest, WorkspaceJoinRequestStatus, WorkspaceRegionAssignment, WorkspaceWithDomains, WorkspaceWithOptionalRole } from '@/modules/workspacesCore/domain/types' import { EventBusPayloads } from '@/modules/shared/services/eventBus' import { MaybeNullOrUndefined, Nullable, NullableKeysToOptional, Optional, PartialNullable, StreamRoles, WorkspaceRoles } from '@speckle/shared' import { WorkspaceCreationState, WorkspaceRoleToDefaultProjectRoleMapping } from '@/modules/workspaces/domain/types' import { WorkspaceTeam } from '@/modules/workspaces/domain/types' import { Stream } from '@/modules/core/domain/streams/types' import { TokenResourceIdentifier } from '@/modules/core/domain/tokens/types' import { ServerRegion } from '@/modules/multiregion/domain/types' import { SetOptional } from 'type-fest' /** Workspace */ export type UpsertWorkspaceArgs = { workspace: Omit< SetOptional< NullableKeysToOptional, | 'domainBasedMembershipProtectionEnabled' | 'discoverabilityEnabled' | 'defaultProjectRole' | 'slug' >, 'domains' > } export type UpsertWorkspace = (args: UpsertWorkspaceArgs) => Promise export type GetUserDiscoverableWorkspaces = (args: { domains: string[] userId: string }) => Promise[]> export type GetWorkspace = (args: { workspaceId: string userId?: string }) => Promise export type GetWorkspaceBySlug = (args: { workspaceSlug: string userId?: string }) => Promise // Useful for dev purposes (e.g. CLI) export type GetWorkspaceBySlugOrId = (args: { workspaceSlugOrId: string }) => Promise export type GetWorkspaces = (args: { workspaceIds?: string[] userId?: string }) => Promise export type GetWorkspacesBySlug = (args: { workspaceIds: string[] userId?: string }) => Promise export type StoreWorkspaceDomain = (args: { workspaceDomain: WorkspaceDomain }) => Promise export type GetWorkspaceDomains = (args: { workspaceIds: string[] }) => Promise type DeleteWorkspaceArgs = { workspaceId: string } export type CountDomainsByWorkspaceId = (args: { workspaceId: string }) => Promise export type DeleteWorkspaceDomain = (args: { id: string }) => Promise export type GetWorkspaceWithDomains = (args: { id: string }) => Promise export type DeleteWorkspace = (args: DeleteWorkspaceArgs) => Promise type CountWorkspacesArgs = { filter?: { search?: string } } export type QueryWorkspacesArgs = CountWorkspacesArgs & { limit: number cursor?: string } export type QueryWorkspaces = (args: QueryWorkspacesArgs) => Promise export type CountWorkspaces = (args: CountWorkspacesArgs) => Promise /** Workspace Roles */ export type GetWorkspaceCollaboratorsArgs = { workspaceId: string limit: number cursor?: string filter?: { /** * Optionally filter by workspace role(s) */ roles?: WorkspaceRoles[] /** * Optionally filter by user name or email */ search?: string } } export type GetWorkspaceCollaborators = ( args: GetWorkspaceCollaboratorsArgs ) => Promise type GetWorkspaceCollaboratorsTotalCountArgs = { workspaceId: string } export type GetWorkspaceCollaboratorsTotalCount = ( args: GetWorkspaceCollaboratorsTotalCountArgs ) => Promise type DeleteWorkspaceRoleArgs = { workspaceId: string userId: string } export type DeleteWorkspaceRole = ( args: DeleteWorkspaceRoleArgs ) => Promise type GetWorkspaceRolesArgs = { workspaceId: string } /** Get all roles in a given workspaces. */ export type GetWorkspaceRoles = (args: GetWorkspaceRolesArgs) => Promise type GetWorkspaceRoleForUserArgs = { userId: string workspaceId: string } /** Get role for given user in a specific workspace. */ export type GetWorkspaceRoleForUser = ( args: GetWorkspaceRoleForUserArgs ) => Promise type GetWorkspaceRolesForUserArgs = { userId: string } type GetWorkspaceRolesForUserOptions = { /** If provided, limit results to roles in given workspaces. */ workspaceIdFilter?: string[] } /** Get roles for given user across several (or all) workspaces. */ export type GetWorkspaceRolesForUser = ( args: GetWorkspaceRolesForUserArgs, options?: GetWorkspaceRolesForUserOptions ) => Promise /** Repository-level change to workspace acl record */ export type UpsertWorkspaceRole = (args: WorkspaceAcl) => Promise /** Service-level change with protection against invalid role changes */ export type UpdateWorkspaceRole = ( args: Pick & { /** * If this gets triggered from a project role update, we don't want to override that project's role to the default one */ skipProjectRoleUpdatesFor?: string[] /** * Only add or upgrade role, prevent downgrades */ preventRoleDowngrade?: boolean } ) => Promise export type GetWorkspaceRoleToDefaultProjectRoleMapping = (args: { workspaceId: string }) => Promise /** Workspace Projects */ type QueryAllWorkspaceProjectsArgs = { workspaceId: string } export type QueryAllWorkspaceProjects = ( args: QueryAllWorkspaceProjectsArgs ) => AsyncGenerator /** Workspace Project Roles */ type GrantWorkspaceProjectRolesArgs = { projectId: string workspaceId: string } export type GrantWorkspaceProjectRoles = ( args: GrantWorkspaceProjectRolesArgs ) => Promise type UpdateWorkspaceProjectRoleArgs = { role: { projectId: string userId: string // Undefined or null role means delete role role?: Nullable } updater: { userId: string resourceAccessRules: MaybeNullOrUndefined } } export type UpdateWorkspaceProjectRole = ( args: UpdateWorkspaceProjectRoleArgs ) => Promise /** Events */ export type EmitWorkspaceEvent = (args: { eventName: TEvent payload: EventBusPayloads[TEvent] }) => Promise export type CountWorkspaceRoleWithOptionalProjectRole = (args: { workspaceId: string workspaceRole: WorkspaceRoles projectRole?: StreamRoles skipUserIds?: string[] }) => Promise export type GetUserIdsWithRoleInWorkspace = ( args: { workspaceId: string workspaceRole: WorkspaceRoles }, options?: { limit?: number } ) => Promise type WorkspaceUpdateArgs = { workspaceId: string workspaceInput: PartialNullable> } export type UpdateWorkspace = ({ workspaceId, workspaceInput }: WorkspaceUpdateArgs) => Promise /** * Workspace regions */ export type GetAvailableRegions = (params: { workspaceId: string }) => Promise export type AssignWorkspaceRegion = (params: { workspaceId: string regionKey: string }) => Promise export type GetDefaultRegion = (params: { workspaceId: string }) => Promise> export type UpsertRegionAssignment = (params: { workspaceId: string regionKey: string }) => Promise export type GetWorkspaceCreationState = (params: { workspaceId: string }) => Promise export type UpsertWorkspaceCreationState = (params: { workspaceCreationState: WorkspaceCreationState }) => Promise export type UpdateWorkspaceJoinRequestStatus = (params: { workspaceId: string userId: string status: WorkspaceJoinRequestStatus }) => Promise export type CreateWorkspaceJoinRequest = (params: { workspaceJoinRequest: Omit }) => Promise export type SendWorkspaceJoinRequestReceivedEmail = (params: { workspace: Pick requester: { id: string; name: string; email: string } }) => Promise export type SendWorkspaceJoinRequestApprovedEmail = (params: { workspace: Pick requester: { id: string; name: string; email: string } }) => Promise export type SendWorkspaceJoinRequestDeniedEmail = (params: { workspace: Pick requester: { id: string; name: string; email: string } }) => Promise export type GetWorkspaceJoinRequest = ( params: Pick & Partial> ) => Promise export type ApproveWorkspaceJoinRequest = ( params: Pick ) => Promise export type DenyWorkspaceJoinRequest = ( params: Pick ) => Promise /** * Project regions */ /** * Updates project region and moves all regional data to target regional db */ export type UpdateProjectRegion = (params: { projectId: string regionKey: string }) => Promise export type CopyWorkspace = (params: { workspaceId: string }) => Promise export type CopyProjects = (params: { projectIds: string[] }) => Promise export type CopyProjectModels = (params: { projectIds: string[] }) => Promise> export type CopyProjectVersions = (params: { projectIds: string[] }) => Promise> export type CopyProjectObjects = (params: { projectIds: string[] }) => Promise> export type CopyProjectAutomations = (params: { projectIds: string[] }) => Promise>