@neuralinnovations/dataisland-sdk 0.2.1 → 0.4.0

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.
Files changed (66) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/credentials.d.ts +9 -8
  3. package/dist/src/credentials.d.ts.map +1 -1
  4. package/dist/src/credentials.js +8 -4
  5. package/dist/src/credentials.js.map +1 -1
  6. package/dist/src/dataIslandApp.d.ts +5 -0
  7. package/dist/src/dataIslandApp.d.ts.map +1 -1
  8. package/dist/src/dataIslandApp.js.map +1 -1
  9. package/dist/src/dto/administration.d.ts +30 -0
  10. package/dist/src/dto/administration.d.ts.map +1 -0
  11. package/dist/src/dto/administration.js +3 -0
  12. package/dist/src/dto/administration.js.map +1 -0
  13. package/dist/src/index.d.ts +2 -1
  14. package/dist/src/index.d.ts.map +1 -1
  15. package/dist/src/index.js +3 -2
  16. package/dist/src/index.js.map +1 -1
  17. package/dist/src/internal/app.impl.d.ts +2 -0
  18. package/dist/src/internal/app.impl.d.ts.map +1 -1
  19. package/dist/src/internal/app.impl.js +7 -0
  20. package/dist/src/internal/app.impl.js.map +1 -1
  21. package/dist/src/services/statistics.d.ts +12 -0
  22. package/dist/src/services/statistics.d.ts.map +1 -0
  23. package/dist/src/services/statistics.js +21 -0
  24. package/dist/src/services/statistics.js.map +1 -0
  25. package/dist/src/storages/administration/administration.d.ts +7 -0
  26. package/dist/src/storages/administration/administration.d.ts.map +1 -0
  27. package/dist/src/storages/administration/administration.js +7 -0
  28. package/dist/src/storages/administration/administration.js.map +1 -0
  29. package/dist/src/storages/administration/library.administration.d.ts +29 -0
  30. package/dist/src/storages/administration/library.administration.d.ts.map +1 -0
  31. package/dist/src/storages/administration/library.administration.impl.d.ts +15 -0
  32. package/dist/src/storages/administration/library.administration.impl.d.ts.map +1 -0
  33. package/dist/src/storages/administration/library.administration.impl.js +118 -0
  34. package/dist/src/storages/administration/library.administration.impl.js.map +1 -0
  35. package/dist/src/storages/administration/library.administration.js +10 -0
  36. package/dist/src/storages/administration/library.administration.js.map +1 -0
  37. package/dist/src/storages/administration/statistics.administration.d.ts +16 -0
  38. package/dist/src/storages/administration/statistics.administration.d.ts.map +1 -0
  39. package/dist/src/storages/administration/statistics.administration.impl.d.ts +11 -0
  40. package/dist/src/storages/administration/statistics.administration.impl.d.ts.map +1 -0
  41. package/dist/src/storages/administration/statistics.administration.impl.js +32 -0
  42. package/dist/src/storages/administration/statistics.administration.impl.js.map +1 -0
  43. package/dist/src/storages/administration/statistics.administration.js +10 -0
  44. package/dist/src/storages/administration/statistics.administration.js.map +1 -0
  45. package/dist/src/storages/library/libraries.d.ts +0 -31
  46. package/dist/src/storages/library/libraries.d.ts.map +1 -1
  47. package/dist/src/storages/library/libraries.impl.d.ts +1 -14
  48. package/dist/src/storages/library/libraries.impl.d.ts.map +1 -1
  49. package/dist/src/storages/library/libraries.impl.js +1 -116
  50. package/dist/src/storages/library/libraries.impl.js.map +1 -1
  51. package/dist/src/storages/library/libraries.js +1 -7
  52. package/dist/src/storages/library/libraries.js.map +1 -1
  53. package/package.json +1 -1
  54. package/src/credentials.ts +18 -12
  55. package/src/dataIslandApp.ts +7 -1
  56. package/src/dto/administration.ts +34 -0
  57. package/src/index.ts +4 -1
  58. package/src/internal/app.impl.ts +11 -2
  59. package/src/services/statistics.ts +31 -0
  60. package/src/storages/administration/administration.ts +8 -0
  61. package/src/storages/administration/library.administration.impl.ts +169 -0
  62. package/src/storages/administration/library.administration.ts +33 -0
  63. package/src/storages/administration/statistics.administration.impl.ts +51 -0
  64. package/src/storages/administration/statistics.administration.ts +21 -0
  65. package/src/storages/library/libraries.impl.ts +2 -170
  66. package/src/storages/library/libraries.ts +0 -37
