@neuralinnovations/dataisland-sdk 0.2.0 → 0.3.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 (61) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/dataIslandApp.d.ts +5 -0
  3. package/dist/src/dataIslandApp.d.ts.map +1 -1
  4. package/dist/src/dataIslandApp.js.map +1 -1
  5. package/dist/src/dto/administration.d.ts +30 -0
  6. package/dist/src/dto/administration.d.ts.map +1 -0
  7. package/dist/src/dto/administration.js +3 -0
  8. package/dist/src/dto/administration.js.map +1 -0
  9. package/dist/src/index.d.ts +2 -1
  10. package/dist/src/index.d.ts.map +1 -1
  11. package/dist/src/index.js +3 -2
  12. package/dist/src/index.js.map +1 -1
  13. package/dist/src/internal/app.impl.d.ts +2 -0
  14. package/dist/src/internal/app.impl.d.ts.map +1 -1
  15. package/dist/src/internal/app.impl.js +7 -0
  16. package/dist/src/internal/app.impl.js.map +1 -1
  17. package/dist/src/services/statistics.d.ts +12 -0
  18. package/dist/src/services/statistics.d.ts.map +1 -0
  19. package/dist/src/services/statistics.js +21 -0
  20. package/dist/src/services/statistics.js.map +1 -0
  21. package/dist/src/storages/administration/administration.d.ts +7 -0
  22. package/dist/src/storages/administration/administration.d.ts.map +1 -0
  23. package/dist/src/storages/administration/administration.js +7 -0
  24. package/dist/src/storages/administration/administration.js.map +1 -0
  25. package/dist/src/storages/administration/library.administration.d.ts +29 -0
  26. package/dist/src/storages/administration/library.administration.d.ts.map +1 -0
  27. package/dist/src/storages/administration/library.administration.impl.d.ts +15 -0
  28. package/dist/src/storages/administration/library.administration.impl.d.ts.map +1 -0
  29. package/dist/src/storages/administration/library.administration.impl.js +118 -0
  30. package/dist/src/storages/administration/library.administration.impl.js.map +1 -0
  31. package/dist/src/storages/administration/library.administration.js +10 -0
  32. package/dist/src/storages/administration/library.administration.js.map +1 -0
  33. package/dist/src/storages/administration/statistics.administration.d.ts +16 -0
  34. package/dist/src/storages/administration/statistics.administration.d.ts.map +1 -0
  35. package/dist/src/storages/administration/statistics.administration.impl.d.ts +11 -0
  36. package/dist/src/storages/administration/statistics.administration.impl.d.ts.map +1 -0
  37. package/dist/src/storages/administration/statistics.administration.impl.js +32 -0
  38. package/dist/src/storages/administration/statistics.administration.impl.js.map +1 -0
  39. package/dist/src/storages/administration/statistics.administration.js +10 -0
  40. package/dist/src/storages/administration/statistics.administration.js.map +1 -0
  41. package/dist/src/storages/library/libraries.d.ts +0 -31
  42. package/dist/src/storages/library/libraries.d.ts.map +1 -1
  43. package/dist/src/storages/library/libraries.impl.d.ts +1 -14
  44. package/dist/src/storages/library/libraries.impl.d.ts.map +1 -1
  45. package/dist/src/storages/library/libraries.impl.js +1 -110
  46. package/dist/src/storages/library/libraries.impl.js.map +1 -1
  47. package/dist/src/storages/library/libraries.js +1 -7
  48. package/dist/src/storages/library/libraries.js.map +1 -1
  49. package/package.json +1 -1
  50. package/src/dataIslandApp.ts +7 -1
  51. package/src/dto/administration.ts +34 -0
  52. package/src/index.ts +4 -1
  53. package/src/internal/app.impl.ts +11 -2
  54. package/src/services/statistics.ts +31 -0
  55. package/src/storages/administration/administration.ts +8 -0
  56. package/src/storages/administration/library.administration.impl.ts +169 -0
  57. package/src/storages/administration/library.administration.ts +33 -0
  58. package/src/storages/administration/statistics.administration.impl.ts +51 -0
  59. package/src/storages/administration/statistics.administration.ts +21 -0
  60. package/src/storages/library/libraries.impl.ts +2 -161
  61. package/src/storages/library/libraries.ts +0 -37
