@neuralinnovations/dataisland-sdk 0.0.1-dev32 → 0.0.1-dev34

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 (71) hide show
  1. package/README.md +14 -3
  2. package/dist/package.json +1 -1
  3. package/dist/src/dto/badRequestResponse.d.ts +6 -0
  4. package/dist/src/dto/badRequestResponse.d.ts.map +1 -0
  5. package/dist/src/dto/badRequestResponse.js +3 -0
  6. package/dist/src/dto/badRequestResponse.js.map +1 -0
  7. package/dist/src/dto/limitsResponse.d.ts +27 -0
  8. package/dist/src/dto/limitsResponse.d.ts.map +1 -0
  9. package/dist/src/dto/limitsResponse.js +11 -0
  10. package/dist/src/dto/limitsResponse.js.map +1 -0
  11. package/dist/src/dto/statisticsResponse.d.ts +11 -0
  12. package/dist/src/dto/statisticsResponse.d.ts.map +1 -0
  13. package/dist/src/dto/statisticsResponse.js +3 -0
  14. package/dist/src/dto/statisticsResponse.js.map +1 -0
  15. package/dist/src/dto/userInfoResponse.d.ts +43 -0
  16. package/dist/src/dto/userInfoResponse.d.ts.map +1 -1
  17. package/dist/src/services/responseUtils.d.ts +1 -0
  18. package/dist/src/services/responseUtils.d.ts.map +1 -1
  19. package/dist/src/services/responseUtils.js +8 -0
  20. package/dist/src/services/responseUtils.js.map +1 -1
  21. package/dist/src/storages/chats/chat.d.ts +1 -1
  22. package/dist/src/storages/chats/chat.d.ts.map +1 -1
  23. package/dist/src/storages/chats/chat.impl.d.ts +1 -1
  24. package/dist/src/storages/chats/chat.impl.d.ts.map +1 -1
  25. package/dist/src/storages/chats/chat.impl.js +3 -0
  26. package/dist/src/storages/chats/chat.impl.js.map +1 -1
  27. package/dist/src/storages/chats/chats.d.ts +2 -2
  28. package/dist/src/storages/chats/chats.d.ts.map +1 -1
  29. package/dist/src/storages/chats/chats.impl.d.ts +2 -2
  30. package/dist/src/storages/chats/chats.impl.d.ts.map +1 -1
  31. package/dist/src/storages/chats/chats.impl.js +6 -0
  32. package/dist/src/storages/chats/chats.impl.js.map +1 -1
  33. package/dist/src/storages/files/files.impl.d.ts +1 -1
  34. package/dist/src/storages/files/files.impl.d.ts.map +1 -1
  35. package/dist/src/storages/files/files.impl.js +7 -1
  36. package/dist/src/storages/files/files.impl.js.map +1 -1
  37. package/dist/src/storages/organizations/organization.d.ts +33 -1
  38. package/dist/src/storages/organizations/organization.d.ts.map +1 -1
  39. package/dist/src/storages/organizations/organization.impl.d.ts +9 -1
  40. package/dist/src/storages/organizations/organization.impl.d.ts.map +1 -1
  41. package/dist/src/storages/organizations/organization.impl.js +98 -0
  42. package/dist/src/storages/organizations/organization.impl.js.map +1 -1
  43. package/dist/src/storages/organizations/organization.js.map +1 -1
  44. package/dist/src/storages/user/userProfile.impl.d.ts.map +1 -1
  45. package/dist/src/storages/user/userProfile.impl.js.map +1 -1
  46. package/dist/src/storages/workspaces/workspaces.d.ts +1 -1
  47. package/dist/src/storages/workspaces/workspaces.d.ts.map +1 -1
  48. package/dist/src/storages/workspaces/workspaces.impl.d.ts +1 -1
  49. package/dist/src/storages/workspaces/workspaces.impl.d.ts.map +1 -1
  50. package/dist/src/storages/workspaces/workspaces.impl.js +3 -0
  51. package/dist/src/storages/workspaces/workspaces.impl.js.map +1 -1
  52. package/dist/src/utils/browserUtils.d.ts.map +1 -1
  53. package/dist/src/utils/browserUtils.js +1 -5
  54. package/dist/src/utils/browserUtils.js.map +1 -1
  55. package/package.json +1 -1
  56. package/src/dto/badRequestResponse.ts +6 -0
  57. package/src/dto/limitsResponse.ts +31 -0
  58. package/src/dto/statisticsResponse.ts +12 -0
  59. package/src/dto/userInfoResponse.ts +52 -0
  60. package/src/services/responseUtils.ts +10 -0
  61. package/src/storages/chats/chat.impl.ts +5 -1
  62. package/src/storages/chats/chat.ts +1 -1
  63. package/src/storages/chats/chats.impl.ts +10 -2
  64. package/src/storages/chats/chats.ts +2 -2
  65. package/src/storages/files/files.impl.ts +9 -2
  66. package/src/storages/organizations/organization.impl.ts +157 -1
  67. package/src/storages/organizations/organization.ts +42 -1
  68. package/src/storages/user/userProfile.impl.ts +2 -0
  69. package/src/storages/workspaces/workspaces.impl.ts +5 -1
  70. package/src/storages/workspaces/workspaces.ts +1 -1
  71. package/src/utils/browserUtils.ts +1 -5