@@ -0,0 +1,169 @@
1
+ import { LibraryAdministration } from "./library.administration"
2
+ import { Context } from "../../context"
3
+ import { LibraryId } from "../library/libraryId"
4
+ import { RpcService } from "../../services/rpcService"
5
+ import { ResponseUtils } from "../../services/responseUtils"
6
+ import {
7
+ CreateLibraryResponse,
8
+ LibraryDto,
9
+ LibraryResponse
10
+ } from "../../dto/libraryResponse"
11
+ import { OrganizationId } from "../organizations/organizations"
12
+
13
+ export class LibraryAdministrationImpl extends LibraryAdministration {
14
+ private context: Context
15
+
16
+ constructor(context: Context) {
17
+ super()
18
+ this.context = context
19
+ }
20
+
21
+ async createLibrary(name: string, description: string, region: number, isPublic: boolean): Promise<LibraryId> {
22
+ if (
23
+ name === undefined ||
24
+ name === null ||
25
+ name.trim() === ""
26
+ ) {
27
+ throw new Error("Name for library is required, must be not empty")
28
+ }
29
+
30
+ if (
31
+ description === undefined ||
32
+ description === null ||
33
+ description.trim() === ""
34
+ ) {
35
+ throw new Error("Description for library is required, must be not empty")
36
+ }
37
+
38
+ if (
39
+ isPublic === undefined ||
40
+ isPublic === null
41
+ ) {
42
+ throw new Error("IsPublic is required, must be not empty")
43
+ }
44
+
45
+ // send create request to the server
46
+ const response = await this.context
47
+ .resolve(RpcService)
48
+ ?.requestBuilder("api/v1/libraries/management")
49
+ .sendPostJson({
50
+ name: name,
51
+ description: description,
52
+ region: region,
53
+ isPublic: isPublic
54
+ })
55
+
56
+ // check response status
57
+ if (ResponseUtils.isFail(response)) {
58
+ await ResponseUtils.throwError(`Failed to create library ${name}`, response)
59
+ }
60
+
61
+ const library = (await response!.json()) as CreateLibraryResponse
62
+
63
+ return library.libraryId
64
+ }
65
+
66
+ async addOrgToLibrary(libraryId: LibraryId, organizationId: OrganizationId): Promise<void> {
67
+ if (libraryId === undefined || libraryId === null) {
68
+ throw new Error("Organization add to library, libraryId is undefined or null")
69
+ }
70
+ if (libraryId.length === 0 || libraryId.trim().length === 0) {
71
+ throw new Error("Organization add to from library, libraryId is empty")
72
+ }
73
+ if (organizationId === undefined || organizationId === null) {
74
+ throw new Error("Organization add to from library, organizationId is undefined or null")
75
+ }
76
+ if (organizationId.length === 0 || organizationId.trim().length === 0) {
77
+ throw new Error("Organization add to from library, organizationId is empty")
78
+ }
79
+
80
+ const response = await this.context
81
+ .resolve(RpcService)
82
+ ?.requestBuilder("api/v1/libraries/management/allowed/organization")
83
+ .sendPutJson({
84
+ libraryId: libraryId,
85
+ organizationId: organizationId
86
+ })
87
+ if (ResponseUtils.isFail(response)) {
88
+ await ResponseUtils.throwError(
89
+ `Organization ${organizationId} add to library ${libraryId} failed`,
90
+ response
91
+ )
92
+ }
93
+ }
94
+
95
+ async getLibraries(): Promise<LibraryDto[]> {
96
+ const response = await this.context
97
+ .resolve(RpcService)
98
+ ?.requestBuilder("api/v1/libraries/management/allowed/organizations")
99
+ .sendGet()
100
+
101
+ // check response status
102
+ if (ResponseUtils.isFail(response)) {
103
+ await ResponseUtils.throwError(
104
+ "Can not get libraries",
105
+ response
106
+ )
107
+ }
108
+
109
+ // parse libraries from the server's response
110
+ const libraries = (await response!.json()) as LibraryResponse
111
+
112
+ return libraries.libraries
113
+ }
114
+
115
+ async deleteOrgFromLibrary(libraryId: LibraryId, organizationId: OrganizationId): Promise<void> {
116
+ if (libraryId === undefined || libraryId === null) {
117
+ throw new Error("Organization delete from library, libraryId is undefined or null")
118
+ }
119
+ if (libraryId.length === 0 || libraryId.trim().length === 0) {
120
+ throw new Error("Organization delete from library, libraryId is empty")
121
+ }
122
+ if (organizationId === undefined || organizationId === null) {
123
+ throw new Error("Organization delete from library, organizationId is undefined or null")
124
+ }
125
+ if (organizationId.length === 0 || organizationId.trim().length === 0) {
126
+ throw new Error("Organization delete from library, organizationId is empty")
127
+ }
128
+
129
+ // send request to the server
130
+ const response = await this.context
131
+ .resolve(RpcService)
132
+ ?.requestBuilder("api/v1/libraries/management/allowed/organization")
133
+ .searchParam("libraryId", libraryId)
134
+ .searchParam("organizationId", organizationId)
135
+ .sendDelete()
136
+
137
+ // check response status
138
+ if (ResponseUtils.isFail(response)) {
139
+ await ResponseUtils.throwError(
140
+ `Organization ${organizationId} delete from library ${libraryId}, failed`,
141
+ response
142
+ )
143
+ }
144
+ }
145
+
146
+ async deleteLibrary(libraryId: LibraryId): Promise<void> {
147
+ if (libraryId === undefined || libraryId === null) {
148
+ throw new Error("Library delete, libraryId is undefined or null")
149
+ }
150
+ if (libraryId.length === 0 || libraryId.trim().length === 0) {
151
+ throw new Error("Library delete, libraryId is empty")
152
+ }
153
+
154
+ // send request to the server
155
+ const response = await this.context
156
+ .resolve(RpcService)
157
+ ?.requestBuilder("api/v1/libraries/management")
158
+ .searchParam("libraryId", libraryId)
159
+ .sendDelete()
160
+
161
+ // check response status
162
+ if (ResponseUtils.isFail(response)) {
163
+ await ResponseUtils.throwError(
164
+ `Library ${libraryId} delete, failed`,
165
+ response
166
+ )
167
+ }
168
+ }
169
+ }
@@ -0,0 +1,33 @@
1
+ import { LibraryId } from "../library/libraryId"
2
+ import { OrganizationId } from "../organizations/organizations"
3
+ import { LibraryDto } from "../../dto/libraryResponse"
4
+
5
+ /**
6
+ * Library management, you must have permissions to manage libraries
7
+ */
8
+ export abstract class LibraryAdministration {
9
+ /**
10
+ * Create a new library
11
+ */
12
+ abstract createLibrary(name: string, description: string, region: number, isPublic: boolean): Promise<LibraryId>
13
+
14
+ /**
15
+ * Add permission for an organization to share its data through the library
16
+ */
17
+ abstract addOrgToLibrary(libraryId: LibraryId, organizationId: OrganizationId): Promise<void>
18
+
19
+ /**
20
+ * Get all libraries
21
+ */
22
+ abstract getLibraries(): Promise<LibraryDto[]>
23
+
24
+ /**
25
+ * Delete permission for an organization to share its data through the library
26
+ */
27
+ abstract deleteOrgFromLibrary(libraryId: LibraryId, organizationId: OrganizationId): Promise<void>
28
+
29
+ /**
30
+ * Delete a library by id
31
+ */
32
+ abstract deleteLibrary(libraryId: LibraryId): Promise<void>
33
+ }
@@ -0,0 +1,51 @@
1
+ import { StatisticAdministration } from "./statistics.administration"
2
+ import { RpcService } from "../../services/rpcService"
3
+ import { ResponseUtils } from "../../services/responseUtils"
4
+ import {
5
+ OrganizationMembersStatisticResponse,
6
+ OrganizationStatisticResponse
7
+ } from "../../dto/administration"
8
+ import { OrganizationId } from "../organizations/organizations"
9
+ import { Context } from "../../context"
10
+
11
+ export class StatisticAdministrationImpl implements StatisticAdministration {
12
+ constructor(private readonly context: Context) {
13
+ }
14
+
15
+ async getOrganizationMembers(
16
+ organizationId: OrganizationId,
17
+ dateFrom: number,
18
+ dateTo: number
19
+ ): Promise<OrganizationMembersStatisticResponse> {
20
+ const response = await this.context
21
+ .resolve(RpcService)
22
+ ?.requestBuilder("api/v1/Stats/internal/organization/members/total")
23
+ .searchParam("organizationId", organizationId)
24
+ .searchParam("dateFrom", dateFrom.toString())
25
+ .searchParam("dateTo", dateTo.toString())
26
+ .sendGet()
27
+
28
+ // check response status
29
+ if (ResponseUtils.isFail(response)) {
30
+ await ResponseUtils.throwError("Failed to get statistics", response)
31
+ }
32
+
33
+ return await response!.json() as OrganizationMembersStatisticResponse
34
+ }
35
+
36
+ async getOrganizations(dateFrom: number, dateTo: number): Promise<OrganizationStatisticResponse> {
37
+ const response = await this.context
38
+ .resolve(RpcService)
39
+ ?.requestBuilder("/api/v1/Stats/internal/organizations")
40
+ .searchParam("dateFrom", dateFrom.toString())
41
+ .searchParam("dateTo", dateTo.toString())
42
+ .sendGet()
43
+
44
+ // check response status
45
+ if (ResponseUtils.isFail(response)) {
46
+ await ResponseUtils.throwError("Failed to get statistics", response)
47
+ }
48
+
49
+ return await response!.json() as OrganizationStatisticResponse
50
+ }
51
+ }
@@ -0,0 +1,21 @@
1
+ import { OrganizationId } from "../organizations/organizations"
2
+ import {
3
+ OrganizationMembersStatisticResponse,
4
+ OrganizationStatisticResponse
5
+ } from "../../dto/administration"
6
+
7
+ /**
8
+ * Statistic management, you must have permissions to manage statistics
9
+ */
10
+ export abstract class StatisticAdministration {
11
+
12
+ /**
13
+ * Get organization statistics
14
+ */
15
+ abstract getOrganizations(dateFrom: number, dateTo: number): Promise<OrganizationStatisticResponse>;
16
+
17
+ /**
18
+ * Get organization members statistics
19
+ */
20
+ abstract getOrganizationMembers(organizationId: OrganizationId, dateFrom: number, dateTo: number): Promise<OrganizationMembersStatisticResponse>;
21
+ }
@@ -1,183 +1,19 @@
1
- import { Libraries, LibraryManagement } from "./libraries"
1
+ import { Libraries } from "./libraries"
2
2
  import { Library } from "./library"
