chore: remove workspaces from code base (#2220)
This commit is contained in:
@@ -1,10 +0,0 @@
|
|||||||
import { WorkspaceType } from '@standardnotes/common'
|
|
||||||
|
|
||||||
export type Workspace = {
|
|
||||||
uuid: string
|
|
||||||
type: WorkspaceType
|
|
||||||
name: string | null
|
|
||||||
keyRotationIndex: number
|
|
||||||
createdAt: number
|
|
||||||
updatedAt: number
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
export enum WorkspaceApiOperations {
|
|
||||||
Creating,
|
|
||||||
Inviting,
|
|
||||||
Accepting,
|
|
||||||
ListingWorkspaces,
|
|
||||||
ListingWorkspaceUsers,
|
|
||||||
InitiatingKeyshare,
|
|
||||||
}
|
|
||||||
@@ -1,156 +0,0 @@
|
|||||||
import { WorkspaceAccessLevel, WorkspaceType } from '@standardnotes/common'
|
|
||||||
|
|
||||||
import { ErrorMessage } from '../../Error/ErrorMessage'
|
|
||||||
import { ApiCallError } from '../../Error/ApiCallError'
|
|
||||||
import { WorkspaceCreationResponse } from '../../Response/Workspace/WorkspaceCreationResponse'
|
|
||||||
import { WorkspaceInvitationAcceptingResponse } from '../../Response/Workspace/WorkspaceInvitationAcceptingResponse'
|
|
||||||
import { WorkspaceInvitationResponse } from '../../Response/Workspace/WorkspaceInvitationResponse'
|
|
||||||
import { WorkspaceServerInterface } from '../../Server/Workspace/WorkspaceServerInterface'
|
|
||||||
import { WorkspaceListResponse } from '../../Response/Workspace/WorkspaceListResponse'
|
|
||||||
import { WorkspaceUserListResponse } from '../../Response/Workspace/WorkspaceUserListResponse'
|
|
||||||
import { WorkspaceKeyshareInitiatingResponse } from '../../Response/Workspace/WorkspaceKeyshareInitiatingResponse'
|
|
||||||
|
|
||||||
import { WorkspaceApiServiceInterface } from './WorkspaceApiServiceInterface'
|
|
||||||
import { WorkspaceApiOperations } from './WorkspaceApiOperations'
|
|
||||||
|
|
||||||
export class WorkspaceApiService implements WorkspaceApiServiceInterface {
|
|
||||||
private operationsInProgress: Map<WorkspaceApiOperations, boolean>
|
|
||||||
|
|
||||||
constructor(private workspaceServer: WorkspaceServerInterface) {
|
|
||||||
this.operationsInProgress = new Map()
|
|
||||||
}
|
|
||||||
|
|
||||||
async initiateKeyshare(dto: {
|
|
||||||
workspaceUuid: string
|
|
||||||
userUuid: string
|
|
||||||
encryptedWorkspaceKey: string
|
|
||||||
}): Promise<WorkspaceKeyshareInitiatingResponse> {
|
|
||||||
this.lockOperation(WorkspaceApiOperations.InitiatingKeyshare)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.workspaceServer.initiateKeyshare({
|
|
||||||
workspaceUuid: dto.workspaceUuid,
|
|
||||||
userUuid: dto.userUuid,
|
|
||||||
encryptedWorkspaceKey: dto.encryptedWorkspaceKey,
|
|
||||||
})
|
|
||||||
|
|
||||||
this.unlockOperation(WorkspaceApiOperations.InitiatingKeyshare)
|
|
||||||
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
|
||||||
throw new ApiCallError(ErrorMessage.GenericFail)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async listWorkspaceUsers(dto: { workspaceUuid: string }): Promise<WorkspaceUserListResponse> {
|
|
||||||
this.lockOperation(WorkspaceApiOperations.ListingWorkspaceUsers)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.workspaceServer.listWorkspaceUsers({ workspaceUuid: dto.workspaceUuid })
|
|
||||||
|
|
||||||
this.unlockOperation(WorkspaceApiOperations.ListingWorkspaceUsers)
|
|
||||||
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
|
||||||
throw new ApiCallError(ErrorMessage.GenericFail)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async listWorkspaces(): Promise<WorkspaceListResponse> {
|
|
||||||
this.lockOperation(WorkspaceApiOperations.ListingWorkspaces)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.workspaceServer.listWorkspaces({})
|
|
||||||
|
|
||||||
this.unlockOperation(WorkspaceApiOperations.ListingWorkspaces)
|
|
||||||
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
|
||||||
throw new ApiCallError(ErrorMessage.GenericFail)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async acceptInvite(dto: {
|
|
||||||
inviteUuid: string
|
|
||||||
userUuid: string
|
|
||||||
publicKey: string
|
|
||||||
encryptedPrivateKey: string
|
|
||||||
}): Promise<WorkspaceInvitationAcceptingResponse> {
|
|
||||||
this.lockOperation(WorkspaceApiOperations.Accepting)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.workspaceServer.acceptInvite({
|
|
||||||
encryptedPrivateKey: dto.encryptedPrivateKey,
|
|
||||||
publicKey: dto.publicKey,
|
|
||||||
inviteUuid: dto.inviteUuid,
|
|
||||||
userUuid: dto.userUuid,
|
|
||||||
})
|
|
||||||
|
|
||||||
this.unlockOperation(WorkspaceApiOperations.Accepting)
|
|
||||||
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
|
||||||
throw new ApiCallError(ErrorMessage.GenericFail)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async inviteToWorkspace(dto: {
|
|
||||||
inviteeEmail: string
|
|
||||||
workspaceUuid: string
|
|
||||||
accessLevel: WorkspaceAccessLevel
|
|
||||||
}): Promise<WorkspaceInvitationResponse> {
|
|
||||||
this.lockOperation(WorkspaceApiOperations.Inviting)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.workspaceServer.inviteToWorkspace({
|
|
||||||
inviteeEmail: dto.inviteeEmail,
|
|
||||||
workspaceUuid: dto.workspaceUuid,
|
|
||||||
accessLevel: dto.accessLevel,
|
|
||||||
})
|
|
||||||
|
|
||||||
this.unlockOperation(WorkspaceApiOperations.Inviting)
|
|
||||||
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
|
||||||
throw new ApiCallError(ErrorMessage.GenericFail)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async createWorkspace(dto: {
|
|
||||||
workspaceType: WorkspaceType
|
|
||||||
encryptedWorkspaceKey?: string
|
|
||||||
encryptedPrivateKey?: string
|
|
||||||
publicKey?: string
|
|
||||||
workspaceName?: string
|
|
||||||
}): Promise<WorkspaceCreationResponse> {
|
|
||||||
this.lockOperation(WorkspaceApiOperations.Creating)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.workspaceServer.createWorkspace({
|
|
||||||
workspaceType: dto.workspaceType,
|
|
||||||
encryptedPrivateKey: dto.encryptedPrivateKey,
|
|
||||||
encryptedWorkspaceKey: dto.encryptedWorkspaceKey,
|
|
||||||
publicKey: dto.publicKey,
|
|
||||||
workspaceName: dto.workspaceName,
|
|
||||||
})
|
|
||||||
|
|
||||||
this.unlockOperation(WorkspaceApiOperations.Creating)
|
|
||||||
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
|
||||||
throw new ApiCallError(ErrorMessage.GenericFail)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private lockOperation(operation: WorkspaceApiOperations): void {
|
|
||||||
if (this.operationsInProgress.get(operation)) {
|
|
||||||
throw new ApiCallError(ErrorMessage.GenericInProgress)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.operationsInProgress.set(operation, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
private unlockOperation(operation: WorkspaceApiOperations): void {
|
|
||||||
this.operationsInProgress.set(operation, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import { WorkspaceAccessLevel, WorkspaceType } from '@standardnotes/common'
|
|
||||||
|
|
||||||
import { WorkspaceKeyshareInitiatingResponse } from '../../Response/Workspace/WorkspaceKeyshareInitiatingResponse'
|
|
||||||
import { WorkspaceCreationResponse } from '../../Response/Workspace/WorkspaceCreationResponse'
|
|
||||||
import { WorkspaceInvitationAcceptingResponse } from '../../Response/Workspace/WorkspaceInvitationAcceptingResponse'
|
|
||||||
import { WorkspaceInvitationResponse } from '../../Response/Workspace/WorkspaceInvitationResponse'
|
|
||||||
import { WorkspaceListResponse } from '../../Response/Workspace/WorkspaceListResponse'
|
|
||||||
import { WorkspaceUserListResponse } from '../../Response/Workspace/WorkspaceUserListResponse'
|
|
||||||
|
|
||||||
export interface WorkspaceApiServiceInterface {
|
|
||||||
createWorkspace(dto: {
|
|
||||||
workspaceType: WorkspaceType
|
|
||||||
encryptedWorkspaceKey?: string
|
|
||||||
encryptedPrivateKey?: string
|
|
||||||
publicKey?: string
|
|
||||||
workspaceName?: string
|
|
||||||
}): Promise<WorkspaceCreationResponse>
|
|
||||||
inviteToWorkspace(dto: {
|
|
||||||
inviteeEmail: string
|
|
||||||
workspaceUuid: string
|
|
||||||
accessLevel: WorkspaceAccessLevel
|
|
||||||
}): Promise<WorkspaceInvitationResponse>
|
|
||||||
acceptInvite(dto: {
|
|
||||||
inviteUuid: string
|
|
||||||
userUuid: string
|
|
||||||
publicKey: string
|
|
||||||
encryptedPrivateKey: string
|
|
||||||
}): Promise<WorkspaceInvitationAcceptingResponse>
|
|
||||||
listWorkspaces(): Promise<WorkspaceListResponse>
|
|
||||||
listWorkspaceUsers(dto: { workspaceUuid: string }): Promise<WorkspaceUserListResponse>
|
|
||||||
initiateKeyshare(dto: {
|
|
||||||
workspaceUuid: string
|
|
||||||
userUuid: string
|
|
||||||
encryptedWorkspaceKey: string
|
|
||||||
}): Promise<WorkspaceKeyshareInitiatingResponse>
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import { WorkspaceAccessLevel, WorkspaceUserStatus } from '@standardnotes/common'
|
|
||||||
|
|
||||||
export type WorkspaceUser = {
|
|
||||||
uuid: string
|
|
||||||
accessLevel: WorkspaceAccessLevel
|
|
||||||
userUuid: string
|
|
||||||
userDisplayName: string | null
|
|
||||||
workspaceUuid: string
|
|
||||||
encryptedWorkspaceKey: string | null
|
|
||||||
publicKey: string | null
|
|
||||||
encryptedPrivateKey: string | null
|
|
||||||
status: WorkspaceUserStatus
|
|
||||||
keyRotationIndex: number
|
|
||||||
createdAt: number
|
|
||||||
updatedAt: number
|
|
||||||
}
|
|
||||||
@@ -15,7 +15,3 @@ export * from './User/UserApiService'
|
|||||||
export * from './User/UserApiServiceInterface'
|
export * from './User/UserApiServiceInterface'
|
||||||
export * from './WebSocket/WebSocketApiService'
|
export * from './WebSocket/WebSocketApiService'
|
||||||
export * from './WebSocket/WebSocketApiServiceInterface'
|
export * from './WebSocket/WebSocketApiServiceInterface'
|
||||||
export * from './Workspace/WorkspaceApiService'
|
|
||||||
export * from './Workspace/WorkspaceApiServiceInterface'
|
|
||||||
export * from './Workspace/WorkspaceUser'
|
|
||||||
export * from './Workspace/Workspace'
|
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
import { WorkspaceType } from '@standardnotes/common'
|
|
||||||
|
|
||||||
export type WorkspaceCreationRequestParams = {
|
|
||||||
workspaceType: WorkspaceType
|
|
||||||
encryptedWorkspaceKey?: string
|
|
||||||
encryptedPrivateKey?: string
|
|
||||||
publicKey?: string
|
|
||||||
workspaceName?: string
|
|
||||||
[additionalParam: string]: unknown
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
export type WorkspaceInvitationAcceptingRequestParams = {
|
|
||||||
inviteUuid: string
|
|
||||||
userUuid: string
|
|
||||||
publicKey: string
|
|
||||||
encryptedPrivateKey: string
|
|
||||||
[additionalParam: string]: unknown
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
import { WorkspaceAccessLevel } from '@standardnotes/common'
|
|
||||||
|
|
||||||
export type WorkspaceInvitationRequestParams = {
|
|
||||||
workspaceUuid: string
|
|
||||||
inviteeEmail: string
|
|
||||||
accessLevel: WorkspaceAccessLevel
|
|
||||||
[additionalParam: string]: unknown
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
export type WorkspaceKeyshareInitiatingRequestParams = {
|
|
||||||
userUuid: string
|
|
||||||
workspaceUuid: string
|
|
||||||
encryptedWorkspaceKey: string
|
|
||||||
[additionalParam: string]: unknown
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export type WorkspaceListRequestParams = {
|
|
||||||
[additionalParam: string]: unknown
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
export type WorkspaceUserListRequestParams = {
|
|
||||||
workspaceUuid: string
|
|
||||||
[additionalParam: string]: unknown
|
|
||||||
}
|
|
||||||
@@ -17,9 +17,3 @@ export * from './Subscription/SubscriptionInviteRequestParams'
|
|||||||
export * from './User/UserRegistrationRequestParams'
|
export * from './User/UserRegistrationRequestParams'
|
||||||
export * from './UserRequest/UserRequestRequestParams'
|
export * from './UserRequest/UserRequestRequestParams'
|
||||||
export * from './WebSocket/WebSocketConnectionTokenRequestParams'
|
export * from './WebSocket/WebSocketConnectionTokenRequestParams'
|
||||||
export * from './Workspace/WorkspaceCreationRequestParams'
|
|
||||||
export * from './Workspace/WorkspaceInvitationAcceptingRequestParams'
|
|
||||||
export * from './Workspace/WorkspaceInvitationRequestParams'
|
|
||||||
export * from './Workspace/WorkspaceKeyshareInitiatingRequestParams'
|
|
||||||
export * from './Workspace/WorkspaceListRequestParams'
|
|
||||||
export * from './Workspace/WorkspaceUserListRequestParams'
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
import { Either } from '@standardnotes/common'
|
|
||||||
|
|
||||||
import { HttpErrorResponseBody } from '../../Http/HttpErrorResponseBody'
|
|
||||||
import { HttpResponse } from '../../Http/HttpResponse'
|
|
||||||
import { WorkspaceCreationResponseBody } from './WorkspaceCreationResponseBody'
|
|
||||||
|
|
||||||
export interface WorkspaceCreationResponse extends HttpResponse {
|
|
||||||
data: Either<WorkspaceCreationResponseBody, HttpErrorResponseBody>
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export type WorkspaceCreationResponseBody = {
|
|
||||||
uuid: string
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { Either } from '@standardnotes/common'
|
|
||||||
|
|
||||||
import { HttpErrorResponseBody } from '../../Http/HttpErrorResponseBody'
|
|
||||||
import { HttpResponse } from '../../Http/HttpResponse'
|
|
||||||
import { WorkspaceInvitationAcceptingResponseBody } from './WorkspaceInvitationAcceptingResponseBody'
|
|
||||||
|
|
||||||
export interface WorkspaceInvitationAcceptingResponse extends HttpResponse {
|
|
||||||
data: Either<WorkspaceInvitationAcceptingResponseBody, HttpErrorResponseBody>
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export type WorkspaceInvitationAcceptingResponseBody = {
|
|
||||||
success: boolean
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { Either } from '@standardnotes/common'
|
|
||||||
|
|
||||||
import { HttpErrorResponseBody } from '../../Http/HttpErrorResponseBody'
|
|
||||||
import { HttpResponse } from '../../Http/HttpResponse'
|
|
||||||
import { WorkspaceInvitationResponseBody } from './WorkspaceInvitationResponseBody'
|
|
||||||
|
|
||||||
export interface WorkspaceInvitationResponse extends HttpResponse {
|
|
||||||
data: Either<WorkspaceInvitationResponseBody, HttpErrorResponseBody>
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export type WorkspaceInvitationResponseBody = {
|
|
||||||
uuid: string
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { Either } from '@standardnotes/common'
|
|
||||||
|
|
||||||
import { HttpErrorResponseBody } from '../../Http/HttpErrorResponseBody'
|
|
||||||
import { HttpResponse } from '../../Http/HttpResponse'
|
|
||||||
import { WorkspaceKeyshareInitiatingResponseBody } from './WorkspaceKeyshareInitiatingResponseBody'
|
|
||||||
|
|
||||||
export interface WorkspaceKeyshareInitiatingResponse extends HttpResponse {
|
|
||||||
data: Either<WorkspaceKeyshareInitiatingResponseBody, HttpErrorResponseBody>
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export type WorkspaceKeyshareInitiatingResponseBody = {
|
|
||||||
success: boolean
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { Either } from '@standardnotes/common'
|
|
||||||
|
|
||||||
import { HttpErrorResponseBody } from '../../Http/HttpErrorResponseBody'
|
|
||||||
import { HttpResponse } from '../../Http/HttpResponse'
|
|
||||||
import { WorkspaceListResponseBody } from './WorkspaceListResponseBody'
|
|
||||||
|
|
||||||
export interface WorkspaceListResponse extends HttpResponse {
|
|
||||||
data: Either<WorkspaceListResponseBody, HttpErrorResponseBody>
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
import { Workspace } from './../../Client/Workspace/Workspace'
|
|
||||||
|
|
||||||
export type WorkspaceListResponseBody = {
|
|
||||||
ownedWorkspaces: Array<Workspace>
|
|
||||||
joinedWorkspaces: Array<Workspace>
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { Either } from '@standardnotes/common'
|
|
||||||
|
|
||||||
import { HttpErrorResponseBody } from '../../Http/HttpErrorResponseBody'
|
|
||||||
import { HttpResponse } from '../../Http/HttpResponse'
|
|
||||||
import { WorkspaceUserListResponseBody } from './WorkspaceUserListResponseBody'
|
|
||||||
|
|
||||||
export interface WorkspaceUserListResponse extends HttpResponse {
|
|
||||||
data: Either<WorkspaceUserListResponseBody, HttpErrorResponseBody>
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
import { WorkspaceUser } from './../../Client/Workspace/WorkspaceUser'
|
|
||||||
|
|
||||||
export type WorkspaceUserListResponseBody = {
|
|
||||||
users: Array<WorkspaceUser>
|
|
||||||
}
|
|
||||||
@@ -42,15 +42,3 @@ export * from './UserRequest/UserRequestResponse'
|
|||||||
export * from './UserRequest/UserRequestResponseBody'
|
export * from './UserRequest/UserRequestResponseBody'
|
||||||
export * from './WebSocket/WebSocketConnectionTokenResponse'
|
export * from './WebSocket/WebSocketConnectionTokenResponse'
|
||||||
export * from './WebSocket/WebSocketConnectionTokenResponseBody'
|
export * from './WebSocket/WebSocketConnectionTokenResponseBody'
|
||||||
export * from './Workspace/WorkspaceCreationResponse'
|
|
||||||
export * from './Workspace/WorkspaceCreationResponseBody'
|
|
||||||
export * from './Workspace/WorkspaceInvitationAcceptingResponse'
|
|
||||||
export * from './Workspace/WorkspaceInvitationAcceptingResponseBody'
|
|
||||||
export * from './Workspace/WorkspaceKeyshareInitiatingResponse'
|
|
||||||
export * from './Workspace/WorkspaceKeyshareInitiatingResponseBody'
|
|
||||||
export * from './Workspace/WorkspaceInvitationResponse'
|
|
||||||
export * from './Workspace/WorkspaceInvitationResponseBody'
|
|
||||||
export * from './Workspace/WorkspaceListResponse'
|
|
||||||
export * from './Workspace/WorkspaceListResponseBody'
|
|
||||||
export * from './Workspace/WorkspaceUserListResponse'
|
|
||||||
export * from './Workspace/WorkspaceUserListResponseBody'
|
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
const WorkspacePaths = {
|
|
||||||
createWorkspace: '/v1/workspaces',
|
|
||||||
listWorkspaces: '/v1/workspaces',
|
|
||||||
listWorkspaceUsers: (uuid: string) => `/v1/workspaces/${uuid}/users`,
|
|
||||||
initiateKeyshare: (worksapceUuid: string, userUuid: string) =>
|
|
||||||
`/v1/workspaces/${worksapceUuid}/users/${userUuid}/keyshare`,
|
|
||||||
inviteToWorkspace: (uuid: string) => `/v1/workspaces/${uuid}/invites`,
|
|
||||||
acceptInvite: (uuid: string) => `/v1/invites/${uuid}/accept`,
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Paths = {
|
|
||||||
v1: {
|
|
||||||
...WorkspacePaths,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
import { HttpServiceInterface } from '../../Http/HttpServiceInterface'
|
|
||||||
import { WorkspaceInvitationRequestParams } from '../../Request/Workspace/WorkspaceInvitationRequestParams'
|
|
||||||
import { WorkspaceCreationRequestParams } from '../../Request/Workspace/WorkspaceCreationRequestParams'
|
|
||||||
import { WorkspaceInvitationResponse } from '../../Response/Workspace/WorkspaceInvitationResponse'
|
|
||||||
import { WorkspaceCreationResponse } from '../../Response/Workspace/WorkspaceCreationResponse'
|
|
||||||
import { WorkspaceInvitationAcceptingRequestParams } from '../../Request/Workspace/WorkspaceInvitationAcceptingRequestParams'
|
|
||||||
import { WorkspaceInvitationAcceptingResponse } from '../../Response/Workspace/WorkspaceInvitationAcceptingResponse'
|
|
||||||
import { WorkspaceListRequestParams } from '../../Request/Workspace/WorkspaceListRequestParams'
|
|
||||||
import { WorkspaceListResponse } from '../../Response/Workspace/WorkspaceListResponse'
|
|
||||||
import { WorkspaceUserListRequestParams } from '../../Request/Workspace/WorkspaceUserListRequestParams'
|
|
||||||
import { WorkspaceUserListResponse } from '../../Response/Workspace/WorkspaceUserListResponse'
|
|
||||||
import { WorkspaceKeyshareInitiatingRequestParams } from '../../Request/Workspace/WorkspaceKeyshareInitiatingRequestParams'
|
|
||||||
import { WorkspaceKeyshareInitiatingResponse } from '../../Response/Workspace/WorkspaceKeyshareInitiatingResponse'
|
|
||||||
|
|
||||||
import { Paths } from './Paths'
|
|
||||||
import { WorkspaceServerInterface } from './WorkspaceServerInterface'
|
|
||||||
|
|
||||||
export class WorkspaceServer implements WorkspaceServerInterface {
|
|
||||||
constructor(private httpService: HttpServiceInterface) {}
|
|
||||||
|
|
||||||
async initiateKeyshare(
|
|
||||||
params: WorkspaceKeyshareInitiatingRequestParams,
|
|
||||||
): Promise<WorkspaceKeyshareInitiatingResponse> {
|
|
||||||
const response = await this.httpService.post(
|
|
||||||
Paths.v1.initiateKeyshare(params.workspaceUuid, params.userUuid),
|
|
||||||
params,
|
|
||||||
)
|
|
||||||
|
|
||||||
return response as WorkspaceKeyshareInitiatingResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
async listWorkspaceUsers(params: WorkspaceUserListRequestParams): Promise<WorkspaceUserListResponse> {
|
|
||||||
const response = await this.httpService.get(Paths.v1.listWorkspaceUsers(params.workspaceUuid), params)
|
|
||||||
|
|
||||||
return response as WorkspaceUserListResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
async listWorkspaces(params: WorkspaceListRequestParams): Promise<WorkspaceListResponse> {
|
|
||||||
const response = await this.httpService.get(Paths.v1.listWorkspaces, params)
|
|
||||||
|
|
||||||
return response as WorkspaceListResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
async acceptInvite(params: WorkspaceInvitationAcceptingRequestParams): Promise<WorkspaceInvitationAcceptingResponse> {
|
|
||||||
const response = await this.httpService.post(Paths.v1.acceptInvite(params.inviteUuid), params)
|
|
||||||
|
|
||||||
return response as WorkspaceInvitationAcceptingResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
async inviteToWorkspace(params: WorkspaceInvitationRequestParams): Promise<WorkspaceInvitationResponse> {
|
|
||||||
const response = await this.httpService.post(Paths.v1.inviteToWorkspace(params.workspaceUuid), params)
|
|
||||||
|
|
||||||
return response as WorkspaceInvitationResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
async createWorkspace(params: WorkspaceCreationRequestParams): Promise<WorkspaceCreationResponse> {
|
|
||||||
const response = await this.httpService.post(Paths.v1.createWorkspace, params)
|
|
||||||
|
|
||||||
return response as WorkspaceCreationResponse
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
import { WorkspaceInvitationRequestParams } from '../../Request/Workspace/WorkspaceInvitationRequestParams'
|
|
||||||
import { WorkspaceCreationRequestParams } from '../../Request/Workspace/WorkspaceCreationRequestParams'
|
|
||||||
import { WorkspaceInvitationResponse } from '../../Response/Workspace/WorkspaceInvitationResponse'
|
|
||||||
import { WorkspaceCreationResponse } from '../../Response/Workspace/WorkspaceCreationResponse'
|
|
||||||
import { WorkspaceInvitationAcceptingRequestParams } from '../../Request/Workspace/WorkspaceInvitationAcceptingRequestParams'
|
|
||||||
import { WorkspaceInvitationAcceptingResponse } from '../../Response/Workspace/WorkspaceInvitationAcceptingResponse'
|
|
||||||
import { WorkspaceListRequestParams } from '../../Request/Workspace/WorkspaceListRequestParams'
|
|
||||||
import { WorkspaceListResponse } from '../../Response/Workspace/WorkspaceListResponse'
|
|
||||||
import { WorkspaceUserListRequestParams } from '../../Request/Workspace/WorkspaceUserListRequestParams'
|
|
||||||
import { WorkspaceUserListResponse } from '../../Response/Workspace/WorkspaceUserListResponse'
|
|
||||||
import { WorkspaceKeyshareInitiatingRequestParams } from '../../Request/Workspace/WorkspaceKeyshareInitiatingRequestParams'
|
|
||||||
import { WorkspaceKeyshareInitiatingResponse } from '../../Response/Workspace/WorkspaceKeyshareInitiatingResponse'
|
|
||||||
|
|
||||||
export interface WorkspaceServerInterface {
|
|
||||||
createWorkspace(params: WorkspaceCreationRequestParams): Promise<WorkspaceCreationResponse>
|
|
||||||
listWorkspaces(params: WorkspaceListRequestParams): Promise<WorkspaceListResponse>
|
|
||||||
listWorkspaceUsers(params: WorkspaceUserListRequestParams): Promise<WorkspaceUserListResponse>
|
|
||||||
inviteToWorkspace(params: WorkspaceInvitationRequestParams): Promise<WorkspaceInvitationResponse>
|
|
||||||
acceptInvite(params: WorkspaceInvitationAcceptingRequestParams): Promise<WorkspaceInvitationAcceptingResponse>
|
|
||||||
initiateKeyshare(params: WorkspaceKeyshareInitiatingRequestParams): Promise<WorkspaceKeyshareInitiatingResponse>
|
|
||||||
}
|
|
||||||
@@ -12,5 +12,3 @@ export * from './UserRequest/UserRequestServer'
|
|||||||
export * from './UserRequest/UserRequestServerInterface'
|
export * from './UserRequest/UserRequestServerInterface'
|
||||||
export * from './WebSocket/WebSocketServer'
|
export * from './WebSocket/WebSocketServer'
|
||||||
export * from './WebSocket/WebSocketServerInterface'
|
export * from './WebSocket/WebSocketServerInterface'
|
||||||
export * from './Workspace/WorkspaceServer'
|
|
||||||
export * from './Workspace/WorkspaceServerInterface'
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import { ApplicationEventCallback } from '../Event/ApplicationEventCallback'
|
|||||||
import { FeaturesClientInterface } from '../Feature/FeaturesClientInterface'
|
import { FeaturesClientInterface } from '../Feature/FeaturesClientInterface'
|
||||||
import { SubscriptionClientInterface } from '../Subscription/SubscriptionClientInterface'
|
import { SubscriptionClientInterface } from '../Subscription/SubscriptionClientInterface'
|
||||||
import { DeviceInterface } from '../Device/DeviceInterface'
|
import { DeviceInterface } from '../Device/DeviceInterface'
|
||||||
import { WorkspaceClientInterface } from '../Workspace/WorkspaceClientInterface'
|
|
||||||
import { ItemsClientInterface } from '../Item/ItemsClientInterface'
|
import { ItemsClientInterface } from '../Item/ItemsClientInterface'
|
||||||
import { MutatorClientInterface } from '../Mutator/MutatorClientInterface'
|
import { MutatorClientInterface } from '../Mutator/MutatorClientInterface'
|
||||||
import { StorageValueModes } from '../Storage/StorageTypes'
|
import { StorageValueModes } from '../Storage/StorageTypes'
|
||||||
@@ -51,7 +50,6 @@ export interface ApplicationInterface {
|
|||||||
get user(): UserClientInterface
|
get user(): UserClientInterface
|
||||||
get files(): FilesClientInterface
|
get files(): FilesClientInterface
|
||||||
get subscriptions(): SubscriptionClientInterface
|
get subscriptions(): SubscriptionClientInterface
|
||||||
get workspaces(): WorkspaceClientInterface
|
|
||||||
readonly identifier: ApplicationIdentifier
|
readonly identifier: ApplicationIdentifier
|
||||||
readonly platform: Platform
|
readonly platform: Platform
|
||||||
deviceInterface: DeviceInterface
|
deviceInterface: DeviceInterface
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
import { WorkspaceAccessLevel, WorkspaceType } from '@standardnotes/common'
|
|
||||||
import { Workspace, WorkspaceUser } from '@standardnotes/api'
|
|
||||||
|
|
||||||
export interface WorkspaceClientInterface {
|
|
||||||
createWorkspace(dto: {
|
|
||||||
workspaceType: WorkspaceType
|
|
||||||
encryptedWorkspaceKey?: string
|
|
||||||
encryptedPrivateKey?: string
|
|
||||||
publicKey?: string
|
|
||||||
workspaceName?: string
|
|
||||||
}): Promise<{ uuid: string } | null>
|
|
||||||
inviteToWorkspace(dto: {
|
|
||||||
inviteeEmail: string
|
|
||||||
workspaceUuid: string
|
|
||||||
accessLevel: WorkspaceAccessLevel
|
|
||||||
}): Promise<{ uuid: string } | null>
|
|
||||||
acceptInvite(dto: {
|
|
||||||
inviteUuid: string
|
|
||||||
userUuid: string
|
|
||||||
publicKey: string
|
|
||||||
encryptedPrivateKey: string
|
|
||||||
}): Promise<{ success: boolean }>
|
|
||||||
listWorkspaces(): Promise<{ ownedWorkspaces: Array<Workspace>; joinedWorkspaces: Array<Workspace> }>
|
|
||||||
listWorkspaceUsers(dto: { workspaceUuid: string }): Promise<{ users: Array<WorkspaceUser> }>
|
|
||||||
initiateKeyshare(dto: {
|
|
||||||
workspaceUuid: string
|
|
||||||
userUuid: string
|
|
||||||
encryptedWorkspaceKey: string
|
|
||||||
}): Promise<{ success: boolean }>
|
|
||||||
}
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
import { WorkspaceApiServiceInterface, Workspace, WorkspaceUser } from '@standardnotes/api'
|
|
||||||
import { WorkspaceAccessLevel, WorkspaceType } from '@standardnotes/common'
|
|
||||||
import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface'
|
|
||||||
import { AbstractService } from '../Service/AbstractService'
|
|
||||||
import { WorkspaceClientInterface } from './WorkspaceClientInterface'
|
|
||||||
|
|
||||||
export class WorkspaceManager extends AbstractService implements WorkspaceClientInterface {
|
|
||||||
constructor(
|
|
||||||
private workspaceApiService: WorkspaceApiServiceInterface,
|
|
||||||
protected override internalEventBus: InternalEventBusInterface,
|
|
||||||
) {
|
|
||||||
super(internalEventBus)
|
|
||||||
}
|
|
||||||
|
|
||||||
async initiateKeyshare(dto: {
|
|
||||||
workspaceUuid: string
|
|
||||||
userUuid: string
|
|
||||||
encryptedWorkspaceKey: string
|
|
||||||
}): Promise<{ success: boolean }> {
|
|
||||||
try {
|
|
||||||
const result = await this.workspaceApiService.initiateKeyshare(dto)
|
|
||||||
|
|
||||||
if (result.data.error !== undefined) {
|
|
||||||
return { success: false }
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.data
|
|
||||||
} catch (error) {
|
|
||||||
return { success: false }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async listWorkspaceUsers(dto: { workspaceUuid: string }): Promise<{ users: WorkspaceUser[] }> {
|
|
||||||
try {
|
|
||||||
const result = await this.workspaceApiService.listWorkspaceUsers(dto)
|
|
||||||
|
|
||||||
if (result.data.error !== undefined) {
|
|
||||||
return { users: [] }
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.data
|
|
||||||
} catch (error) {
|
|
||||||
return { users: [] }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async listWorkspaces(): Promise<{ ownedWorkspaces: Workspace[]; joinedWorkspaces: Workspace[] }> {
|
|
||||||
try {
|
|
||||||
const result = await this.workspaceApiService.listWorkspaces()
|
|
||||||
|
|
||||||
if (result.data.error !== undefined) {
|
|
||||||
return { ownedWorkspaces: [], joinedWorkspaces: [] }
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.data
|
|
||||||
} catch (error) {
|
|
||||||
return { ownedWorkspaces: [], joinedWorkspaces: [] }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async acceptInvite(dto: {
|
|
||||||
inviteUuid: string
|
|
||||||
userUuid: string
|
|
||||||
publicKey: string
|
|
||||||
encryptedPrivateKey: string
|
|
||||||
}): Promise<{ success: boolean }> {
|
|
||||||
try {
|
|
||||||
const result = await this.workspaceApiService.acceptInvite(dto)
|
|
||||||
|
|
||||||
if (result.data.error !== undefined) {
|
|
||||||
return { success: false }
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.data
|
|
||||||
} catch (error) {
|
|
||||||
return { success: false }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async inviteToWorkspace(dto: {
|
|
||||||
inviteeEmail: string
|
|
||||||
workspaceUuid: string
|
|
||||||
accessLevel: WorkspaceAccessLevel
|
|
||||||
}): Promise<{ uuid: string } | null> {
|
|
||||||
try {
|
|
||||||
const result = await this.workspaceApiService.inviteToWorkspace(dto)
|
|
||||||
|
|
||||||
if (result.data.error !== undefined) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.data
|
|
||||||
} catch (error) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async createWorkspace(dto: {
|
|
||||||
workspaceType: WorkspaceType
|
|
||||||
encryptedWorkspaceKey?: string
|
|
||||||
encryptedPrivateKey?: string
|
|
||||||
publicKey?: string
|
|
||||||
workspaceName?: string
|
|
||||||
}): Promise<{ uuid: string } | null> {
|
|
||||||
try {
|
|
||||||
const result = await this.workspaceApiService.createWorkspace(dto)
|
|
||||||
|
|
||||||
if (result.data.error !== undefined) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.data
|
|
||||||
} catch (error) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -94,5 +94,3 @@ export * from './Sync/SyncServiceInterface'
|
|||||||
export * from './Sync/SyncSource'
|
export * from './Sync/SyncSource'
|
||||||
export * from './User/UserClientInterface'
|
export * from './User/UserClientInterface'
|
||||||
export * from './User/UserService'
|
export * from './User/UserService'
|
||||||
export * from './Workspace/WorkspaceClientInterface'
|
|
||||||
export * from './Workspace/WorkspaceManager'
|
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ import {
|
|||||||
WebSocketApiServiceInterface,
|
WebSocketApiServiceInterface,
|
||||||
WebSocketServer,
|
WebSocketServer,
|
||||||
WebSocketServerInterface,
|
WebSocketServerInterface,
|
||||||
WorkspaceApiService,
|
|
||||||
WorkspaceApiServiceInterface,
|
|
||||||
WorkspaceServer,
|
|
||||||
WorkspaceServerInterface,
|
|
||||||
} from '@standardnotes/api'
|
} from '@standardnotes/api'
|
||||||
import * as Common from '@standardnotes/common'
|
import * as Common from '@standardnotes/common'
|
||||||
import * as ExternalServices from '@standardnotes/services'
|
import * as ExternalServices from '@standardnotes/services'
|
||||||
@@ -57,8 +53,6 @@ import {
|
|||||||
FileService,
|
FileService,
|
||||||
SubscriptionClientInterface,
|
SubscriptionClientInterface,
|
||||||
SubscriptionManager,
|
SubscriptionManager,
|
||||||
WorkspaceClientInterface,
|
|
||||||
WorkspaceManager,
|
|
||||||
ChallengePrompt,
|
ChallengePrompt,
|
||||||
Challenge,
|
Challenge,
|
||||||
ErrorAlertStrings,
|
ErrorAlertStrings,
|
||||||
@@ -155,9 +149,6 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
|||||||
private declare subscriptionApiService: SubscriptionApiServiceInterface
|
private declare subscriptionApiService: SubscriptionApiServiceInterface
|
||||||
private declare subscriptionServer: SubscriptionServerInterface
|
private declare subscriptionServer: SubscriptionServerInterface
|
||||||
private declare subscriptionManager: SubscriptionClientInterface
|
private declare subscriptionManager: SubscriptionClientInterface
|
||||||
private declare workspaceApiService: WorkspaceApiServiceInterface
|
|
||||||
private declare workspaceServer: WorkspaceServerInterface
|
|
||||||
private declare workspaceManager: WorkspaceClientInterface
|
|
||||||
private declare webSocketApiService: WebSocketApiServiceInterface
|
private declare webSocketApiService: WebSocketApiServiceInterface
|
||||||
private declare webSocketServer: WebSocketServerInterface
|
private declare webSocketServer: WebSocketServerInterface
|
||||||
private sessionManager!: InternalServices.SNSessionManager
|
private sessionManager!: InternalServices.SNSessionManager
|
||||||
@@ -275,10 +266,6 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
|||||||
return this.subscriptionManager
|
return this.subscriptionManager
|
||||||
}
|
}
|
||||||
|
|
||||||
get workspaces(): ExternalServices.WorkspaceClientInterface {
|
|
||||||
return this.workspaceManager
|
|
||||||
}
|
|
||||||
|
|
||||||
get signInWithRecoveryCodes(): UseCaseInterface<void> {
|
get signInWithRecoveryCodes(): UseCaseInterface<void> {
|
||||||
return this._signInWithRecoveryCodes
|
return this._signInWithRecoveryCodes
|
||||||
}
|
}
|
||||||
@@ -1184,9 +1171,6 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
|||||||
this.createWebSocketServer()
|
this.createWebSocketServer()
|
||||||
this.createWebSocketApiService()
|
this.createWebSocketApiService()
|
||||||
this.createSubscriptionManager()
|
this.createSubscriptionManager()
|
||||||
this.createWorkspaceServer()
|
|
||||||
this.createWorkspaceApiService()
|
|
||||||
this.createWorkspaceManager()
|
|
||||||
this.createWebSocketsService()
|
this.createWebSocketsService()
|
||||||
this.createSessionManager()
|
this.createSessionManager()
|
||||||
this.createHistoryManager()
|
this.createHistoryManager()
|
||||||
@@ -1235,9 +1219,6 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
|||||||
;(this.subscriptionApiService as unknown) = undefined
|
;(this.subscriptionApiService as unknown) = undefined
|
||||||
;(this.subscriptionServer as unknown) = undefined
|
;(this.subscriptionServer as unknown) = undefined
|
||||||
;(this.subscriptionManager as unknown) = undefined
|
;(this.subscriptionManager as unknown) = undefined
|
||||||
;(this.workspaceApiService as unknown) = undefined
|
|
||||||
;(this.workspaceServer as unknown) = undefined
|
|
||||||
;(this.workspaceManager as unknown) = undefined
|
|
||||||
;(this.webSocketApiService as unknown) = undefined
|
;(this.webSocketApiService as unknown) = undefined
|
||||||
;(this.webSocketServer as unknown) = undefined
|
;(this.webSocketServer as unknown) = undefined
|
||||||
;(this.sessionManager as unknown) = undefined
|
;(this.sessionManager as unknown) = undefined
|
||||||
@@ -1484,18 +1465,6 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
|||||||
this.subscriptionManager = new SubscriptionManager(this.subscriptionApiService, this.internalEventBus)
|
this.subscriptionManager = new SubscriptionManager(this.subscriptionApiService, this.internalEventBus)
|
||||||
}
|
}
|
||||||
|
|
||||||
private createWorkspaceServer() {
|
|
||||||
this.workspaceServer = new WorkspaceServer(this.httpService)
|
|
||||||
}
|
|
||||||
|
|
||||||
private createWorkspaceApiService() {
|
|
||||||
this.workspaceApiService = new WorkspaceApiService(this.workspaceServer)
|
|
||||||
}
|
|
||||||
|
|
||||||
private createWorkspaceManager() {
|
|
||||||
this.workspaceManager = new WorkspaceManager(this.workspaceApiService, this.internalEventBus)
|
|
||||||
}
|
|
||||||
|
|
||||||
private createItemManager() {
|
private createItemManager() {
|
||||||
this.itemManager = new InternalServices.ItemManager(this.payloadManager, this.internalEventBus)
|
this.itemManager = new InternalServices.ItemManager(this.payloadManager, this.internalEventBus)
|
||||||
this.services.push(this.itemManager)
|
this.services.push(this.itemManager)
|
||||||
|
|||||||
@@ -88,7 +88,6 @@
|
|||||||
<script type="module" src="files.test.js"></script>
|
<script type="module" src="files.test.js"></script>
|
||||||
<script type="module" src="session.test.js"></script>
|
<script type="module" src="session.test.js"></script>
|
||||||
<script type="module" src="subscriptions.test.js"></script>
|
<script type="module" src="subscriptions.test.js"></script>
|
||||||
<script type="module" src="workspaces.test.js"></script>
|
|
||||||
<script type="module" src="recovery.test.js"></script>
|
<script type="module" src="recovery.test.js"></script>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
mocha.run();
|
mocha.run();
|
||||||
|
|||||||
@@ -1,103 +0,0 @@
|
|||||||
import * as Factory from './lib/factory.js'
|
|
||||||
chai.use(chaiAsPromised)
|
|
||||||
const expect = chai.expect
|
|
||||||
|
|
||||||
describe.skip('workspaces', function () {
|
|
||||||
this.timeout(Factory.TwentySecondTimeout)
|
|
||||||
|
|
||||||
let ownerContext
|
|
||||||
let owner
|
|
||||||
let inviteeContext
|
|
||||||
let invitee
|
|
||||||
|
|
||||||
afterEach(async function () {
|
|
||||||
await Factory.safeDeinit(ownerContext.application)
|
|
||||||
await Factory.safeDeinit(inviteeContext.application)
|
|
||||||
localStorage.clear()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async function () {
|
|
||||||
localStorage.clear()
|
|
||||||
|
|
||||||
ownerContext = await Factory.createAppContextWithFakeCrypto()
|
|
||||||
await ownerContext.launch()
|
|
||||||
const ownerRegistrationResponse = await ownerContext.register()
|
|
||||||
owner = ownerRegistrationResponse.user
|
|
||||||
|
|
||||||
inviteeContext = await Factory.createAppContextWithFakeCrypto()
|
|
||||||
await inviteeContext.launch()
|
|
||||||
const inviteeRegistrationResponse = await inviteeContext.register()
|
|
||||||
invitee = inviteeRegistrationResponse.user
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should create workspaces for user', async () => {
|
|
||||||
await ownerContext.application.workspaceManager.createWorkspace({
|
|
||||||
workspaceType: 'team',
|
|
||||||
encryptedWorkspaceKey: 'foo',
|
|
||||||
encryptedPrivateKey: 'bar',
|
|
||||||
publicKey: 'buzz',
|
|
||||||
workspaceName: 'Acme Team',
|
|
||||||
})
|
|
||||||
|
|
||||||
await ownerContext.application.workspaceManager.createWorkspace({
|
|
||||||
workspaceType: 'private',
|
|
||||||
encryptedWorkspaceKey: 'foo',
|
|
||||||
encryptedPrivateKey: 'bar',
|
|
||||||
publicKey: 'buzz',
|
|
||||||
})
|
|
||||||
|
|
||||||
const { ownedWorkspaces, joinedWorkspaces } = await ownerContext.application.workspaceManager.listWorkspaces()
|
|
||||||
|
|
||||||
expect(joinedWorkspaces.length).to.equal(0)
|
|
||||||
|
|
||||||
expect(ownedWorkspaces.length).to.equal(2)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should allow inviting and adding users to a workspace', async () => {
|
|
||||||
const { uuid } = await ownerContext.application.workspaceManager.createWorkspace({
|
|
||||||
workspaceType: 'team',
|
|
||||||
encryptedWorkspaceKey: 'foo',
|
|
||||||
encryptedPrivateKey: 'bar',
|
|
||||||
publicKey: 'buzz',
|
|
||||||
workspaceName: 'Acme Team',
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await ownerContext.application.workspaceManager.inviteToWorkspace({
|
|
||||||
inviteeEmail: 'test@standardnotes.com',
|
|
||||||
workspaceUuid: uuid,
|
|
||||||
accessLevel: 'read-only'
|
|
||||||
})
|
|
||||||
|
|
||||||
await inviteeContext.application.workspaceManager.acceptInvite({
|
|
||||||
inviteUuid: result.uuid,
|
|
||||||
userUuid: invitee.uuid,
|
|
||||||
publicKey: 'foobar',
|
|
||||||
encryptedPrivateKey: 'buzz',
|
|
||||||
})
|
|
||||||
|
|
||||||
let listUsersResult = await inviteeContext.application.workspaceManager.listWorkspaceUsers({ workspaceUuid: uuid })
|
|
||||||
let inviteeAssociation = listUsersResult.users.find(user => user.userDisplayName === 'test@standardnotes.com')
|
|
||||||
|
|
||||||
expect(inviteeAssociation.userUuid).to.equal(invitee.uuid)
|
|
||||||
expect(inviteeAssociation.status).to.equal('pending-keyshare')
|
|
||||||
|
|
||||||
await ownerContext.application.workspaceManager.initiateKeyshare({
|
|
||||||
workspaceUuid: inviteeAssociation.workspaceUuid,
|
|
||||||
userUuid: inviteeAssociation.userUuid,
|
|
||||||
encryptedWorkspaceKey: 'foobarbuzz',
|
|
||||||
})
|
|
||||||
|
|
||||||
listUsersResult = await inviteeContext.application.workspaceManager.listWorkspaceUsers({ workspaceUuid: uuid })
|
|
||||||
inviteeAssociation = listUsersResult.users.find(user => user.userDisplayName === 'test@standardnotes.com')
|
|
||||||
|
|
||||||
expect(inviteeAssociation.userUuid).to.equal(invitee.uuid)
|
|
||||||
expect(inviteeAssociation.status).to.equal('active')
|
|
||||||
expect(inviteeAssociation.encryptedWorkspaceKey).to.equal('foobarbuzz')
|
|
||||||
|
|
||||||
const { ownedWorkspaces, joinedWorkspaces } = await inviteeContext.application.workspaceManager.listWorkspaces()
|
|
||||||
|
|
||||||
expect(joinedWorkspaces.length).to.equal(1)
|
|
||||||
|
|
||||||
expect(ownedWorkspaces.length).to.equal(0)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
Reference in New Issue
Block a user