@@ -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 { CurrentLimitItem, CurrentLimitRecordData, CurrentLimitsData, OrganizationDto, OrganizationSegmentData, UserDto, UserLimitsData, 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,8 @@ 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"
15
+ import { LimitActionType, SegmentData, SegmentsData } from "../../dto/limitsResponse"
14
16
 
15
17
  export class OrganizationImpl extends Organization implements Disposable {
16
18
  private _isDisposed: boolean = false
@@ -146,6 +148,160 @@ export class OrganizationImpl extends Organization implements Disposable {
146
148
  })
147
149
  }
148
150
 
151
+ async statistics(dateFrom: number, dateTo: number): Promise<StatisticsResponse> {
152
+ // send request to the server
153
+ const response = await this.context
154
+ .resolve(RpcService)
155
+ ?.requestBuilder("api/v1/Stats/organization")
156
+ .searchParam("organizationId", this.id)
157
+ .searchParam("dateFrom", dateFrom.toString())
158
+ .searchParam("dateTo", dateTo.toString())
159
+ .sendGet()
160
+
161
+ // check response status
162
+ if (ResponseUtils.isFail(response)) {
163
+ await ResponseUtils.throwError(
164
+ `Failed during fetch of organization statistics ${this.id}`,
165
+ response
166
+ )
167
+ }
168
+
169
+ return await response!.json() as StatisticsResponse
170
+ }
171
+
172
+ async membersStatistics(dateFrom: number, dateTo: number): Promise<UsersStatisticsResponse> {
173
+ // send request to the server
174
+ const response = await this.context
175
+ .resolve(RpcService)
176
+ ?.requestBuilder("api/v1/Stats/organization/members")
177
+ .searchParam("organizationId", this.id)
178
+ .searchParam("dateFrom", dateFrom.toString())
179
+ .searchParam("dateTo", dateTo.toString())
180
+ .sendGet()
181
+
182
+ // check response status
183
+ if (ResponseUtils.isFail(response)) {
184
+ await ResponseUtils.throwError(
185
+ `Failed during fetch of organization members statistics ${this.id}`,
186
+ response
187
+ )
188
+ }
189
+
190
+ return await response!.json() as UsersStatisticsResponse
191
+ }
192
+
193
+ async userStatistic(userId: string, dateFrom: number, dateTo: number): Promise<StatisticsResponse> {
194
+ // send request to the server
195
+ const response = await this.context
196
+ .resolve(RpcService)
197
+ ?.requestBuilder("api/v1/Stats/user")
198
+ .searchParam("userId", userId)
199
+ .searchParam("organizationId", this.id)
200
+ .searchParam("dateFrom", dateFrom.toString())
201
+ .searchParam("dateTo", dateTo.toString())
202
+ .sendGet()
203
+
204
+ // check response status
205
+ if (ResponseUtils.isFail(response)) {
206
+ await ResponseUtils.throwError(
207
+ `Failed during fetch of user statistics ${this.id}`,
208
+ response
209
+ )
210
+ }
211
+
212
+ return await response!.json() as StatisticsResponse
213
+ }
214
+
215
+ async userLimits(): Promise<CurrentLimitsData> {
216
+ // fetch limits
217
+ const response = await this.context.resolve(RpcService)
218
+ ?.requestBuilder("api/v1/Users/limits")
219
+ .searchParam("organizationId", this.id)
220
+ .sendGet()
221
+
222
+ // check response status
223
+ if (ResponseUtils.isFail(response)) {
224
+ await ResponseUtils.throwError(`Failed to get limits in organization: ${this.id}`, response)
225
+ }
226
+
227
+ // parse limits from the server's response
228
+ const limits = (await response!.json()) as UserLimitsData
229
+
230
+ const currentLimits = { segment: limits.userSegment.key, limits : [] } as CurrentLimitsData
231
+ for (const limit of limits.userLimits){
232
+ const type = limit.action as LimitActionType
233
+ const currentItem = { action : type, records: []} as CurrentLimitItem
234
+
235
+ if (limit.records.length == 0) continue
236
+
237
+ for (const record of limit.records) {
238
+ const segmentRecord = limits.userSegment.dayItems.find(item => item.daysCount == record.daysCount)
239
+ if (segmentRecord == null){
240
+ await ResponseUtils.throwError(`Invalid response during get limits in organization: ${this.id}. Days count with ${type} not found in segment ${limits.userSegment.key}`, response)
241
+ continue
242
+ }
243
+ const actionRecord = segmentRecord?.actionItems.find(item => item.type == type)
244
+ if (actionRecord == null){
245
+ await ResponseUtils.throwError(`Invalid response during get limits in organization: ${this.id}. Type ${type} not found in segment ${limits.userSegment.key}`, response)
246
+ continue
247
+ }
248
+
249
+ const currentRecord = {} as CurrentLimitRecordData
250
+ currentRecord.daysCount = record.daysCount
251
+ currentRecord.activeTill = record.activeTill
252
+ currentRecord.all = actionRecord?.tokenLimit ?? actionRecord?.countLimit
253
+
254
+ const available = record.tokenLimit ?? record.countLimit
255
+ currentRecord.used = currentRecord.all - available
256
+
257
+ currentItem.records.push(currentRecord)
258
+ }
259
+
260
+ currentLimits.limits.push(currentItem)
261
+ }
262
+
263
+ return currentLimits
264
+ }
265
+
266
+ async organizationLimits(): Promise<SegmentData> {
267
+ // fetch limits
268
+ const response = await this.context.resolve(RpcService)
269
+ ?.requestBuilder("api/v1/Descriptions/limits/organization")
270
+ .searchParam("organizationId", this.id)
271
+ .sendGet()
272
+
273
+ // check response status
274
+ if (ResponseUtils.isFail(response)) {
275
+ await ResponseUtils.throwError(`Failed to get limits in organization: ${this.id}`, response)
276
+ }
277
+
278
+ const json = await response!.json()
279
+
280
+ // parse limits from the server's response
281
+ const limits = (json as OrganizationSegmentData).segment
282
+
283
+ return limits
284
+ }
285
+
286
+ async limitSegments(): Promise<SegmentData[]> {
287
+ // fetch limits
288
+ const response = await this.context.resolve(RpcService)
289
+ ?.requestBuilder("api/v1/Descriptions/limits/segments")
290
+ .searchParam("organizationId", this.id)
291
+ .sendGet()
292
+
293
+ // check response status
294
+ if (ResponseUtils.isFail(response)) {
295
+ await ResponseUtils.throwError(`Failed to get limits in organization: ${this.id}`, response)
296
+ }
297
+ const json = await response!.json()
298
+
299
+ // parse limits from the server's response
300
+ const limits = (json as SegmentsData).segments
301
+
302
+ return limits
303
+ }
304
+
149
305
  async createInviteLink(emails: string[], accessGroups: string[]): Promise<void> {
150
306
  const response = await this.context
151
307
  .resolve(RpcService)
@@ -3,8 +3,10 @@ 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 { CurrentLimitsData, UserDto, UsersStatisticsResponse } from "../../dto/userInfoResponse"
7
7
  import { GroupId } from "../groups/group"
8
+ import { StatisticsResponse } from "../../dto/statisticsResponse"
9
+ import { SegmentData } from "../../dto/limitsResponse"
8
10
 
9
11
  /**
10
12
  * Organization event.
@@ -55,6 +57,45 @@ export abstract class Organization extends EventDispatcher<
55
57
  */
56
58
  abstract members(): Promise<UserDto[]>
57
59
 
60
+ /**
61
+ * Get organization statistics
62
+ * @param dateFrom
63
+ * @param dateTo
64
+ */
65
+ abstract statistics(dateFrom: number, dateTo: number): Promise<StatisticsResponse>
66
+
67
+
68
+ /**
69
+ * Get organization statistics
70
+ * @param dateFrom
71
+ * @param dateTo
72
+ */
73
+ abstract membersStatistics(dateFrom: number, dateTo: number): Promise<UsersStatisticsResponse>
74
+
75
+
76
+ /**
77
+ * Get statistics for user
78
+ * @param dateFrom
79
+ * @param dateTo
80
+ */
81
+ abstract userStatistic(userid: string, dateFrom: number, dateTo: number): Promise<StatisticsResponse>
82
+
83
+
84
+ /**
85
+ * Get user limits data
86
+ */
87
+ abstract userLimits(): Promise<CurrentLimitsData>
88
+
89
+ /**
90
+ * Get default organization limits
91
+ */
92
+ abstract organizationLimits(): Promise<SegmentData>
93
+
94
+ /**
95
+ * Get all available segments data
96
+ */
97
+ abstract limitSegments(): Promise<SegmentData[]>
98
+
58
99
  /**
59
100
  * Change organization name and description.
60
101
  */
@@ -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
  }
