@neuralinnovations/dataisland-sdk 0.0.1-dev1 → 0.0.1-dev11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +174 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/package.json +98 -0
- package/dist/src/appBuilder.d.ts +44 -0
- package/dist/src/appBuilder.d.ts.map +1 -0
- package/dist/src/appBuilder.js +10 -0
- package/dist/src/appBuilder.js.map +1 -0
- package/dist/src/commands/startCommandHandler.d.ts +7 -0
- package/dist/src/commands/startCommandHandler.d.ts.map +1 -0
- package/dist/src/commands/startCommandHandler.js +17 -0
- package/dist/src/commands/startCommandHandler.js.map +1 -0
- package/dist/src/context.d.ts +23 -0
- package/dist/src/context.d.ts.map +1 -0
- package/dist/src/context.js +31 -0
- package/dist/src/context.js.map +1 -0
- package/dist/src/credentials.d.ts +28 -0
- package/dist/src/credentials.d.ts.map +1 -0
- package/dist/src/credentials.js +70 -0
- package/dist/src/credentials.js.map +1 -0
- package/dist/src/dataIslandApp.d.ts +50 -0
- package/dist/src/dataIslandApp.d.ts.map +1 -0
- package/dist/src/dataIslandApp.js +10 -0
- package/dist/src/dataIslandApp.js.map +1 -0
- package/dist/src/disposable.d.ts +84 -0
- package/dist/src/disposable.d.ts.map +1 -0
- package/dist/src/disposable.js +140 -0
- package/dist/src/disposable.js.map +1 -0
- package/dist/src/dto/accessGroupResponse.d.ts +27 -0
- package/dist/src/dto/accessGroupResponse.d.ts.map +1 -0
- package/dist/src/dto/accessGroupResponse.js +3 -0
- package/dist/src/dto/accessGroupResponse.js.map +1 -0
- package/dist/src/dto/chatResponse.d.ts +78 -0
- package/dist/src/dto/chatResponse.d.ts.map +1 -0
- package/dist/src/dto/chatResponse.js +45 -0
- package/dist/src/dto/chatResponse.js.map +1 -0
- package/dist/src/dto/userInfoResponse.d.ts +40 -0
- package/dist/src/dto/userInfoResponse.d.ts.map +1 -0
- package/dist/src/dto/userInfoResponse.js +3 -0
- package/dist/src/dto/userInfoResponse.js.map +1 -0
- package/dist/src/dto/workspacesResponse.d.ts +43 -0
- package/dist/src/dto/workspacesResponse.d.ts.map +1 -0
- package/dist/src/dto/workspacesResponse.js +3 -0
- package/dist/src/dto/workspacesResponse.js.map +1 -0
- package/dist/src/events.d.ts +17 -0
- package/dist/src/events.d.ts.map +1 -0
- package/dist/src/events.js +52 -0
- package/dist/src/events.js.map +1 -0
- package/dist/src/index.d.ts +56 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +89 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/internal/app.impl.d.ts +28 -0
- package/dist/src/internal/app.impl.d.ts.map +1 -0
- package/dist/src/internal/app.impl.js +151 -0
- package/dist/src/internal/app.impl.js.map +1 -0
- package/dist/src/internal/appBuilder.impl.d.ts +27 -0
- package/dist/src/internal/appBuilder.impl.d.ts.map +1 -0
- package/dist/src/internal/appBuilder.impl.js +71 -0
- package/dist/src/internal/appBuilder.impl.js.map +1 -0
- package/dist/src/internal/createApp.impl.d.ts +4 -0
- package/dist/src/internal/createApp.impl.d.ts.map +1 -0
- package/dist/src/internal/createApp.impl.js +11 -0
- package/dist/src/internal/createApp.impl.js.map +1 -0
- package/dist/src/internal/registry.d.ts +22 -0
- package/dist/src/internal/registry.d.ts.map +1 -0
- package/dist/src/internal/registry.js +69 -0
- package/dist/src/internal/registry.js.map +1 -0
- package/dist/src/middleware.d.ts +5 -0
- package/dist/src/middleware.d.ts.map +1 -0
- package/dist/src/middleware.js +3 -0
- package/dist/src/middleware.js.map +1 -0
- package/dist/src/services/commandService.d.ts +18 -0
- package/dist/src/services/commandService.d.ts.map +1 -0
- package/dist/src/services/commandService.js +40 -0
- package/dist/src/services/commandService.js.map +1 -0
- package/dist/src/services/credentialService.d.ts +9 -0
- package/dist/src/services/credentialService.d.ts.map +1 -0
- package/dist/src/services/credentialService.js +26 -0
- package/dist/src/services/credentialService.js.map +1 -0
- package/dist/src/services/middlewareService.d.ts +9 -0
- package/dist/src/services/middlewareService.d.ts.map +1 -0
- package/dist/src/services/middlewareService.js +34 -0
- package/dist/src/services/middlewareService.js.map +1 -0
- package/dist/src/services/organizationService.d.ts +10 -0
- package/dist/src/services/organizationService.d.ts.map +1 -0
- package/dist/src/services/organizationService.js +19 -0
- package/dist/src/services/organizationService.js.map +1 -0
- package/dist/src/services/requestBuilder.d.ts +17 -0
- package/dist/src/services/requestBuilder.d.ts.map +1 -0
- package/dist/src/services/requestBuilder.js +104 -0
- package/dist/src/services/requestBuilder.js.map +1 -0
- package/dist/src/services/responseUtils.d.ts +6 -0
- package/dist/src/services/responseUtils.d.ts.map +1 -0
- package/dist/src/services/responseUtils.js +32 -0
- package/dist/src/services/responseUtils.js.map +1 -0
- package/dist/src/services/rpcService.d.ts +77 -0
- package/dist/src/services/rpcService.d.ts.map +1 -0
- package/dist/src/services/rpcService.js +125 -0
- package/dist/src/services/rpcService.js.map +1 -0
- package/dist/src/services/service.d.ts +21 -0
- package/dist/src/services/service.d.ts.map +1 -0
- package/dist/src/services/service.js +41 -0
- package/dist/src/services/service.js.map +1 -0
- package/dist/src/services/userProfileService.d.ts +8 -0
- package/dist/src/services/userProfileService.d.ts.map +1 -0
- package/dist/src/services/userProfileService.js +32 -0
- package/dist/src/services/userProfileService.js.map +1 -0
- package/dist/src/storages/chats/answer.d.ts +30 -0
- package/dist/src/storages/chats/answer.d.ts.map +1 -0
- package/dist/src/storages/chats/answer.impl.d.ts +23 -0
- package/dist/src/storages/chats/answer.impl.d.ts.map +1 -0
- package/dist/src/storages/chats/answer.impl.js +110 -0
- package/dist/src/storages/chats/answer.impl.js.map +1 -0
- package/dist/src/storages/chats/answer.js +7 -0
- package/dist/src/storages/chats/answer.js.map +1 -0
- package/dist/src/storages/chats/chat.d.ts +30 -0
- package/dist/src/storages/chats/chat.d.ts.map +1 -0
- package/dist/src/storages/chats/chat.impl.d.ts +22 -0
- package/dist/src/storages/chats/chat.impl.d.ts.map +1 -0
- package/dist/src/storages/chats/chat.impl.js +67 -0
- package/dist/src/storages/chats/chat.impl.js.map +1 -0
- package/dist/src/storages/chats/chat.js +12 -0
- package/dist/src/storages/chats/chat.js.map +1 -0
- package/dist/src/storages/chats/chats.d.ts +40 -0
- package/dist/src/storages/chats/chats.d.ts.map +1 -0
- package/dist/src/storages/chats/chats.impl.d.ts +18 -0
- package/dist/src/storages/chats/chats.impl.d.ts.map +1 -0
- package/dist/src/storages/chats/chats.impl.js +102 -0
- package/dist/src/storages/chats/chats.impl.js.map +1 -0
- package/dist/src/storages/chats/chats.js +16 -0
- package/dist/src/storages/chats/chats.js.map +1 -0
- package/dist/src/storages/files/file.d.ts +24 -0
- package/dist/src/storages/files/file.d.ts.map +1 -0
- package/dist/src/storages/files/file.impl.d.ts +18 -0
- package/dist/src/storages/files/file.impl.d.ts.map +1 -0
- package/dist/src/storages/files/file.impl.js +52 -0
- package/dist/src/storages/files/file.impl.js.map +1 -0
- package/dist/src/storages/files/file.js +10 -0
- package/dist/src/storages/files/file.js.map +1 -0
- package/dist/src/storages/files/files.d.ts +33 -0
- package/dist/src/storages/files/files.d.ts.map +1 -0
- package/dist/src/storages/files/files.impl.d.ts +33 -0
- package/dist/src/storages/files/files.impl.d.ts.map +1 -0
- package/dist/src/storages/files/files.impl.js +159 -0
- package/dist/src/storages/files/files.impl.js.map +1 -0
- package/dist/src/storages/files/files.js +19 -0
- package/dist/src/storages/files/files.js.map +1 -0
- package/dist/src/storages/files/filesPage.d.ts +23 -0
- package/dist/src/storages/files/filesPage.d.ts.map +1 -0
- package/dist/src/storages/files/filesPage.js +10 -0
- package/dist/src/storages/files/filesPage.js.map +1 -0
- package/dist/src/storages/groups/groups.d.ts +87 -0
- package/dist/src/storages/groups/groups.d.ts.map +1 -0
- package/dist/src/storages/groups/groups.impl.d.ts +55 -0
- package/dist/src/storages/groups/groups.impl.d.ts.map +1 -0
- package/dist/src/storages/groups/groups.impl.js +245 -0
- package/dist/src/storages/groups/groups.impl.js.map +1 -0
- package/dist/src/storages/groups/groups.js +26 -0
- package/dist/src/storages/groups/groups.js.map +1 -0
- package/dist/src/storages/organizations/organization.d.ts +38 -0
- package/dist/src/storages/organizations/organization.d.ts.map +1 -0
- package/dist/src/storages/organizations/organization.impl.d.ts +30 -0
- package/dist/src/storages/organizations/organization.impl.d.ts.map +1 -0
- package/dist/src/storages/organizations/organization.impl.js +71 -0
- package/dist/src/storages/organizations/organization.impl.js.map +1 -0
- package/dist/src/storages/organizations/organization.js +10 -0
- package/dist/src/storages/organizations/organization.js.map +1 -0
- package/dist/src/storages/organizations/organizations.d.ts +46 -0
- package/dist/src/storages/organizations/organizations.d.ts.map +1 -0
- package/dist/src/storages/organizations/organizations.impl.d.ts +38 -0
- package/dist/src/storages/organizations/organizations.impl.d.ts.map +1 -0
- package/dist/src/storages/organizations/organizations.impl.js +151 -0
- package/dist/src/storages/organizations/organizations.impl.js.map +1 -0
- package/dist/src/storages/organizations/organizations.js +20 -0
- package/dist/src/storages/organizations/organizations.js.map +1 -0
- package/dist/src/storages/user/userProfile.d.ts +32 -0
- package/dist/src/storages/user/userProfile.d.ts.map +1 -0
- package/dist/src/storages/user/userProfile.impl.d.ts +13 -0
- package/dist/src/storages/user/userProfile.impl.d.ts.map +1 -0
- package/dist/src/storages/user/userProfile.impl.js +51 -0
- package/dist/src/storages/user/userProfile.impl.js.map +1 -0
- package/dist/src/storages/user/userProfile.js +12 -0
- package/dist/src/storages/user/userProfile.js.map +1 -0
- package/dist/src/storages/workspaces/workspace.d.ts +40 -0
- package/dist/src/storages/workspaces/workspace.d.ts.map +1 -0
- package/dist/src/storages/workspaces/workspace.impl.d.ts +22 -0
- package/dist/src/storages/workspaces/workspace.impl.d.ts.map +1 -0
- package/dist/src/storages/workspaces/workspace.impl.js +87 -0
- package/dist/src/storages/workspaces/workspace.impl.js.map +1 -0
- package/dist/src/storages/workspaces/workspace.js +18 -0
- package/dist/src/storages/workspaces/workspace.js.map +1 -0
- package/dist/src/storages/workspaces/workspaces.d.ts +47 -0
- package/dist/src/storages/workspaces/workspaces.d.ts.map +1 -0
- package/dist/src/storages/workspaces/workspaces.impl.d.ts +33 -0
- package/dist/src/storages/workspaces/workspaces.impl.d.ts.map +1 -0
- package/dist/src/storages/workspaces/workspaces.impl.js +157 -0
- package/dist/src/storages/workspaces/workspaces.impl.js.map +1 -0
- package/dist/src/storages/workspaces/workspaces.js +19 -0
- package/dist/src/storages/workspaces/workspaces.js.map +1 -0
- package/dist/src/unitTest.d.ts +12 -0
- package/dist/src/unitTest.d.ts.map +1 -0
- package/dist/src/unitTest.js +44 -0
- package/dist/src/unitTest.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +41 -3
- package/src/appBuilder.ts +24 -5
- package/src/commands/startCommandHandler.ts +14 -0
- package/src/context.ts +32 -0
- package/src/credentials.ts +31 -9
- package/src/dataIslandApp.ts +59 -0
- package/src/disposable.ts +4 -5
- package/src/dto/accessGroupResponse.ts +35 -0
- package/src/dto/chatResponse.ts +103 -0
- package/src/dto/userInfoResponse.ts +47 -0
- package/src/dto/workspacesResponse.ts +49 -0
- package/src/events.ts +13 -17
- package/src/index.ts +44 -18
- package/src/internal/app.impl.ts +97 -32
- package/src/internal/appBuilder.impl.ts +39 -12
- package/src/internal/createApp.impl.ts +5 -5
- package/src/middleware.ts +1 -1
- package/src/services/commandService.ts +44 -0
- package/src/services/credentialService.ts +3 -3
- package/src/services/middlewareService.ts +8 -6
- package/src/services/organizationService.ts +28 -0
- package/src/services/requestBuilder.ts +127 -0
- package/src/services/responseUtils.ts +32 -0
- package/src/services/rpcService.ts +129 -52
- package/src/services/service.ts +10 -8
- package/src/services/userProfileService.ts +38 -0
- package/src/storages/chats/answer.impl.ts +163 -0
- package/src/storages/chats/answer.ts +42 -0
- package/src/storages/chats/chat.impl.ts +87 -0
- package/src/storages/chats/chat.ts +38 -0
- package/src/storages/chats/chats.impl.ts +142 -0
- package/src/storages/chats/chats.ts +47 -0
- package/src/storages/files/file.impl.ts +69 -0
- package/src/storages/files/file.ts +28 -0
- package/src/storages/files/files.impl.ts +213 -0
- package/src/storages/files/files.ts +38 -0
- package/src/storages/files/filesPage.ts +27 -0
- package/src/storages/groups/groups.impl.ts +326 -0
- package/src/storages/groups/groups.ts +101 -0
- package/src/storages/organizations/organization.impl.ts +95 -0
- package/src/storages/organizations/organization.ts +44 -0
- package/src/storages/organizations/organizations.impl.ts +197 -0
- package/src/storages/organizations/organizations.ts +56 -0
- package/src/storages/user/userProfile.impl.ts +56 -0
- package/src/storages/user/userProfile.ts +42 -0
- package/src/storages/workspaces/workspace.impl.ts +109 -0
- package/src/storages/workspaces/workspace.ts +49 -0
- package/src/storages/workspaces/workspaces.impl.ts +212 -0
- package/src/storages/workspaces/workspaces.ts +53 -0
- package/src/unitTest.ts +53 -0
- package/.browserslistrc +0 -5
- package/.editorconfig +0 -22
- package/.eslintrc.json +0 -44
- package/.github/workflows/publish-npm.yml +0 -28
- package/.prettierignore +0 -1
- package/.prettierrc +0 -11
- package/.yarnrc +0 -2
- package/babel.config.js +0 -6
- package/jest.config.ts +0 -199
- package/src/appSdk.ts +0 -40
- package/src/internal/context.ts +0 -13
- package/src/types.ts +0 -110
- package/test/disposable.test.ts +0 -39
- package/test/events.test.ts +0 -151
- package/test/index.test.ts +0 -83
- package/test/registry.test.ts +0 -44
- package/tsconfig.json +0 -31
@@ -0,0 +1,213 @@
|
|
1
|
+
import { Context } from "../../context"
|
2
|
+
import { Disposable } from "../../disposable"
|
3
|
+
import { FileDto, FileListResponse } from "../../dto/workspacesResponse"
|
4
|
+
import { RpcService } from "../../services/rpcService"
|
5
|
+
import { FileImpl } from "./file.impl"
|
6
|
+
import { Files, FilesEvent, UploadFile } from "./files"
|
7
|
+
import { WorkspaceImpl } from "../workspaces/workspace.impl"
|
8
|
+
import { ResponseUtils } from "../../services/responseUtils"
|
9
|
+
import { File } from "./file"
|
10
|
+
import { FilesPage } from "./filesPage"
|
11
|
+
|
12
|
+
export class FilesPageImpl extends FilesPage implements Disposable {
|
13
|
+
private _isDisposed: boolean = false
|
14
|
+
|
15
|
+
public files: File[] = []
|
16
|
+
public total: number = 0
|
17
|
+
public filesPerPage: number = 0
|
18
|
+
public page: number = 0
|
19
|
+
|
20
|
+
get pages(): number {
|
21
|
+
return Math.ceil(Math.max(this.total / this.filesPerPage, 1.0))
|
22
|
+
}
|
23
|
+
|
24
|
+
get isDisposed(): boolean {
|
25
|
+
return this._isDisposed
|
26
|
+
}
|
27
|
+
|
28
|
+
dispose(): void {
|
29
|
+
this._isDisposed = true
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
export class FilesImpl extends Files {
|
34
|
+
constructor(
|
35
|
+
private readonly workspace: WorkspaceImpl,
|
36
|
+
private readonly context: Context
|
37
|
+
) {
|
38
|
+
super()
|
39
|
+
}
|
40
|
+
|
41
|
+
// Object used as files page data, returned by "query"
|
42
|
+
public filesList?: FilesPage
|
43
|
+
|
44
|
+
async upload(file: any): Promise<File> {
|
45
|
+
return await this.internalUpload(file)
|
46
|
+
}
|
47
|
+
|
48
|
+
async delete(id: string): Promise<void> {
|
49
|
+
return await this.internalDeleteFile(id)
|
50
|
+
}
|
51
|
+
|
52
|
+
async query(query: string, page: number, limit: number): Promise<FilesPage> {
|
53
|
+
return await this.internalQuery(query, page, limit)
|
54
|
+
}
|
55
|
+
|
56
|
+
//----------------------------------------------------------------------------
|
57
|
+
// INTERNALS
|
58
|
+
//----------------------------------------------------------------------------
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Delete organization.
|
62
|
+
* @param id
|
63
|
+
*/
|
64
|
+
async internalDeleteFile(id: string): Promise<void> {
|
65
|
+
if (id === undefined || id === null) {
|
66
|
+
throw new Error("File delete, id is undefined or null")
|
67
|
+
}
|
68
|
+
if (id.length === 0 || id.trim().length === 0) {
|
69
|
+
throw new Error("File delete, id is empty")
|
70
|
+
}
|
71
|
+
|
72
|
+
const response = await this.context
|
73
|
+
.resolve(RpcService)
|
74
|
+
?.requestBuilder("/api/v1/Files")
|
75
|
+
.searchParam("id", id)
|
76
|
+
.sendDelete()
|
77
|
+
if (ResponseUtils.isFail(response)) {
|
78
|
+
await ResponseUtils.throwError(`File ${id} delete, failed`, response)
|
79
|
+
}
|
80
|
+
const file = <FileImpl>this.filesList!.files.find(f => f.id === id)
|
81
|
+
const index = this.filesList!.files.indexOf(file)
|
82
|
+
if (index < 0) {
|
83
|
+
throw new Error("Organization delete, index is not found")
|
84
|
+
}
|
85
|
+
|
86
|
+
// remove file from collection
|
87
|
+
this.filesList!.files.splice(index, 1)
|
88
|
+
|
89
|
+
// dispatch event, file removed
|
90
|
+
this.dispatch({
|
91
|
+
type: FilesEvent.REMOVED,
|
92
|
+
data: file
|
93
|
+
})
|
94
|
+
|
95
|
+
// dispose file
|
96
|
+
file.dispose()
|
97
|
+
}
|
98
|
+
|
99
|
+
async internalQuery(
|
100
|
+
query: string,
|
101
|
+
page: number,
|
102
|
+
limit: number
|
103
|
+
): Promise<FilesPage> {
|
104
|
+
|
105
|
+
// check page
|
106
|
+
if (page === undefined || page === null) {
|
107
|
+
throw new Error("File fetch, page is undefined or null")
|
108
|
+
}
|
109
|
+
if (page < 0) {
|
110
|
+
throw new Error("File fetch, page is negative")
|
111
|
+
}
|
112
|
+
|
113
|
+
// check limit
|
114
|
+
if (limit === undefined || limit === null) {
|
115
|
+
throw new Error("File fetch, limit is undefined or null")
|
116
|
+
}
|
117
|
+
if (limit === 0) {
|
118
|
+
throw new Error("File fetch, limit is 0")
|
119
|
+
}
|
120
|
+
|
121
|
+
// send request to the server
|
122
|
+
const response = await this.context
|
123
|
+
.resolve(RpcService)
|
124
|
+
?.requestBuilder("api/v1/Files/list")
|
125
|
+
|
126
|
+
.searchParam("workspaceId", this.workspace.id)
|
127
|
+
.searchParam("organizationId", this.workspace.organization.id)
|
128
|
+
.searchParam("query", query)
|
129
|
+
.searchParam("page", page.toString())
|
130
|
+
.searchParam("limit", limit.toString())
|
131
|
+
.sendGet()
|
132
|
+
|
133
|
+
// check response status
|
134
|
+
if (ResponseUtils.isFail(response)) {
|
135
|
+
await ResponseUtils.throwError(
|
136
|
+
`Files fetch query:${query}, page:${page}, limit:${limit}, failed`,
|
137
|
+
response
|
138
|
+
)
|
139
|
+
}
|
140
|
+
|
141
|
+
// parse files from the server's response
|
142
|
+
const files = (await response!.json()) as FileListResponse
|
143
|
+
|
144
|
+
// create files list
|
145
|
+
const filesList = new FilesPageImpl()
|
146
|
+
filesList.total = files.totalFilesCount
|
147
|
+
filesList.filesPerPage = files.filesPerPage
|
148
|
+
filesList.page = page
|
149
|
+
|
150
|
+
// init files from the server's response
|
151
|
+
for (const fl of files.files) {
|
152
|
+
|
153
|
+
// create file implementation
|
154
|
+
const file = new FileImpl(this.context).initFrom(fl)
|
155
|
+
|
156
|
+
// add file to the collection
|
157
|
+
filesList.files.push(file)
|
158
|
+
|
159
|
+
// dispatch event, file added
|
160
|
+
this.dispatch({
|
161
|
+
type: FilesEvent.ADDED,
|
162
|
+
data: file
|
163
|
+
})
|
164
|
+
}
|
165
|
+
|
166
|
+
// set files list
|
167
|
+
this.filesList = filesList
|
168
|
+
|
169
|
+
return filesList
|
170
|
+
}
|
171
|
+
|
172
|
+
async internalUpload(file: UploadFile): Promise<File> {
|
173
|
+
// check file
|
174
|
+
if (file === undefined || file === null) {
|
175
|
+
throw new Error("File upload, file is undefined or null")
|
176
|
+
}
|
177
|
+
|
178
|
+
// form data to send
|
179
|
+
const form = new FormData()
|
180
|
+
form.append("organizationId", this.workspace.organization.id)
|
181
|
+
form.append("workspaceId", this.workspace.id)
|
182
|
+
form.append("name", file.name)
|
183
|
+
form.append("file", file, file.name)
|
184
|
+
|
185
|
+
// send request to the server
|
186
|
+
const response = await this.context
|
187
|
+
.resolve(RpcService)
|
188
|
+
?.requestBuilder("api/v1/Files")
|
189
|
+
.sendPostFormData(form)
|
190
|
+
|
191
|
+
// check response status
|
192
|
+
if (ResponseUtils.isFail(response)) {
|
193
|
+
await ResponseUtils.throwError(`File upload ${file.name}`, response)
|
194
|
+
}
|
195
|
+
|
196
|
+
// parse file from the server's response
|
197
|
+
const result = (await response!.json()).file as FileDto
|
198
|
+
|
199
|
+
// create file implementation
|
200
|
+
const fileImpl = new FileImpl(this.context).initFrom(result)
|
201
|
+
|
202
|
+
// TODO: why is this here?
|
203
|
+
this.filesList?.files.push(fileImpl)
|
204
|
+
|
205
|
+
// dispatch event, file added
|
206
|
+
this.dispatch({
|
207
|
+
type: FilesEvent.ADDED,
|
208
|
+
data: fileImpl
|
209
|
+
})
|
210
|
+
|
211
|
+
return fileImpl
|
212
|
+
}
|
213
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { EventDispatcher } from "../../events"
|
2
|
+
import { File, FileId } from "./file"
|
3
|
+
import { FilesPage } from "./filesPage"
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Files event.
|
7
|
+
*/
|
8
|
+
export enum FilesEvent {
|
9
|
+
ADDED = "added",
|
10
|
+
REMOVED = "removed"
|
11
|
+
}
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Upload file.
|
15
|
+
*/
|
16
|
+
export type UploadFile = globalThis.File
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Files storage.
|
20
|
+
*/
|
21
|
+
export abstract class Files extends EventDispatcher<FilesEvent, File> {
|
22
|
+
/**
|
23
|
+
* Upload file.
|
24
|
+
*/
|
25
|
+
abstract upload(file: UploadFile): Promise<File>
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Delete file.
|
29
|
+
* @param id
|
30
|
+
*/
|
31
|
+
abstract delete(id: FileId): Promise<void>
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Query files.
|
35
|
+
*/
|
36
|
+
abstract query(query: string, page: number, limit: number): Promise<FilesPage>
|
37
|
+
}
|
38
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { File } from "./file"
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Files page.
|
5
|
+
*/
|
6
|
+
export abstract class FilesPage {
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Get files.
|
10
|
+
*/
|
11
|
+
abstract get files(): File[]
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Get pages count.
|
15
|
+
*/
|
16
|
+
abstract get pages(): number
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Get total count.
|
20
|
+
*/
|
21
|
+
abstract get total(): number
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Get current page.
|
25
|
+
*/
|
26
|
+
abstract get page(): number
|
27
|
+
}
|
@@ -0,0 +1,326 @@
|
|
1
|
+
import { Context } from "../../context"
|
2
|
+
import { Disposable } from "../../disposable"
|
3
|
+
import {
|
4
|
+
AccessGroupDto,
|
5
|
+
AccessGroupResponse,
|
6
|
+
AccessGroupsResponse
|
7
|
+
} from "../../dto/accessGroupResponse"
|
8
|
+
import { UserDto } from "../../dto/userInfoResponse"
|
9
|
+
import { WorkspaceDto, WorkspacesResponse } from "../../dto/workspacesResponse"
|
10
|
+
import { RpcService } from "../../services/rpcService"
|
11
|
+
import { Group, GroupEvent, GroupId, Groups } from "./groups"
|
12
|
+
import { OrganizationImpl } from "../organizations/organization.impl"
|
13
|
+
import { OrganizationId } from "../organizations/organizations"
|
14
|
+
import { ResponseUtils } from "../../services/responseUtils"
|
15
|
+
import { Organization } from "../organizations/organization"
|
16
|
+
|
17
|
+
export class GroupImpl extends Group implements Disposable {
|
18
|
+
private _isDisposed: boolean = false
|
19
|
+
private _content?: AccessGroupDto
|
20
|
+
private _members?: UserDto[]
|
21
|
+
|
22
|
+
constructor(
|
23
|
+
private readonly context: Context,
|
24
|
+
public readonly organization: Organization
|
25
|
+
) {
|
26
|
+
super()
|
27
|
+
}
|
28
|
+
|
29
|
+
async initFrom(id: GroupId): Promise<Group> {
|
30
|
+
// fetch group
|
31
|
+
const response = await this.context.resolve(RpcService)
|
32
|
+
?.requestBuilder("api/v1/AccessGroups")
|
33
|
+
.searchParam("id", id)
|
34
|
+
.sendGet()
|
35
|
+
|
36
|
+
// check response status
|
37
|
+
if (ResponseUtils.isFail(response)) {
|
38
|
+
await ResponseUtils.throwError(`Failed to get group: ${id}, organization: ${this}`, response)
|
39
|
+
}
|
40
|
+
|
41
|
+
// parse group from the server's response
|
42
|
+
const group = (await response!.json()) as AccessGroupResponse
|
43
|
+
|
44
|
+
// init group
|
45
|
+
this._content = group.group
|
46
|
+
this._members = group.members
|
47
|
+
|
48
|
+
return this
|
49
|
+
}
|
50
|
+
|
51
|
+
get id(): GroupId {
|
52
|
+
if (this._content) {
|
53
|
+
return this._content.id
|
54
|
+
}
|
55
|
+
throw new Error("Access group is not loaded.")
|
56
|
+
}
|
57
|
+
|
58
|
+
get group(): AccessGroupDto {
|
59
|
+
if (this._content) {
|
60
|
+
return this._content
|
61
|
+
}
|
62
|
+
throw new Error("Access group is not loaded.")
|
63
|
+
}
|
64
|
+
|
65
|
+
async getWorkspaces(): Promise<WorkspaceDto[]> {
|
66
|
+
// fetch workspaces
|
67
|
+
const response = await this.context.resolve(RpcService)
|
68
|
+
?.requestBuilder("api/v1/Organizations/workspaces")
|
69
|
+
.searchParam("groupId", this.id)
|
70
|
+
.sendGet()
|
71
|
+
|
72
|
+
if (ResponseUtils.isFail(response)) {
|
73
|
+
await ResponseUtils.throwError(`Failed to get workspaces for group: ${this.id}, organization: ${this.organization.id}`, response)
|
74
|
+
}
|
75
|
+
|
76
|
+
// parse workspaces from the server's response
|
77
|
+
const workspaces = (await response!.json()) as WorkspacesResponse
|
78
|
+
|
79
|
+
return workspaces.workspaces
|
80
|
+
}
|
81
|
+
|
82
|
+
get members(): UserDto[] {
|
83
|
+
if (this._members) {
|
84
|
+
return this._members
|
85
|
+
}
|
86
|
+
throw new Error("Access group is not loaded.")
|
87
|
+
}
|
88
|
+
|
89
|
+
async setName(name: string): Promise<void> {
|
90
|
+
if (name === undefined || name === null) {
|
91
|
+
throw new Error("Groups change, name is undefined or null")
|
92
|
+
}
|
93
|
+
if (name.length === 0 || name.trim().length === 0) {
|
94
|
+
throw new Error("Groups change, name is empty")
|
95
|
+
}
|
96
|
+
// send request to the server
|
97
|
+
const response = await this.context
|
98
|
+
.resolve(RpcService)
|
99
|
+
?.requestBuilder("api/v1/AccessGroups/name")
|
100
|
+
.sendPutJson({
|
101
|
+
groupId: this.id,
|
102
|
+
name: name
|
103
|
+
})
|
104
|
+
|
105
|
+
// check response status
|
106
|
+
if (ResponseUtils.isFail(response)) {
|
107
|
+
await ResponseUtils.throwError(`Failed to change group name, group: ${this.id}, organization: ${this.organization.id}`, response)
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
async setPermits(permits: { isAdmin: boolean }): Promise<void> {
|
112
|
+
// send request to the server
|
113
|
+
const response = await this.context
|
114
|
+
.resolve(RpcService)
|
115
|
+
?.requestBuilder("api/v1/AccessGroups/permits")
|
116
|
+
.sendPutJson({
|
117
|
+
groupId: this.id,
|
118
|
+
permits: permits
|
119
|
+
})
|
120
|
+
|
121
|
+
if (ResponseUtils.isFail(response)) {
|
122
|
+
await ResponseUtils.throwError(`Failed to change group permits, group: ${this.id}, organization: ${this.organization.id}`, response)
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
async setWorkspaces(workspaces: string[]): Promise<void> {
|
127
|
+
if (workspaces === null || workspaces === undefined) {
|
128
|
+
throw new Error("Group add workspaces, workspaces is undefined or null")
|
129
|
+
}
|
130
|
+
|
131
|
+
// send request to the server
|
132
|
+
const response = await this.context
|
133
|
+
.resolve(RpcService)
|
134
|
+
?.requestBuilder("api/v1/AccessGroups/workspaces")
|
135
|
+
.sendPutJson({
|
136
|
+
groupId: this.id,
|
137
|
+
actualWorkspaceIds: workspaces
|
138
|
+
})
|
139
|
+
|
140
|
+
if (ResponseUtils.isFail(response)) {
|
141
|
+
await ResponseUtils.throwError(`Failed to set workspaces for group: ${this.id}, organization: ${this.organization.id}`, response)
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
async setMembersIds(members: string[]) {
|
146
|
+
if (members === null || members === undefined) {
|
147
|
+
throw new Error("Group add members, members is undefined or null")
|
148
|
+
}
|
149
|
+
|
150
|
+
// send request to the server
|
151
|
+
const response = await this.context
|
152
|
+
.resolve(RpcService)
|
153
|
+
?.requestBuilder("api/v1/AccessGroups/members")
|
154
|
+
.sendPutJson({
|
155
|
+
groupId: this.id,
|
156
|
+
memberIds: members
|
157
|
+
})
|
158
|
+
|
159
|
+
if (ResponseUtils.isFail(response)) {
|
160
|
+
await ResponseUtils.throwError(`Failed to set members for group: ${this.id}, organization: ${this.organization.id}`, response)
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
get isDisposed(): boolean {
|
165
|
+
return this._isDisposed
|
166
|
+
}
|
167
|
+
|
168
|
+
dispose(): void {
|
169
|
+
this._isDisposed = true
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
export class GroupsImpl extends Groups {
|
174
|
+
|
175
|
+
private _groups: Group[] = []
|
176
|
+
|
177
|
+
constructor(
|
178
|
+
public readonly organization: OrganizationImpl,
|
179
|
+
private readonly context: Context
|
180
|
+
) {
|
181
|
+
super()
|
182
|
+
}
|
183
|
+
|
184
|
+
async initialize() {
|
185
|
+
await this.internalInit()
|
186
|
+
}
|
187
|
+
|
188
|
+
async create(name: string, organizationId: OrganizationId, permits: {
|
189
|
+
isAdmin: boolean
|
190
|
+
}, memberIds: string[]): Promise<Group> {
|
191
|
+
return await this.internalCreate(name, organizationId, permits, memberIds)
|
192
|
+
}
|
193
|
+
|
194
|
+
get(id: GroupId): Group | undefined {
|
195
|
+
return this._groups.find(group => group.id === id)
|
196
|
+
}
|
197
|
+
|
198
|
+
async delete(id: GroupId): Promise<void> {
|
199
|
+
return await this.internalDeleteGroup(id)
|
200
|
+
}
|
201
|
+
|
202
|
+
//----------------------------------------------------------------------------
|
203
|
+
// INTERNALS
|
204
|
+
//----------------------------------------------------------------------------
|
205
|
+
|
206
|
+
/**
|
207
|
+
* Init access groups.
|
208
|
+
*/
|
209
|
+
async internalInit(): Promise<void> {
|
210
|
+
// fetch groups
|
211
|
+
const response = await this.context.resolve(RpcService)
|
212
|
+
?.requestBuilder("api/v1/Organizations/access_groups")
|
213
|
+
.searchParam("id", this.organization.id)
|
214
|
+
.sendGet()
|
215
|
+
|
216
|
+
// check response status
|
217
|
+
if (ResponseUtils.isFail(response)) {
|
218
|
+
await ResponseUtils.throwError(`Failed to get groups for organization: ${this.organization.id}`, response)
|
219
|
+
}
|
220
|
+
|
221
|
+
// parse groups from the server's response
|
222
|
+
const groups = (await response!.json()) as AccessGroupsResponse
|
223
|
+
|
224
|
+
// init groups
|
225
|
+
for (const gr of groups.groups) {
|
226
|
+
// create group implementation
|
227
|
+
const group = await new GroupImpl(this.context, this.organization).initFrom(gr.id)
|
228
|
+
|
229
|
+
// add group to the collection
|
230
|
+
this._groups.push(group)
|
231
|
+
|
232
|
+
// dispatch event
|
233
|
+
this.dispatch({
|
234
|
+
type: GroupEvent.ADDED,
|
235
|
+
data: group
|
236
|
+
})
|
237
|
+
}
|
238
|
+
}
|
239
|
+
|
240
|
+
async internalCreate(name: string, organizationId: OrganizationId, permits: {
|
241
|
+
isAdmin: boolean
|
242
|
+
}, memberIds: string[]): Promise<Group> {
|
243
|
+
if (name === undefined || name === null) {
|
244
|
+
throw new Error("Group create, name is undefined or null")
|
245
|
+
}
|
246
|
+
if (name.length === 0 || name.trim().length === 0) {
|
247
|
+
throw new Error("Group create, name is empty")
|
248
|
+
}
|
249
|
+
|
250
|
+
// send request to the server
|
251
|
+
const response = await this.context
|
252
|
+
.resolve(RpcService)
|
253
|
+
?.requestBuilder("api/v1/AccessGroups")
|
254
|
+
.sendPostJson({
|
255
|
+
name: name,
|
256
|
+
organizationId: organizationId,
|
257
|
+
permits: permits,
|
258
|
+
memberIds: memberIds
|
259
|
+
})
|
260
|
+
|
261
|
+
// check response status
|
262
|
+
if (ResponseUtils.isFail(response)) {
|
263
|
+
await ResponseUtils.throwError(`Failed to create group, organization: ${this.organization.id}`, response)
|
264
|
+
}
|
265
|
+
// parse group from the server's response
|
266
|
+
const content = (await response!.json()) as AccessGroupResponse
|
267
|
+
|
268
|
+
// create group implementation
|
269
|
+
const group = await new GroupImpl(this.context, this.organization).initFrom(content.group.id)
|
270
|
+
|
271
|
+
// add group to the collection
|
272
|
+
this._groups.push(group)
|
273
|
+
|
274
|
+
// dispatch event
|
275
|
+
this.dispatch({
|
276
|
+
type: GroupEvent.ADDED,
|
277
|
+
data: group
|
278
|
+
})
|
279
|
+
|
280
|
+
return group
|
281
|
+
}
|
282
|
+
|
283
|
+
/**
|
284
|
+
* Delete group.
|
285
|
+
* @param id
|
286
|
+
*/
|
287
|
+
async internalDeleteGroup(id: GroupId): Promise<void> {
|
288
|
+
if (id === undefined || id === null) {
|
289
|
+
throw new Error("Group delete, id is undefined or null")
|
290
|
+
}
|
291
|
+
if (id.length === 0 || id.trim().length === 0) {
|
292
|
+
throw new Error("Group delete, id is empty")
|
293
|
+
}
|
294
|
+
|
295
|
+
// send request to the server
|
296
|
+
const response = await this.context
|
297
|
+
.resolve(RpcService)
|
298
|
+
?.requestBuilder("/api/v1/AccessGroups")
|
299
|
+
.searchParam("groupId", id)
|
300
|
+
.sendDelete()
|
301
|
+
|
302
|
+
// check response status
|
303
|
+
if (ResponseUtils.isFail(response)) {
|
304
|
+
await ResponseUtils.throwError(`Failed to delete group: ${id}, organization: ${this.organization.id}`, response)
|
305
|
+
}
|
306
|
+
|
307
|
+
// delete group from collection
|
308
|
+
const group = <GroupImpl>this._groups.find(f => f.id === id)
|
309
|
+
const index = this._groups.indexOf(group)
|
310
|
+
if (index < 0) {
|
311
|
+
throw new Error("Group delete, index is not found")
|
312
|
+
}
|
313
|
+
|
314
|
+
// remove group from collection
|
315
|
+
this._groups.splice(index, 1)
|
316
|
+
|
317
|
+
// dispatch event, group removed
|
318
|
+
this.dispatch({
|
319
|
+
type: GroupEvent.REMOVED,
|
320
|
+
data: group
|
321
|
+
})
|
322
|
+
|
323
|
+
// dispose group
|
324
|
+
group.dispose()
|
325
|
+
}
|
326
|
+
}
|
@@ -0,0 +1,101 @@
|
|
1
|
+
import { AccessGroupDto } from "../../dto/accessGroupResponse"
|
2
|
+
import { UserDto } from "../../dto/userInfoResponse"
|
3
|
+
import { WorkspaceDto } from "../../dto/workspacesResponse"
|
4
|
+
import { EventDispatcher } from "../../events"
|
5
|
+
import { OrganizationId } from "../organizations/organizations"
|
6
|
+
import { Organization } from "../organizations/organization"
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Group id.
|
10
|
+
*/
|
11
|
+
export type GroupId = string
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Group event.
|
15
|
+
*/
|
16
|
+
export enum GroupEvent {
|
17
|
+
ADDED = "added",
|
18
|
+
REMOVED = "removed",
|
19
|
+
UPDATED = "updated"
|
20
|
+
}
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Group.
|
24
|
+
*/
|
25
|
+
export abstract class Group extends EventDispatcher<GroupEvent, Group> {
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Group id.
|
29
|
+
*/
|
30
|
+
abstract get id(): GroupId
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Group information.
|
34
|
+
*/
|
35
|
+
abstract get group(): AccessGroupDto
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Group members.
|
39
|
+
*/
|
40
|
+
abstract get members(): UserDto[]
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Group workspaces.
|
44
|
+
*/
|
45
|
+
abstract getWorkspaces(): Promise<WorkspaceDto[]>
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Set workspaces.
|
49
|
+
*/
|
50
|
+
abstract setWorkspaces(workspaces: string[]): Promise<void>
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Set name.
|
54
|
+
*/
|
55
|
+
abstract setName(name: string): Promise<void>
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Set permits.
|
59
|
+
*/
|
60
|
+
abstract setPermits(permits: { isAdmin: boolean }): Promise<void>
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Set members.
|
64
|
+
*/
|
65
|
+
abstract setMembersIds(members: string[]): Promise<void>
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Groups storage.
|
70
|
+
*/
|
71
|
+
export abstract class Groups extends EventDispatcher<GroupEvent, Group> {
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Organization.
|
75
|
+
*/
|
76
|
+
abstract get organization(): Organization
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Create new group.
|
80
|
+
* @param name
|
81
|
+
* @param organizationId
|
82
|
+
* @param permits
|
83
|
+
* @param memberIds
|
84
|
+
*/
|
85
|
+
abstract create(name: string, organizationId: OrganizationId, permits: {
|
86
|
+
isAdmin: boolean
|
87
|
+
}, memberIds: string[]): Promise<Group>
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Get group by id.
|
91
|
+
* @param id
|
92
|
+
*/
|
93
|
+
abstract get(id: GroupId): Group | undefined
|
94
|
+
|
95
|
+
/**
|
96
|
+
* delete group by id.
|
97
|
+
* @param id
|
98
|
+
*/
|
99
|
+
abstract delete(id: GroupId): Promise<void>
|
100
|
+
|
101
|
+
}
|