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

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/dist/package.json +1 -1
  2. package/dist/src/dto/badRequestResponse.d.ts +6 -0
  3. package/dist/src/dto/badRequestResponse.d.ts.map +1 -0
  4. package/dist/src/dto/badRequestResponse.js +3 -0
  5. package/dist/src/dto/badRequestResponse.js.map +1 -0
  6. package/dist/src/dto/limitsResponse.d.ts +27 -0
  7. package/dist/src/dto/limitsResponse.d.ts.map +1 -0
  8. package/dist/src/dto/limitsResponse.js +11 -0
  9. package/dist/src/dto/limitsResponse.js.map +1 -0
  10. package/dist/src/dto/userInfoResponse.d.ts +34 -0
  11. package/dist/src/dto/userInfoResponse.d.ts.map +1 -1
  12. package/dist/src/services/responseUtils.d.ts +1 -0
  13. package/dist/src/services/responseUtils.d.ts.map +1 -1
  14. package/dist/src/services/responseUtils.js +8 -0
  15. package/dist/src/services/responseUtils.js.map +1 -1
  16. package/dist/src/services/userProfileService.d.ts.map +1 -1
  17. package/dist/src/services/userProfileService.js +1 -1
  18. package/dist/src/services/userProfileService.js.map +1 -1
  19. package/dist/src/storages/chats/chat.d.ts +1 -1
  20. package/dist/src/storages/chats/chat.d.ts.map +1 -1
  21. package/dist/src/storages/chats/chat.impl.d.ts +1 -1
  22. package/dist/src/storages/chats/chat.impl.d.ts.map +1 -1
  23. package/dist/src/storages/chats/chat.impl.js +3 -0
  24. package/dist/src/storages/chats/chat.impl.js.map +1 -1
  25. package/dist/src/storages/chats/chats.d.ts +2 -2
  26. package/dist/src/storages/chats/chats.d.ts.map +1 -1
  27. package/dist/src/storages/chats/chats.impl.d.ts +2 -2
  28. package/dist/src/storages/chats/chats.impl.d.ts.map +1 -1
  29. package/dist/src/storages/chats/chats.impl.js +6 -0
  30. package/dist/src/storages/chats/chats.impl.js.map +1 -1
  31. package/dist/src/storages/files/files.impl.d.ts +1 -1
  32. package/dist/src/storages/files/files.impl.d.ts.map +1 -1
  33. package/dist/src/storages/files/files.impl.js +7 -1
  34. package/dist/src/storages/files/files.impl.js.map +1 -1
  35. package/dist/src/storages/organizations/organization.d.ts +14 -1
  36. package/dist/src/storages/organizations/organization.d.ts.map +1 -1
  37. package/dist/src/storages/organizations/organization.impl.d.ts +5 -1
  38. package/dist/src/storages/organizations/organization.impl.d.ts.map +1 -1
  39. package/dist/src/storages/organizations/organization.impl.js +65 -0
  40. package/dist/src/storages/organizations/organization.impl.js.map +1 -1
  41. package/dist/src/storages/organizations/organization.js.map +1 -1
  42. package/dist/src/storages/user/userProfile.d.ts +14 -0
  43. package/dist/src/storages/user/userProfile.d.ts.map +1 -1
  44. package/dist/src/storages/user/userProfile.impl.d.ts +6 -0
  45. package/dist/src/storages/user/userProfile.impl.d.ts.map +1 -1
  46. package/dist/src/storages/user/userProfile.impl.js +49 -0
  47. package/dist/src/storages/user/userProfile.impl.js.map +1 -1
  48. package/dist/src/storages/user/userProfile.js.map +1 -1
  49. package/dist/src/storages/workspaces/workspaces.d.ts +1 -1
  50. package/dist/src/storages/workspaces/workspaces.d.ts.map +1 -1
  51. package/dist/src/storages/workspaces/workspaces.impl.d.ts +1 -1
  52. package/dist/src/storages/workspaces/workspaces.impl.d.ts.map +1 -1
  53. package/dist/src/storages/workspaces/workspaces.impl.js +3 -0
  54. package/dist/src/storages/workspaces/workspaces.impl.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/userInfoResponse.ts +42 -1
  59. package/src/services/responseUtils.ts +10 -0
  60. package/src/services/userProfileService.ts +1 -1
  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 +92 -1
  67. package/src/storages/organizations/organization.ts +18 -1
  68. package/src/storages/user/userProfile.impl.ts +62 -0
  69. package/src/storages/user/userProfile.ts +17 -0
  70. package/src/storages/workspaces/workspaces.impl.ts +5 -1
  71. package/src/storages/workspaces/workspaces.ts +1 -1