@@ -51,7 +51,7 @@ export class WorkspacesImpl extends Workspaces {
51
51
  newGroupName: string
52
52
  groupIds: string[]
53
53
  }
54
- ): Promise<Workspace> {
54
+ ): Promise<Workspace | undefined> {
55
55
  if (name === undefined || name === null || name.trim() === "") {
56
56
  throw new Error("Name is required, must be not empty")
57
57
  }
@@ -104,6 +104,10 @@ export class WorkspacesImpl extends Workspaces {
104
104
 
105
105
  // check response status
106
106
  if (ResponseUtils.isFail(response)) {
107
+ if (await ResponseUtils.isLimitReached()){
108
+ return undefined
109
+ }
110
+
107
111
  await ResponseUtils.throwError(`Failed to create workspace, in organization: ${this.organization.id}`, response)
108
112
  }
109
113
 
@@ -48,7 +48,7 @@ export abstract class Workspaces extends EventDispatcher<
48
48
  isCreateNewGroup: boolean,
49
49
  newGroupName: string,
50
50
  groupIds: string[]
51
- }): Promise<Workspace>
51
+ }): Promise<Workspace | undefined>
52
52
 
53
53
  /**
54
54
  * Delete workspace.
@@ -11,9 +11,7 @@ const getNavigator = () => {
11
11
  if (!(globalThis as any).navigator) {
12
12
  (globalThis as any).navigator = {
13
13
  userAgent: "",
14
- language: "ua",
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)