@neuralinnovations/dataisland-sdk 0.0.1-dev31 → 0.0.1-dev33

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 (80) hide show
  1. package/README.md +27 -3
  2. package/dist/package.json +1 -1
  3. package/dist/src/dto/chatResponse.d.ts +1 -0
  4. package/dist/src/dto/chatResponse.d.ts.map +1 -1
  5. package/dist/src/dto/chatResponse.js.map +1 -1
  6. package/dist/src/dto/statisticsResponse.d.ts +11 -0
  7. package/dist/src/dto/statisticsResponse.d.ts.map +1 -0
  8. package/dist/src/dto/statisticsResponse.js +3 -0
  9. package/dist/src/dto/statisticsResponse.js.map +1 -0
  10. package/dist/src/dto/userInfoResponse.d.ts +10 -0
  11. package/dist/src/dto/userInfoResponse.d.ts.map +1 -1
  12. package/dist/src/dto/workspacesResponse.d.ts +2 -0
  13. package/dist/src/dto/workspacesResponse.d.ts.map +1 -1
  14. package/dist/src/index.d.ts +1 -0
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js +4 -1
  17. package/dist/src/index.js.map +1 -1
  18. package/dist/src/storages/chats/chat.d.ts +4 -0
  19. package/dist/src/storages/chats/chat.d.ts.map +1 -1
  20. package/dist/src/storages/chats/chat.impl.d.ts +1 -0
  21. package/dist/src/storages/chats/chat.impl.d.ts.map +1 -1
  22. package/dist/src/storages/chats/chat.impl.js +4 -0
  23. package/dist/src/storages/chats/chat.impl.js.map +1 -1
  24. package/dist/src/storages/chats/chat.js.map +1 -1
  25. package/dist/src/storages/chats/chats.d.ts +5 -0
  26. package/dist/src/storages/chats/chats.d.ts.map +1 -1
  27. package/dist/src/storages/chats/chats.impl.d.ts +1 -0
  28. package/dist/src/storages/chats/chats.impl.d.ts.map +1 -1
  29. package/dist/src/storages/chats/chats.impl.js +33 -1
  30. package/dist/src/storages/chats/chats.impl.js.map +1 -1
  31. package/dist/src/storages/chats/chats.js.map +1 -1
  32. package/dist/src/storages/files/file.d.ts +5 -1
  33. package/dist/src/storages/files/file.d.ts.map +1 -1
  34. package/dist/src/storages/files/file.impl.d.ts +2 -1
  35. package/dist/src/storages/files/file.impl.d.ts.map +1 -1
  36. package/dist/src/storages/files/file.impl.js +13 -13
  37. package/dist/src/storages/files/file.impl.js.map +1 -1
  38. package/dist/src/storages/files/file.js.map +1 -1
  39. package/dist/src/storages/files/files.d.ts +5 -0
  40. package/dist/src/storages/files/files.d.ts.map +1 -1
  41. package/dist/src/storages/files/files.impl.d.ts +2 -0
  42. package/dist/src/storages/files/files.impl.d.ts.map +1 -1
  43. package/dist/src/storages/files/files.impl.js +23 -3
  44. package/dist/src/storages/files/files.impl.js.map +1 -1
  45. package/dist/src/storages/files/files.js.map +1 -1
  46. package/dist/src/storages/organizations/organization.d.ts +20 -1
  47. package/dist/src/storages/organizations/organization.d.ts.map +1 -1
  48. package/dist/src/storages/organizations/organization.impl.d.ts +5 -1
  49. package/dist/src/storages/organizations/organization.impl.d.ts.map +1 -1
  50. package/dist/src/storages/organizations/organization.impl.js +33 -0
  51. package/dist/src/storages/organizations/organization.impl.js.map +1 -1
  52. package/dist/src/storages/organizations/organization.js.map +1 -1
  53. package/dist/src/storages/user/userProfile.impl.d.ts.map +1 -1
  54. package/dist/src/storages/user/userProfile.impl.js.map +1 -1
  55. package/dist/src/utils/browserUtils.d.ts.map +1 -1
  56. package/dist/src/utils/browserUtils.js +1 -5
  57. package/dist/src/utils/browserUtils.js.map +1 -1
  58. package/dist/src/utils/utils.d.ts +3 -0
  59. package/dist/src/utils/utils.d.ts.map +1 -0
  60. package/dist/src/utils/utils.js +13 -0
  61. package/dist/src/utils/utils.js.map +1 -0
  62. package/package.json +1 -1
  63. package/src/dto/chatResponse.ts +1 -0
  64. package/src/dto/statisticsResponse.ts +12 -0
  65. package/src/dto/userInfoResponse.ts +12 -0
  66. package/src/dto/workspacesResponse.ts +3 -1
  67. package/src/index.ts +1 -0
  68. package/src/storages/chats/chat.impl.ts +4 -0
  69. package/src/storages/chats/chat.ts +5 -0
  70. package/src/storages/chats/chats.impl.ts +45 -2
  71. package/src/storages/chats/chats.ts +6 -0
  72. package/src/storages/files/file.impl.ts +15 -21
  73. package/src/storages/files/file.ts +6 -1
  74. package/src/storages/files/files.impl.ts +36 -3
  75. package/src/storages/files/files.ts +6 -0
  76. package/src/storages/organizations/organization.impl.ts +66 -1
  77. package/src/storages/organizations/organization.ts +25 -1
  78. package/src/storages/user/userProfile.impl.ts +2 -0
  79. package/src/utils/browserUtils.ts +1 -5
  80. package/src/utils/utils.ts +8 -0