@@ -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,174 +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, 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
- isPublic === undefined ||
33
- isPublic === null
34
- ) {
35
- throw new Error("IsPublic is required, must be not empty")
36
- }
37
-
38
- // send create request to the server
39
- const response = await this.context
40
- .resolve(RpcService)
41
- ?.requestBuilder("api/v1/libraries/management")
42
- .sendPostJson({
43
- name: name,
44
- region: region,
45
- isPublic: isPublic
46
- })
47
-
48
- // check response status
49
- if (ResponseUtils.isFail(response)) {
50
- await ResponseUtils.throwError(`Failed to create library ${name}`, response)
51
- }
52
-
53
- const library = (await response!.json()) as CreateLibraryResponse
54
-
55
- return library.libraryId
56
- }
57
-
58
- async addOrgToLibrary(libraryId: LibraryId, organizationId: OrganizationId): Promise<void> {
59
- if (libraryId === undefined || libraryId === null) {
60
- throw new Error("Organization add to library, libraryId is undefined or null")
61
- }
62
- if (libraryId.length === 0 || libraryId.trim().length === 0) {
63
- throw new Error("Organization add to from library, libraryId is empty")
64
- }
65
- if (organizationId === undefined || organizationId === null) {
66
- throw new Error("Organization add to from library, organizationId is undefined or null")
67
- }
68
- if (organizationId.length === 0 || organizationId.trim().length === 0) {
69
- throw new Error("Organization add to from library, organizationId is empty")
70
- }
71
-
72
- const response = await this.context
73
- .resolve(RpcService)
74
- ?.requestBuilder("api/v1/libraries/management/allowed/organization")
75
- .sendPutJson({
76
- libraryId: libraryId,
77
- organizationId: organizationId
78
- })
79
- if (ResponseUtils.isFail(response)) {
80
- await ResponseUtils.throwError(
81
- `Organization ${organizationId} add to library ${libraryId} failed`,
82
- response
83
- )
84
- }
85
- }
86
-
87
- async getLibraries(): Promise<LibraryDto[]> {
88
- const response = await this.context
89
- .resolve(RpcService)
90
- ?.requestBuilder("api/v1/libraries/management/allowed/organizations")
91
- .sendGet()
92
-
93
- // check response status
94
- if (ResponseUtils.isFail(response)) {
95
- await ResponseUtils.throwError(
96
- "Can not get libraries",
97
- response
98
- )
99
- }
100
-
101
- // parse libraries from the server's response
102
- const libraries = (await response!.json()) as LibraryResponse
103
-
104
- return libraries.libraries
105
- }
106
-
107
- async deleteOrgFromLibrary(libraryId: LibraryId, organizationId: OrganizationId): Promise<void> {
108
- if (libraryId === undefined || libraryId === null) {
109
- throw new Error("Organization delete from library, libraryId is undefined or null")
110
- }
111
- if (libraryId.length === 0 || libraryId.trim().length === 0) {
112
- throw new Error("Organization delete from library, libraryId is empty")
113
- }
114
- if (organizationId === undefined || organizationId === null) {
115
- throw new Error("Organization delete from library, organizationId is undefined or null")
116
- }
117
- if (organizationId.length === 0 || organizationId.trim().length === 0) {
118
- throw new Error("Organization delete from library, organizationId is empty")
119
- }
120
-
121
- // send request to the server
122
- const response = await this.context
123
- .resolve(RpcService)
124
- ?.requestBuilder("api/v1/libraries/management/allowed/organization")
125
- .searchParam("libraryId", libraryId)
126
- .searchParam("organizationId", organizationId)
127
- .sendDelete()
128
-
129
- // check response status
130
- if (ResponseUtils.isFail(response)) {
131
- await ResponseUtils.throwError(
132
- `Organization ${organizationId} delete from library ${libraryId}, failed`,
133
- response
134
- )
135
- }
136
- }
137
-
138
- async deleteLibrary(libraryId: LibraryId): Promise<void> {
139
- if (libraryId === undefined || libraryId === null) {
140
- throw new Error("Library delete, libraryId is undefined or null")
141
- }
142
- if (libraryId.length === 0 || libraryId.trim().length === 0) {
143
- throw new Error("Library delete, libraryId is empty")
144
- }
145
-
146
- // send request to the server
147
- const response = await this.context
148
- .resolve(RpcService)
149
- ?.requestBuilder("api/v1/libraries/management")
150
- .searchParam("libraryId", libraryId)
151
- .sendDelete()
152
-
153
- // check response status
154
- if (ResponseUtils.isFail(response)) {
155
- await ResponseUtils.throwError(
156
- `Library ${libraryId} delete, failed`,
157
- response
158
- )
159
- }
160
- }
161
- }
162
-
163
10
  export class LibrariesImpl extends Libraries {
164
11
  private readonly _libraries: LibraryImpl[] = []
165
- private readonly _management
166
12
 
167
13
  constructor(
168
14
  private readonly context: Context
169
15
  ) {
170
16
  super()
171
- this._management = new LibraryManagementImpl(context)
172
17
  }
173
18
 
174
19
  async initialize() {
@@ -203,8 +48,4 @@ export class LibrariesImpl extends Libraries {
203
48
  return this._libraries.find((library) => library.id === libraryId)
204
49
  }
205
50
 
206
- get management(): LibraryManagement {
207
- return this._management
208
- }
209
-
210
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, 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
  }