3
3
  import { LibraryImpl } from "./library.impl"
4
4
  import { Context } from "../../context"
5
- import {
6
- CreateLibraryResponse,
7
- LibrariesResponse, LibraryDto, LibraryResponse
8
- } from "../../dto/libraryResponse"
5
+ import { LibrariesResponse } from "../../dto/libraryResponse"
9
6
  import { RpcService } from "../../services/rpcService"
10
7
  import { ResponseUtils } from "../../services/responseUtils"
11
- import { OrganizationId } from "../organizations/organizations"
12
8
  import { LibraryId } from "./libraryId"
13
9
 
14
- export class LibraryManagementImpl extends LibraryManagement {
15
- private context: Context
16
-
17
- constructor(context: Context) {
18
- super()
19
- this.context = context
20
- }
21
-
22
- async createLibrary(name: string, description: string, region: number, isPublic: boolean): Promise<LibraryId> {
23
- if (
24
- name === undefined ||
25
- name === null ||
26
- name.trim() === ""
27
- ) {
28
- throw new Error("Name for library is required, must be not empty")
29
- }
30
-
31
- if (
32
- description === undefined ||
33
- description === null ||
34
- description.trim() === ""
35
- ) {
36
- throw new Error("Description for library is required, must be not empty")
37
- }
38
-
39
- if (
40
- isPublic === undefined ||
41
- isPublic === null
42
- ) {
43
- throw new Error("IsPublic is required, must be not empty")
44
- }
45
-
46
- // send create request to the server
47
- const response = await this.context
48
- .resolve(RpcService)
49
- ?.requestBuilder("api/v1/libraries/management")
50
- .sendPostJson({
51
- name: name,
52
- description: description,
53
- region: region,
54
- isPublic: isPublic
55
- })
56
-
57
- // check response status
58
- if (ResponseUtils.isFail(response)) {
59
- await ResponseUtils.throwError(`Failed to create library ${name}`, response)
60
- }
61
-
62
- const library = (await response!.json()) as CreateLibraryResponse
63
-
64
- return library.libraryId
65
- }
66
-
67
- async addOrgToLibrary(libraryId: LibraryId, organizationId: OrganizationId): Promise<void> {
68
- if (libraryId === undefined || libraryId === null) {
69
- throw new Error("Organization add to library, libraryId is undefined or null")
70
- }
71
- if (libraryId.length === 0 || libraryId.trim().length === 0) {
72
- throw new Error("Organization add to from library, libraryId is empty")
73
- }
74
- if (organizationId === undefined || organizationId === null) {
75
- throw new Error("Organization add to from library, organizationId is undefined or null")
76
- }
77
- if (organizationId.length === 0 || organizationId.trim().length === 0) {
78
- throw new Error("Organization add to from library, organizationId is empty")
79
- }
80
-
81
- const response = await this.context
82
- .resolve(RpcService)
83
- ?.requestBuilder("api/v1/libraries/management/allowed/organization")
84
- .sendPutJson({
85
- libraryId: libraryId,
86
- organizationId: organizationId
87
- })
88
- if (ResponseUtils.isFail(response)) {
89
- await ResponseUtils.throwError(
90
- `Organization ${organizationId} add to library ${libraryId} failed`,
91
- response
92
- )
93
- }
94
- }
95
-
96
- async getLibraries(): Promise<LibraryDto[]> {
97
- const response = await this.context
98
- .resolve(RpcService)
99
- ?.requestBuilder("api/v1/libraries/management/allowed/organizations")
100
- .sendGet()
101
-
102
- // check response status
103
- if (ResponseUtils.isFail(response)) {
104
- await ResponseUtils.throwError(
105
- "Can not get libraries",
106
- response
107
- )
108
- }
109
-
110
- // parse libraries from the server's response
111
- const libraries = (await response!.json()) as LibraryResponse
112
-
113
- return libraries.libraries
114
- }
115
-
116
- async deleteOrgFromLibrary(libraryId: LibraryId, organizationId: OrganizationId): Promise<void> {
117
- if (libraryId === undefined || libraryId === null) {
118
- throw new Error("Organization delete from library, libraryId is undefined or null")
119
- }
120
- if (libraryId.length === 0 || libraryId.trim().length === 0) {
121
- throw new Error("Organization delete from library, libraryId is empty")
122
- }
123
- if (organizationId === undefined || organizationId === null) {
124
- throw new Error("Organization delete from library, organizationId is undefined or null")
125
- }
126
- if (organizationId.length === 0 || organizationId.trim().length === 0) {
127
- throw new Error("Organization delete from library, organizationId is empty")
128
- }
129
-
130
- // send request to the server
131
- const response = await this.context
132
- .resolve(RpcService)
133
- ?.requestBuilder("api/v1/libraries/management/allowed/organization")
134
- .searchParam("libraryId", libraryId)
135
- .searchParam("organizationId", organizationId)
136
- .sendDelete()
137
-
138
- // check response status
139
- if (ResponseUtils.isFail(response)) {
140
- await ResponseUtils.throwError(
141
- `Organization ${organizationId} delete from library ${libraryId}, failed`,
142
- response
143
- )
144
- }
145
- }
146
-
147
- async deleteLibrary(libraryId: LibraryId): Promise<void> {
148
- if (libraryId === undefined || libraryId === null) {
149
- throw new Error("Library delete, libraryId is undefined or null")
150
- }
151
- if (libraryId.length === 0 || libraryId.trim().length === 0) {
152
- throw new Error("Library delete, libraryId is empty")
153
- }
154
-
155
- // send request to the server
156
- const response = await this.context
157
- .resolve(RpcService)
158
- ?.requestBuilder("api/v1/libraries/management")
159
- .searchParam("libraryId", libraryId)
160
- .sendDelete()
161
-
162
- // check response status
163
- if (ResponseUtils.isFail(response)) {
164
- await ResponseUtils.throwError(
165
- `Library ${libraryId} delete, failed`,
166
- response
167
- )
168
- }
169
- }
170
- }
171
-
172
10
  export class LibrariesImpl extends Libraries {
173
11
  private readonly _libraries: LibraryImpl[] = []
174
- private readonly _management
175
12
 
176
13
  constructor(
177
14
  private readonly context: Context
178
15
  ) {
179
16
  super()
180
- this._management = new LibraryManagementImpl(context)
181
17
  }
182
18
 
183
19
  async initialize() {
@@ -212,8 +48,4 @@ export class LibrariesImpl extends Libraries {
212
48
  return this._libraries.find((library) => library.id === libraryId)
213
49
  }
214
50
 
215
- get management(): LibraryManagement {
216
- return this._management
217
- }
218
-
219
51
  }
@@ -1,38 +1,6 @@
1
1
  import { Library } from "./library"
2
- import { OrganizationId } from "../organizations/organizations"
3
- import { LibraryDto } from "../../dto/libraryResponse"
4
2
  import { LibraryId } from "./libraryId"
5
3
 
6
- /**
7
- * Library management, you must have permissions to manage libraries
8
- */
9
- export abstract class LibraryManagement {
10
- /**
11
- * Create a new library
12
- */
13
- abstract createLibrary(name: string, description: string, region: number, isPublic: boolean): Promise<LibraryId>
14
-
15
- /**
16
- * Add permission for an organization to share its data through the library
17
- */
18
- abstract addOrgToLibrary(libraryId: LibraryId, organizationId: OrganizationId): Promise<void>
19
-
20
- /**
21
- * Get all libraries
22
- */
23
- abstract getLibraries(): Promise<LibraryDto[]>
24
-
25
- /**
26
- * Delete permission for an organization to share its data through the library
27
- */
28
- abstract deleteOrgFromLibrary(libraryId: LibraryId, organizationId: OrganizationId): Promise<void>
29
-
30
- /**
31
- * Delete a library by id
32
- */
33
- abstract deleteLibrary(libraryId: LibraryId): Promise<void>
34
- }
35
-
36
4
  /**
37
5
  * Libraries
38
6
  */
@@ -48,9 +16,4 @@ export abstract class Libraries {
48
16
  * @param libraryId
49
17
  */
50
18
  abstract getLibraryById(libraryId: LibraryId): Library | undefined
51
-
52
- /**
53
- * You must have permissions to manage libraries
54
- */
55
- abstract get management(): LibraryManagement
56
19
  }