@@ -3,9 +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, UsersStatisticsResponse } from "../../dto/userInfoResponse"
6
+ import { CurrentLimitsData, UserDto, UsersStatisticsResponse } from "../../dto/userInfoResponse"
7
7
  import { GroupId } from "../groups/group"
8
8
  import { StatisticsResponse } from "../../dto/statisticsResponse"
9
+ import { SegmentData } from "../../dto/limitsResponse"
9
10
 
10
11
  /**
11
12
  * Organization event.
@@ -79,6 +80,22 @@ export abstract class Organization extends EventDispatcher<
79
80
  */
80
81
  abstract userStatistic(userid: string, dateFrom: number, dateTo: number): Promise<StatisticsResponse>
81
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
+
82
99
  /**
83
100
  * Change organization name and description.
84
101
  */
@@ -1,10 +1,17 @@
1
1
  import { UserEvent, UserProfile } from "./userProfile"
2
2
  import { UserInfoResponse } from "../../dto/userInfoResponse"
3
+ import { Context } from "../../context"
4
+ import { RpcService } from "../../services/rpcService"
5
+ import { ResponseUtils } from "../../services/responseUtils"
3
6
 
4
7
  export class UserProfileImpl extends UserProfile {
5
8
  private content?: UserInfoResponse
6
9
 
7
10
 
11
+ constructor(private readonly context: Context) {
12
+ super()
13
+ }
14
+
8
15
  get id(): string {
9
16
  if (this.content) {
10
17
  return this.content.user.id
@@ -26,6 +33,13 @@ export class UserProfileImpl extends UserProfile {
26
33
  throw new Error("The profile is not loaded.")
27
34
  }
28
35
 
36
+ get binanceId(): string {
37
+ if (this.content) {
38
+ return this.content.user.profile.binanceId
39
+ }
40
+ throw new Error("The profile is not loaded.")
41
+ }
42
+
29
43
  get isDeleted(): boolean {
30
44
  if (this.content) {
31
45
  return this.content.user.isDeleted
@@ -62,4 +76,52 @@ export class UserProfileImpl extends UserProfile {
62
76
  })
63
77
  }
64
78
 
79
+ async updateUser(newName: string, newId: string): Promise<void>{
80
+ if (!this.content) {
81
+ throw new Error("User is not loaded.")
82
+ }
83
+
84
+ if (newName === this.name && newId === this.binanceId) {
85
+ return Promise.resolve()
86
+ }
87
+
88
+ const response = await this.context
89
+ .resolve(RpcService)
90
+ ?.requestBuilder("api/v1/Users")
91
+ .sendPutJson({
92
+ profile: {
93
+ newName,
94
+ undefined,
95
+ newId,
96
+ }
97
+ })
98
+
99
+ if (ResponseUtils.isFail(response)) {
100
+ await ResponseUtils.throwError("Failed to change organization", response)
101
+ }
102
+
103
+ if (this.content) {
104
+ this.content!.user.profile.name = newName
105
+ this.content!.user.profile.binanceId = newId
106
+ }
107
+
108
+ this.dispatch({
109
+ type: UserEvent.CHANGED,
110
+ data: this
111
+ })
112
+ }
113
+
114
+ async deleteUser(): Promise<boolean>{
115
+ const response = await this.context
116
+ .resolve(RpcService)?.
117
+ requestBuilder("/api/v1/Users/self")
118
+ .sendDelete()
119
+
120
+ if (ResponseUtils.isFail(response)) {
121
+ await ResponseUtils.throwError("Failed to delete user", response)
122
+ }
123
+
124
+ return true
125
+ }
126
+
65
127
  }
@@ -25,6 +25,11 @@ export abstract class UserProfile extends EventDispatcher<
25
25
  */
26
26
  abstract get email(): string
27
27
 
28
+ /**
29
+ * Additional binance ID
30
+ */
31
+ abstract get binanceId(): string
32
+
28
33
  /**
29
34
  * Is user deleted.
30
35
  */
@@ -44,4 +49,16 @@ export abstract class UserProfile extends EventDispatcher<
44
49
  * Modified at.
45
50
  */
46
51
  abstract get modifiedAt(): Date
52
+
53
+ /**
54
+ * Update user profile
55
+ * @param newName
56
+ * @param newId
57
+ */
58
+ abstract updateUser(newName: string, newId: string): Promise<void>
59
+
60
+ /**
61
+ * Delete User
62
+ */
63
+ abstract deleteUser(): Promise<boolean>
47
64
  }
@@ -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.