@@ -29,6 +29,10 @@ export class FilesImpl extends Files {
29
29
  return loaded_files
30
30
  }
31
31
 
32
+ async get(fileId: string): Promise<File>{
33
+ return await this.internalGetFile(fileId)
34
+ }
35
+
32
36
  async delete(ids: string[]): Promise<void> {
33
37
  for (const id of ids) {
34
38
  await this.internalDeleteFile(id)
@@ -43,6 +47,37 @@ export class FilesImpl extends Files {
43
47
  // INTERNALS
44
48
  //----------------------------------------------------------------------------
45
49
 
50
+
51
+ async internalGetFile(id: string): Promise<File>{
52
+ if (id === undefined || id === null) {
53
+ throw new Error("File get, id is undefined or null")
54
+ }
55
+ if (id.length === 0 || id.trim().length === 0) {
56
+ throw new Error("File get, id is empty")
57
+ }
58
+
59
+ const response = await this.context
60
+ .resolve(RpcService)
61
+ ?.requestBuilder("api/v1/Files")
62
+ .searchParam("id", id)
63
+ .sendGet()
64
+
65
+ if (ResponseUtils.isFail(response)) {
66
+ await ResponseUtils.throwError(
67
+ `Failed to get file ${id}`,
68
+ response
69
+ )
70
+ }
71
+
72
+ // parse file from the server's response
73
+ const result = (await response!.json() as { file: FileDto }).file as FileDto
74
+
75
+ // create file implementation
76
+ const fileImpl = new FileImpl(this.context)
77
+
78
+ return await fileImpl.initFrom(result)
79
+ }
80
+
46
81
  /**
47
82
  * Delete file.
48
83
  * @param id
@@ -60,6 +95,7 @@ export class FilesImpl extends Files {
60
95
  ?.requestBuilder("/api/v1/Files")
61
96
  .searchParam("id", id)
62
97
  .sendDelete()
98
+
63
99
  if (ResponseUtils.isFail(response)) {
64
100
  await ResponseUtils.throwError(`File ${id} delete, failed`, response)
65
101
  }
@@ -180,9 +216,6 @@ export class FilesImpl extends Files {
180
216
 
181
217
  await fileImpl.initFrom(result)
182
218
 
183
- // TODO: why is this here?
184
- this.filesList?.files.push(fileImpl)
185
-
186
219
  // dispatch event, file added
187
220
  this.dispatch({
188
221
  type: FilesEvent.ADDED,
@@ -25,6 +25,12 @@ export abstract class Files extends EventDispatcher<FilesEvent, File> {
25
25
  */
26
26
  abstract upload(files: UploadFile[]): Promise<File[]>
27
27
 
28
+ /**
29
+ * Get file by ID
30
+ * @param fileId
31
+ */
32
+ abstract get(fileId: FileId): Promise<File>
33
+
28
34
  /**
29
35
  * Delete files.
30
36
  * @param ids
@@ -1,6 +1,6 @@
1
1
  import { OrganizationId } from "./organizations"
2
2
  import { Disposable } from "../../disposable"
3
- import { OrganizationDto, UserDto } from "../../dto/userInfoResponse"
3
+ import { OrganizationDto, UserDto, UsersStatisticsResponse } from "../../dto/userInfoResponse"
4
4
  import { Workspaces } from "../workspaces/workspaces"
5
5
  import { WorkspacesImpl } from "../workspaces/workspaces.impl"
6
6
  import { Context } from "../../context"
@@ -11,6 +11,7 @@ import { ChatsImpl } from "../chats/chats.impl"
11
11
  import { Chats } from "../chats/chats"
12
12
  import { RpcService } from "../../services/rpcService"
13
13
  import { ResponseUtils } from "../../services/responseUtils"
14
+ import { StatisticsResponse } from "../../dto/statisticsResponse"
14
15
 
15
16
  export class OrganizationImpl extends Organization implements Disposable {
16
17
  private _isDisposed: boolean = false
@@ -146,6 +147,70 @@ export class OrganizationImpl extends Organization implements Disposable {
146
147
  })
147
148
  }
148
149
 
150
+ async statistics(dateFrom: number, dateTo: number): Promise<StatisticsResponse> {
151
+ // send request to the server
152
+ const response = await this.context
153
+ .resolve(RpcService)
154
+ ?.requestBuilder("api/v1/Stats/organization")
155
+ .searchParam("organizationId", this.id)
156
+ .searchParam("dateFrom", dateFrom.toString())
157
+ .searchParam("dateTo", dateTo.toString())
158
+ .sendGet()
159
+
160
+ // check response status
161
+ if (ResponseUtils.isFail(response)) {
162
+ await ResponseUtils.throwError(
163
+ `Failed during fetch of organization statistics ${this.id}`,
164
+ response
165
+ )
166
+ }
167
+
168
+ return await response!.json() as StatisticsResponse
169
+ }
170
+
171
+ async membersStatistics(dateFrom: number, dateTo: number): Promise<UsersStatisticsResponse> {
172
+ // send request to the server
173
+ const response = await this.context
174
+ .resolve(RpcService)
175
+ ?.requestBuilder("api/v1/Stats/organization/members")
176
+ .searchParam("organizationId", this.id)
177
+ .searchParam("dateFrom", dateFrom.toString())
178
+ .searchParam("dateTo", dateTo.toString())
179
+ .sendGet()
180
+
181
+ // check response status
182
+ if (ResponseUtils.isFail(response)) {
183
+ await ResponseUtils.throwError(
184
+ `Failed during fetch of organization members statistics ${this.id}`,
185
+ response
186
+ )
187
+ }
188
+
189
+ return await response!.json() as UsersStatisticsResponse
190
+ }
191
+
192
+ async userStatistic(userId: string, dateFrom: number, dateTo: number): Promise<StatisticsResponse> {
193
+ // send request to the server
194
+ const response = await this.context
195
+ .resolve(RpcService)
196
+ ?.requestBuilder("api/v1/Stats/user")
197
+ .searchParam("userId", userId)
198
+ .searchParam("organizationId", this.id)
199
+ .searchParam("dateFrom", dateFrom.toString())
200
+ .searchParam("dateTo", dateTo.toString())
201
+ .sendGet()
202
+
203
+ // check response status
204
+ if (ResponseUtils.isFail(response)) {
205
+ await ResponseUtils.throwError(
206
+ `Failed during fetch of user statistics ${this.id}`,
207
+ response
208
+ )
209
+ }
210
+
211
+ return await response!.json() as StatisticsResponse
212
+ }
213
+
149
214
  async createInviteLink(emails: string[], accessGroups: string[]): Promise<void> {
150
215
  const response = await this.context
151
216
  .resolve(RpcService)
@@ -3,8 +3,9 @@ import { OrganizationId } from "./organizations"
3
3
  import { Groups } from "../groups/groups"
4
4
  import { Chats } from "../chats/chats"
5
5
  import { EventDispatcher } from "../../events"
6
- import { UserDto } from "../../dto/userInfoResponse"
6
+ import { UserDto, UsersStatisticsResponse } from "../../dto/userInfoResponse"
7
7
  import { GroupId } from "../groups/group"
8
+ import { StatisticsResponse } from "../../dto/statisticsResponse"
8
9
 
9
10
  /**
10
11
  * Organization event.
@@ -55,6 +56,29 @@ export abstract class Organization extends EventDispatcher<
55
56
  */
56
57
  abstract members(): Promise<UserDto[]>
57
58
 
59
+ /**
60
+ * Get organization statistics
61
+ * @param dateFrom
62
+ * @param dateTo
63
+ */
64
+ abstract statistics(dateFrom: number, dateTo: number): Promise<StatisticsResponse>
65
+
66
+
67
+ /**
68
+ * Get organization statistics
69
+ * @param dateFrom
70
+ * @param dateTo
71
+ */
72
+ abstract membersStatistics(dateFrom: number, dateTo: number): Promise<UsersStatisticsResponse>
73
+
74
+
75
+ /**
76
+ * Get statistics for user
77
+ * @param dateFrom
78
+ * @param dateTo
79
+ */
80
+ abstract userStatistic(userid: string, dateFrom: number, dateTo: number): Promise<StatisticsResponse>
81
+
58
82
  /**
59
83
  * Change organization name and description.
60
84
  */
@@ -4,6 +4,7 @@ import { UserInfoResponse } from "../../dto/userInfoResponse"
4
4
  export class UserProfileImpl extends UserProfile {
5
5
  private content?: UserInfoResponse
6
6
 
7
+
7
8
  get id(): string {
8
9
  if (this.content) {
9
10
  return this.content.user.id
@@ -60,4 +61,5 @@ export class UserProfileImpl extends UserProfile {
60
61
  data: this
61
62
  })
62
63
  }
64
+
63
65
  }
@@ -11,9 +11,7 @@ const getNavigator = () => {
11
11
  if (!(globalThis as any).navigator) {
12
12
  (globalThis as any).navigator = {
13
13
  userAgent: "",
14
- language: "",
15
- hardwareConcurrency: 0,
16
- cookieEnabled: false
14
+ hardwareConcurrency: 0
17
15
  }
18
16
  }
19
17
  return navigator
@@ -61,9 +59,7 @@ export const createFingerprint = () => {
61
59
  const fingerprint = new Map<string, any>()
62
60
 
63
61
  fingerprint.set("userAgent", nav.userAgent)
64
- fingerprint.set("language", nav.language)
65
62
  fingerprint.set("hardware_concurrency", nav.hardwareConcurrency)
66
- fingerprint.set("cookie_enabled", nav.cookieEnabled)
67
63
  fingerprint.set("pixel_ratio", win.devicePixelRatio)
68
64
  fingerprint.set("session_storage", win.sessionStorage)
69
65
  fingerprint.set("local_storage", win.localStorage)
@@ -0,0 +1,8 @@
1
+ // check if the object is null or undefined
2
+ export const isNullOrUndefined = (object: unknown): object is null | undefined => {
3
+ return object === null || object === undefined
4
+ }
5
+
6
+ export const isEmptyNullOrUndefined = (object: unknown): boolean => {
7
+ return isNullOrUndefined(object) || object === ""
8
+ }