@neuralinnovations/dataisland-sdk 0.0.1-dev8 → 0.0.1-dev9
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/.github/workflows/publish-npm.yml +11 -0
- package/.github/workflows/tests.yml +4 -0
- package/.github/workflows/version.yml +5 -1
- package/README.md +36 -3
- package/docs/classes/BasicCredential.md +1 -1
- package/docs/classes/BearerCredential.md +1 -1
- package/docs/classes/Chat.md +34 -6
- package/docs/classes/Chats.md +87 -1
- package/docs/classes/CredentialBase.md +1 -1
- package/docs/classes/DataIslandApp.md +1 -1
- package/docs/classes/DebugCredential.md +1 -1
- package/docs/classes/DefaultCredential.md +1 -1
- package/docs/classes/DisposableContainer.md +1 -1
- package/docs/classes/EventDispatcher.md +1 -1
- package/docs/classes/File.md +1 -1
- package/docs/classes/Files.md +2 -2
- package/docs/classes/FilesPage.md +1 -1
- package/docs/classes/Group.md +19 -1
- package/docs/classes/Groups.md +27 -3
- package/docs/classes/Lifetime.md +1 -1
- package/docs/classes/Organization.md +37 -1
- package/docs/classes/Organizations.md +1 -1
- package/docs/classes/UserProfile.md +1 -1
- package/docs/classes/Workspace.md +1 -1
- package/docs/classes/Workspaces.md +6 -2
- package/docs/enums/ChatAnswerType.md +22 -0
- package/docs/enums/ChatsEvent.md +1 -1
- package/docs/enums/FilesEvent.md +1 -1
- package/docs/enums/GroupEvent.md +3 -1
- package/docs/enums/OrganizationsEvent.md +1 -1
- package/docs/enums/UserEvent.md +1 -1
- package/docs/enums/WorkspaceEvent.md +1 -1
- package/docs/enums/WorkspacesEvent.md +1 -1
- package/docs/interfaces/Disposable.md +1 -1
- package/docs/interfaces/Event.md +1 -1
- package/docs/interfaces/EventSubscriber.md +1 -1
- package/docs/interfaces/Input.md +1 -1
- package/docs/modules.md +5 -3
- package/package.json +6 -2
- package/src/dataIslandApp.ts +2 -2
- package/src/dto/chatResponse.ts +54 -55
- package/src/dto/workspacesResponse.ts +2 -2
- package/src/index.ts +13 -13
- package/src/internal/app.impl.ts +2 -2
- package/src/services/organizationService.ts +2 -2
- package/src/services/userProfileService.ts +2 -2
- 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/{file.impl.ts → files/file.impl.ts} +5 -5
- package/src/storages/{file.ts → files/file.ts} +1 -1
- package/src/storages/{files.impl.ts → files/files.impl.ts} +6 -6
- package/src/storages/{files.ts → files/files.ts} +2 -2
- package/src/storages/{groups.impl.ts → groups/groups.impl.ts} +86 -97
- package/src/storages/groups/groups.ts +101 -0
- package/src/storages/{organization.impl.ts → organizations/organization.impl.ts} +34 -7
- package/src/storages/{organization.ts → organizations/organization.ts} +13 -2
- package/src/storages/{organizations.impl.ts → organizations/organizations.impl.ts} +10 -4
- package/src/storages/{organizations.ts → organizations/organizations.ts} +1 -1
- package/src/storages/{userProfile.impl.ts → user/userProfile.impl.ts} +1 -1
- package/src/storages/{userProfile.ts → user/userProfile.ts} +1 -1
- package/src/storages/{workspace.impl.ts → workspaces/workspace.impl.ts} +7 -7
- package/src/storages/{workspace.ts → workspaces/workspace.ts} +3 -3
- package/src/storages/{workspaces.impl.ts → workspaces/workspaces.impl.ts} +11 -11
- package/src/storages/{workspaces.ts → workspaces/workspaces.ts} +2 -2
- package/test/chats.test.ts +48 -0
- package/test/organization.test.ts +13 -1
- package/test/setup.ts +7 -0
- package/docs/enums/ChatAnswer.md +0 -22
- package/src/storages/chat.ts +0 -21
- package/src/storages/chats.ts +0 -17
- package/src/storages/groups.ts +0 -43
- /package/src/storages/{filesPage.ts → files/filesPage.ts} +0 -0
@@ -1,12 +1,18 @@
|
|
1
|
-
import { Context } from "
|
2
|
-
import { Disposable } from "
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
6
|
-
|
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"
|
7
11
|
import { Group, GroupEvent, GroupId, Groups } from "./groups"
|
8
|
-
import { OrganizationImpl } from "
|
9
|
-
import { OrganizationId } from "
|
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"
|
10
16
|
|
11
17
|
export class GroupImpl extends Group implements Disposable {
|
12
18
|
private _isDisposed: boolean = false
|
@@ -14,32 +20,28 @@ export class GroupImpl extends Group implements Disposable {
|
|
14
20
|
private _members?: UserDto[]
|
15
21
|
|
16
22
|
constructor(
|
17
|
-
private readonly context: Context
|
23
|
+
private readonly context: Context,
|
24
|
+
public readonly organization: Organization
|
18
25
|
) {
|
19
26
|
super()
|
20
27
|
}
|
21
28
|
|
22
|
-
async initFrom(id: GroupId): Promise<Group>{
|
29
|
+
async initFrom(id: GroupId): Promise<Group> {
|
30
|
+
// fetch group
|
23
31
|
const response = await this.context.resolve(RpcService)
|
24
32
|
?.requestBuilder("api/v1/AccessGroups")
|
25
33
|
.searchParam("id", id)
|
26
34
|
.sendGet()
|
27
35
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
text = (await response?.text()) ?? ""
|
32
|
-
} catch (e) {
|
33
|
-
console.error(e)
|
34
|
-
}
|
35
|
-
|
36
|
-
throw new Error(
|
37
|
-
`Get group, response is not ok, status: ${response?.status},${response?.statusText} ${text}`
|
38
|
-
)
|
36
|
+
// check response status
|
37
|
+
if (ResponseUtils.isFail(response)) {
|
38
|
+
await ResponseUtils.throwError(`Failed to get group: ${id}, organization: ${this}`, response)
|
39
39
|
}
|
40
40
|
|
41
|
-
|
41
|
+
// parse group from the server's response
|
42
|
+
const group = (await response!.json()) as AccessGroupResponse
|
42
43
|
|
44
|
+
// init group
|
43
45
|
this._content = group.group
|
44
46
|
this._members = group.members
|
45
47
|
|
@@ -61,31 +63,24 @@ export class GroupImpl extends Group implements Disposable {
|
|
61
63
|
}
|
62
64
|
|
63
65
|
async getWorkspaces(): Promise<WorkspaceDto[]> {
|
66
|
+
// fetch workspaces
|
64
67
|
const response = await this.context.resolve(RpcService)
|
65
68
|
?.requestBuilder("api/v1/Organizations/workspaces")
|
66
69
|
.searchParam("groupId", this.id)
|
67
70
|
.sendGet()
|
68
71
|
|
69
|
-
if (
|
70
|
-
|
71
|
-
try {
|
72
|
-
text = (await response?.text()) ?? ""
|
73
|
-
} catch (e) {
|
74
|
-
console.error(e)
|
75
|
-
}
|
76
|
-
|
77
|
-
throw new Error(
|
78
|
-
`Groups get workspaces, response is not ok, status: ${response?.status},${response?.statusText} ${text}`
|
79
|
-
)
|
72
|
+
if (ResponseUtils.isFail(response)) {
|
73
|
+
await ResponseUtils.throwError(`Failed to get workspaces for group: ${this.id}, organization: ${this.organization.id}`, response)
|
80
74
|
}
|
81
75
|
|
82
|
-
|
76
|
+
// parse workspaces from the server's response
|
77
|
+
const workspaces = (await response!.json()) as WorkspacesResponse
|
83
78
|
|
84
79
|
return workspaces.workspaces
|
85
80
|
}
|
86
81
|
|
87
82
|
get members(): UserDto[] {
|
88
|
-
if (this._members){
|
83
|
+
if (this._members) {
|
89
84
|
return this._members
|
90
85
|
}
|
91
86
|
throw new Error("Access group is not loaded.")
|
@@ -98,6 +93,7 @@ export class GroupImpl extends Group implements Disposable {
|
|
98
93
|
if (name.length === 0 || name.trim().length === 0) {
|
99
94
|
throw new Error("Groups change, name is empty")
|
100
95
|
}
|
96
|
+
// send request to the server
|
101
97
|
const response = await this.context
|
102
98
|
.resolve(RpcService)
|
103
99
|
?.requestBuilder("api/v1/AccessGroups/name")
|
@@ -106,14 +102,14 @@ export class GroupImpl extends Group implements Disposable {
|
|
106
102
|
name: name
|
107
103
|
})
|
108
104
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
)
|
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)
|
113
108
|
}
|
114
109
|
}
|
115
110
|
|
116
|
-
async setPermits(permits: {isAdmin: boolean})
|
111
|
+
async setPermits(permits: { isAdmin: boolean }): Promise<void> {
|
112
|
+
// send request to the server
|
117
113
|
const response = await this.context
|
118
114
|
.resolve(RpcService)
|
119
115
|
?.requestBuilder("api/v1/AccessGroups/permits")
|
@@ -122,19 +118,17 @@ export class GroupImpl extends Group implements Disposable {
|
|
122
118
|
permits: permits
|
123
119
|
})
|
124
120
|
|
125
|
-
if (
|
126
|
-
|
127
|
-
`Failed to set new permits. ${response?.status}, ${response?.statusText}`
|
128
|
-
)
|
121
|
+
if (ResponseUtils.isFail(response)) {
|
122
|
+
await ResponseUtils.throwError(`Failed to change group permits, group: ${this.id}, organization: ${this.organization.id}`, response)
|
129
123
|
}
|
130
124
|
}
|
131
125
|
|
132
|
-
|
133
126
|
async setWorkspaces(workspaces: string[]): Promise<void> {
|
134
|
-
if (workspaces === null || workspaces === undefined){
|
127
|
+
if (workspaces === null || workspaces === undefined) {
|
135
128
|
throw new Error("Group add workspaces, workspaces is undefined or null")
|
136
129
|
}
|
137
130
|
|
131
|
+
// send request to the server
|
138
132
|
const response = await this.context
|
139
133
|
.resolve(RpcService)
|
140
134
|
?.requestBuilder("api/v1/AccessGroups/workspaces")
|
@@ -143,19 +137,17 @@ export class GroupImpl extends Group implements Disposable {
|
|
143
137
|
actualWorkspaceIds: workspaces
|
144
138
|
})
|
145
139
|
|
146
|
-
if (
|
147
|
-
|
148
|
-
`Failed to set new member Ids. ${response?.status}, ${response?.statusText}`
|
149
|
-
)
|
140
|
+
if (ResponseUtils.isFail(response)) {
|
141
|
+
await ResponseUtils.throwError(`Failed to set workspaces for group: ${this.id}, organization: ${this.organization.id}`, response)
|
150
142
|
}
|
151
143
|
}
|
152
144
|
|
153
|
-
|
154
145
|
async setMembersIds(members: string[]) {
|
155
|
-
if (members === null || members === undefined){
|
146
|
+
if (members === null || members === undefined) {
|
156
147
|
throw new Error("Group add members, members is undefined or null")
|
157
148
|
}
|
158
149
|
|
150
|
+
// send request to the server
|
159
151
|
const response = await this.context
|
160
152
|
.resolve(RpcService)
|
161
153
|
?.requestBuilder("api/v1/AccessGroups/members")
|
@@ -164,12 +156,9 @@ export class GroupImpl extends Group implements Disposable {
|
|
164
156
|
memberIds: members
|
165
157
|
})
|
166
158
|
|
167
|
-
if (
|
168
|
-
|
169
|
-
`Failed to set new member Ids. ${response?.status}, ${response?.statusText}`
|
170
|
-
)
|
159
|
+
if (ResponseUtils.isFail(response)) {
|
160
|
+
await ResponseUtils.throwError(`Failed to set members for group: ${this.id}, organization: ${this.organization.id}`, response)
|
171
161
|
}
|
172
|
-
|
173
162
|
}
|
174
163
|
|
175
164
|
get isDisposed(): boolean {
|
@@ -186,27 +175,30 @@ export class GroupsImpl extends Groups {
|
|
186
175
|
private _groups: Group[] = []
|
187
176
|
|
188
177
|
constructor(
|
189
|
-
|
178
|
+
public readonly organization: OrganizationImpl,
|
190
179
|
private readonly context: Context
|
191
180
|
) {
|
192
181
|
super()
|
193
182
|
}
|
194
183
|
|
195
|
-
async initialize(){
|
184
|
+
async initialize() {
|
196
185
|
await this.internalInit()
|
197
186
|
}
|
198
187
|
|
199
|
-
async create(name: string, organizationId: OrganizationId, permits: {
|
188
|
+
async create(name: string, organizationId: OrganizationId, permits: {
|
189
|
+
isAdmin: boolean
|
190
|
+
}, memberIds: string[]): Promise<Group> {
|
200
191
|
return await this.internalCreate(name, organizationId, permits, memberIds)
|
201
192
|
}
|
202
|
-
|
203
|
-
|
193
|
+
|
194
|
+
get(id: GroupId): Group | undefined {
|
195
|
+
return this._groups.find(group => group.id === id)
|
204
196
|
}
|
197
|
+
|
205
198
|
async delete(id: GroupId): Promise<void> {
|
206
199
|
return await this.internalDeleteGroup(id)
|
207
200
|
}
|
208
201
|
|
209
|
-
|
210
202
|
//----------------------------------------------------------------------------
|
211
203
|
// INTERNALS
|
212
204
|
//----------------------------------------------------------------------------
|
@@ -215,31 +207,29 @@ export class GroupsImpl extends Groups {
|
|
215
207
|
* Init access groups.
|
216
208
|
*/
|
217
209
|
async internalInit(): Promise<void> {
|
210
|
+
// fetch groups
|
218
211
|
const response = await this.context.resolve(RpcService)
|
219
212
|
?.requestBuilder("api/v1/Organizations/access_groups")
|
220
213
|
.searchParam("id", this.organization.id)
|
221
214
|
.sendGet()
|
222
215
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
text = (await response?.text()) ?? ""
|
227
|
-
} catch (e) {
|
228
|
-
console.error(e)
|
229
|
-
}
|
230
|
-
|
231
|
-
throw new Error(
|
232
|
-
`Groups init, response is not ok, status: ${response?.status},${response?.statusText} ${text}`
|
233
|
-
)
|
216
|
+
// check response status
|
217
|
+
if (ResponseUtils.isFail(response)) {
|
218
|
+
await ResponseUtils.throwError(`Failed to get groups for organization: ${this.organization.id}`, response)
|
234
219
|
}
|
235
220
|
|
236
|
-
|
221
|
+
// parse groups from the server's response
|
222
|
+
const groups = (await response!.json()) as AccessGroupsResponse
|
237
223
|
|
238
|
-
|
239
|
-
|
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)
|
240
228
|
|
229
|
+
// add group to the collection
|
241
230
|
this._groups.push(group)
|
242
231
|
|
232
|
+
// dispatch event
|
243
233
|
this.dispatch({
|
244
234
|
type: GroupEvent.ADDED,
|
245
235
|
data: group
|
@@ -247,7 +237,9 @@ export class GroupsImpl extends Groups {
|
|
247
237
|
}
|
248
238
|
}
|
249
239
|
|
250
|
-
async internalCreate(name: string, organizationId: OrganizationId, permits: {
|
240
|
+
async internalCreate(name: string, organizationId: OrganizationId, permits: {
|
241
|
+
isAdmin: boolean
|
242
|
+
}, memberIds: string[]): Promise<Group> {
|
251
243
|
if (name === undefined || name === null) {
|
252
244
|
throw new Error("Group create, name is undefined or null")
|
253
245
|
}
|
@@ -255,6 +247,7 @@ export class GroupsImpl extends Groups {
|
|
255
247
|
throw new Error("Group create, name is empty")
|
256
248
|
}
|
257
249
|
|
250
|
+
// send request to the server
|
258
251
|
const response = await this.context
|
259
252
|
.resolve(RpcService)
|
260
253
|
?.requestBuilder("api/v1/AccessGroups")
|
@@ -265,17 +258,20 @@ export class GroupsImpl extends Groups {
|
|
265
258
|
memberIds: memberIds
|
266
259
|
})
|
267
260
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
)
|
261
|
+
// check response status
|
262
|
+
if (ResponseUtils.isFail(response)) {
|
263
|
+
await ResponseUtils.throwError(`Failed to create group, organization: ${this.organization.id}`, response)
|
272
264
|
}
|
273
|
-
|
265
|
+
// parse group from the server's response
|
266
|
+
const content = (await response!.json()) as AccessGroupResponse
|
274
267
|
|
275
|
-
|
268
|
+
// create group implementation
|
269
|
+
const group = await new GroupImpl(this.context, this.organization).initFrom(content.group.id)
|
276
270
|
|
271
|
+
// add group to the collection
|
277
272
|
this._groups.push(group)
|
278
273
|
|
274
|
+
// dispatch event
|
279
275
|
this.dispatch({
|
280
276
|
type: GroupEvent.ADDED,
|
281
277
|
data: group
|
@@ -296,24 +292,19 @@ export class GroupsImpl extends Groups {
|
|
296
292
|
throw new Error("Group delete, id is empty")
|
297
293
|
}
|
298
294
|
|
295
|
+
// send request to the server
|
299
296
|
const response = await this.context
|
300
297
|
.resolve(RpcService)
|
301
298
|
?.requestBuilder("/api/v1/AccessGroups")
|
302
299
|
.searchParam("groupId", id)
|
303
300
|
.sendDelete()
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
} catch (e) {
|
309
|
-
console.error(e)
|
310
|
-
}
|
311
|
-
|
312
|
-
throw new Error(
|
313
|
-
`Group ${id} delete, response is not ok, status: ${response?.status},${response?.statusText} ${text}`
|
314
|
-
)
|
301
|
+
|
302
|
+
// check response status
|
303
|
+
if (ResponseUtils.isFail(response)) {
|
304
|
+
await ResponseUtils.throwError(`Failed to delete group: ${id}, organization: ${this.organization.id}`, response)
|
315
305
|
}
|
316
306
|
|
307
|
+
// delete group from collection
|
317
308
|
const group = <GroupImpl>this._groups.find(f => f.id === id)
|
318
309
|
const index = this._groups.indexOf(group)
|
319
310
|
if (index < 0) {
|
@@ -332,6 +323,4 @@ export class GroupsImpl extends Groups {
|
|
332
323
|
// dispose group
|
333
324
|
group.dispose()
|
334
325
|
}
|
335
|
-
|
336
|
-
|
337
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
|
+
}
|
@@ -1,12 +1,16 @@
|
|
1
1
|
import { OrganizationId } from "./organizations"
|
2
|
-
import { Disposable } from "
|
3
|
-
import { OrganizationDto } from "
|
4
|
-
import { Workspaces } from "
|
5
|
-
import { WorkspacesImpl } from "
|
6
|
-
import { Context } from "
|
2
|
+
import { Disposable } from "../../disposable"
|
3
|
+
import { OrganizationDto } from "../../dto/userInfoResponse"
|
4
|
+
import { Workspaces } from "../workspaces/workspaces"
|
5
|
+
import { WorkspacesImpl } from "../workspaces/workspaces.impl"
|
6
|
+
import { Context } from "../../context"
|
7
7
|
import { Organization } from "./organization"
|
8
|
-
import { GroupsImpl } from "
|
9
|
-
import { Groups } from "
|
8
|
+
import { GroupsImpl } from "../groups/groups.impl"
|
9
|
+
import { Groups } from "../groups/groups"
|
10
|
+
import { ChatsImpl } from "../chats/chats.impl"
|
11
|
+
import { Chats } from "../chats/chats"
|
12
|
+
import { RpcService } from "../../services/rpcService"
|
13
|
+
import { ResponseUtils } from "../../services/responseUtils"
|
10
14
|
|
11
15
|
export class OrganizationImpl extends Organization implements Disposable {
|
12
16
|
private _isDisposed: boolean = false
|
@@ -14,11 +18,13 @@ export class OrganizationImpl extends Organization implements Disposable {
|
|
14
18
|
private _content?: OrganizationDto
|
15
19
|
private readonly _workspaces: WorkspacesImpl
|
16
20
|
private readonly _accessGroups: GroupsImpl
|
21
|
+
private readonly _chats: ChatsImpl
|
17
22
|
|
18
23
|
constructor(private readonly context: Context) {
|
19
24
|
super()
|
20
25
|
this._workspaces = new WorkspacesImpl(this, this.context)
|
21
26
|
this._accessGroups = new GroupsImpl(this, this.context)
|
27
|
+
this._chats = new ChatsImpl(this, this.context)
|
22
28
|
}
|
23
29
|
|
24
30
|
public async initFrom(
|
@@ -65,4 +71,25 @@ export class OrganizationImpl extends Organization implements Disposable {
|
|
65
71
|
get accessGroups(): Groups {
|
66
72
|
return this._accessGroups
|
67
73
|
}
|
74
|
+
|
75
|
+
get chats(): Chats {
|
76
|
+
return this._chats
|
77
|
+
}
|
78
|
+
|
79
|
+
async createInviteLink(emails: string[], accessGroups: string[]): Promise<void> {
|
80
|
+
const response = await this.context
|
81
|
+
.resolve(RpcService)
|
82
|
+
?.requestBuilder("api/v1/Invites")
|
83
|
+
.sendPostJson({
|
84
|
+
organizationId: this.id,
|
85
|
+
emails: emails,
|
86
|
+
accessGroupIds: accessGroups
|
87
|
+
})
|
88
|
+
if (ResponseUtils.isFail(response)) {
|
89
|
+
await ResponseUtils.throwError(
|
90
|
+
`Invite link creation failed for organization ${this.id}`,
|
91
|
+
response
|
92
|
+
)
|
93
|
+
}
|
94
|
+
}
|
68
95
|
}
|
@@ -1,6 +1,7 @@
|
|
1
|
-
import { Workspaces } from "
|
1
|
+
import { Workspaces } from "../workspaces/workspaces"
|
2
2
|
import { OrganizationId } from "./organizations"
|
3
|
-
import { Groups } from "
|
3
|
+
import { GroupId, Groups } from "../groups/groups"
|
4
|
+
import { Chats } from "../chats/chats"
|
4
5
|
|
5
6
|
/**
|
6
7
|
* Organization.
|
@@ -26,8 +27,18 @@ export abstract class Organization {
|
|
26
27
|
*/
|
27
28
|
abstract get workspaces(): Workspaces
|
28
29
|
|
30
|
+
/**
|
31
|
+
* Chats.
|
32
|
+
*/
|
33
|
+
abstract get chats(): Chats
|
34
|
+
|
29
35
|
/**
|
30
36
|
* Groups.
|
31
37
|
*/
|
32
38
|
abstract get accessGroups(): Groups
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Create invite link
|
42
|
+
*/
|
43
|
+
abstract createInviteLink(emails: string[], accessGroups: GroupId[]): Promise<void>
|
33
44
|
}
|
@@ -4,11 +4,11 @@ import {
|
|
4
4
|
Organizations
|
5
5
|
} from "./organizations"
|
6
6
|
import { OrganizationImpl } from "./organization.impl"
|
7
|
-
import { RpcService } from "
|
8
|
-
import { OrganizationDto, UserSettings } from "
|
9
|
-
import { Context } from "
|
7
|
+
import { RpcService } from "../../services/rpcService"
|
8
|
+
import { OrganizationDto, UserSettings } from "../../dto/userInfoResponse"
|
9
|
+
import { Context } from "../../context"
|
10
10
|
import { Organization } from "./organization"
|
11
|
-
import { ResponseUtils } from "
|
11
|
+
import { ResponseUtils } from "../../services/responseUtils"
|
12
12
|
|
13
13
|
export class OrganizationsImpl extends Organizations {
|
14
14
|
constructor(public readonly context: Context) {
|
@@ -79,17 +79,22 @@ export class OrganizationsImpl extends Organizations {
|
|
79
79
|
if (!this.contains(id)) {
|
80
80
|
throw new Error(`Organization delete, id: ${id} is not found`)
|
81
81
|
}
|
82
|
+
// send request to the server
|
82
83
|
const response = await this.context
|
83
84
|
.resolve(RpcService)
|
84
85
|
?.requestBuilder("/api/v1/Organizations")
|
85
86
|
.searchParam("id", id)
|
86
87
|
.sendDelete()
|
88
|
+
|
89
|
+
// check response status
|
87
90
|
if (ResponseUtils.isFail(response)) {
|
88
91
|
await ResponseUtils.throwError(
|
89
92
|
`Organization ${id} delete, failed`,
|
90
93
|
response
|
91
94
|
)
|
92
95
|
}
|
96
|
+
|
97
|
+
// check organization in collection
|
93
98
|
const org = <OrganizationImpl>this.get(id)
|
94
99
|
const index = this.organizations.indexOf(org)
|
95
100
|
if (index < 0) {
|
@@ -188,4 +193,5 @@ export class OrganizationsImpl extends Organizations {
|
|
188
193
|
})
|
189
194
|
}
|
190
195
|
}
|
196
|
+
|
191
197
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { UserEvent, UserProfile } from "./userProfile"
|
2
|
-
import { UserInfoResponse } from "
|
2
|
+
import { UserInfoResponse } from "../../dto/userInfoResponse"
|
3
3
|
|
4
4
|
export class UserProfileImpl extends UserProfile {
|
5
5
|
private content?: UserInfoResponse
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import { Context } from "
|
2
|
-
import { Files } from "
|
1
|
+
import { Context } from "../../context"
|
2
|
+
import { Files } from "../files/files"
|
3
3
|
import { Workspace, WorkspaceEvent } from "./workspace"
|
4
|
-
import { OrganizationImpl } from "
|
5
|
-
import { WorkspaceDto } from "
|
6
|
-
import { RpcService } from "
|
7
|
-
import { FilesImpl } from "
|
8
|
-
import { ResponseUtils } from "
|
4
|
+
import { OrganizationImpl } from "../organizations/organization.impl"
|
5
|
+
import { WorkspaceDto } from "../../dto/workspacesResponse"
|
6
|
+
import { RpcService } from "../../services/rpcService"
|
7
|
+
import { FilesImpl } from "../files/files.impl"
|
8
|
+
import { ResponseUtils } from "../../services/responseUtils"
|
9
9
|
|
10
10
|
export class WorkspaceImpl extends Workspace {
|
11
11
|
private _isMarkAsDeleted: boolean = false
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import { EventDispatcher } from "
|
2
|
-
import { Files } from "
|
1
|
+
import { EventDispatcher } from "../../events"
|
2
|
+
import { Files } from "../files/files"
|
3
3
|
import { WorkspaceId } from "./workspaces"
|
4
|
-
import { Organization } from "
|
4
|
+
import { Organization } from "../organizations/organization"
|
5
5
|
|
6
6
|
/**
|
7
7
|
* Workspace event.
|