@neuralinnovations/dataisland-sdk 0.6.30 → 0.6.32

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 (83) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/commands/startCommandHandler.js +6 -6
  3. package/dist/src/commands/startCommandHandler.js.map +1 -1
  4. package/dist/src/dto/chatbotAccountResponse.d.ts +23 -0
  5. package/dist/src/dto/chatbotAccountResponse.d.ts.map +1 -0
  6. package/dist/src/dto/chatbotAccountResponse.js +11 -0
  7. package/dist/src/dto/chatbotAccountResponse.js.map +1 -0
  8. package/dist/src/dto/instaResponse.d.ts +6 -0
  9. package/dist/src/dto/instaResponse.d.ts.map +1 -1
  10. package/dist/src/dto/instaResponse.js.map +1 -1
  11. package/dist/src/storages/chatbot/chatbotAccount.d.ts +8 -0
  12. package/dist/src/storages/chatbot/chatbotAccount.d.ts.map +1 -0
  13. package/dist/src/storages/chatbot/chatbotAccount.impl.d.ts +12 -0
  14. package/dist/src/storages/chatbot/chatbotAccount.impl.d.ts.map +1 -0
  15. package/dist/src/storages/chatbot/chatbotAccount.impl.js +38 -0
  16. package/dist/src/storages/chatbot/chatbotAccount.impl.js.map +1 -0
  17. package/dist/src/storages/chatbot/chatbotAccount.js +7 -0
  18. package/dist/src/storages/chatbot/chatbotAccount.js.map +1 -0
  19. package/dist/src/storages/chatbot/chatbotAccounts.d.ts +9 -0
  20. package/dist/src/storages/chatbot/chatbotAccounts.d.ts.map +1 -0
  21. package/dist/src/storages/chatbot/chatbotAccounts.impl.d.ts +16 -0
  22. package/dist/src/storages/chatbot/chatbotAccounts.impl.d.ts.map +1 -0
  23. package/dist/src/storages/chatbot/chatbotAccounts.impl.js +92 -0
  24. package/dist/src/storages/chatbot/chatbotAccounts.impl.js.map +1 -0
  25. package/dist/src/storages/chatbot/chatbotAccounts.js +7 -0
  26. package/dist/src/storages/chatbot/chatbotAccounts.js.map +1 -0
  27. package/dist/src/storages/chats/chats.d.ts +4 -0
  28. package/dist/src/storages/chats/chats.d.ts.map +1 -1
  29. package/dist/src/storages/chats/chats.impl.d.ts +1 -1
  30. package/dist/src/storages/chats/chats.impl.d.ts.map +1 -1
  31. package/dist/src/storages/chats/chats.impl.js +2 -2
  32. package/dist/src/storages/chats/chats.impl.js.map +1 -1
  33. package/dist/src/storages/chats/chats.js.map +1 -1
  34. package/dist/src/storages/groups/groups.impl.d.ts +0 -1
  35. package/dist/src/storages/groups/groups.impl.d.ts.map +1 -1
  36. package/dist/src/storages/groups/groups.impl.js +0 -3
  37. package/dist/src/storages/groups/groups.impl.js.map +1 -1
  38. package/dist/src/storages/insta/instaAccounts.d.ts +2 -0
  39. package/dist/src/storages/insta/instaAccounts.d.ts.map +1 -1
  40. package/dist/src/storages/insta/instaAccounts.impl.d.ts +2 -0
  41. package/dist/src/storages/insta/instaAccounts.impl.d.ts.map +1 -1
  42. package/dist/src/storages/insta/instaAccounts.impl.js +11 -0
  43. package/dist/src/storages/insta/instaAccounts.impl.js.map +1 -1
  44. package/dist/src/storages/insta/instaAccounts.js.map +1 -1
  45. package/dist/src/storages/organizations/organization.d.ts +5 -0
  46. package/dist/src/storages/organizations/organization.d.ts.map +1 -1
  47. package/dist/src/storages/organizations/organization.impl.d.ts +3 -0
  48. package/dist/src/storages/organizations/organization.impl.d.ts.map +1 -1
  49. package/dist/src/storages/organizations/organization.impl.js +11 -6
  50. package/dist/src/storages/organizations/organization.impl.js.map +1 -1
  51. package/dist/src/storages/organizations/organization.js.map +1 -1
  52. package/dist/src/storages/queryFlows/queryFlows.d.ts +1 -1
  53. package/dist/src/storages/queryFlows/queryFlows.d.ts.map +1 -1
  54. package/dist/src/storages/queryFlows/queryFlows.impl.d.ts +1 -1
  55. package/dist/src/storages/queryFlows/queryFlows.impl.d.ts.map +1 -1
  56. package/dist/src/storages/queryFlows/queryFlows.impl.js +2 -6
  57. package/dist/src/storages/queryFlows/queryFlows.impl.js.map +1 -1
  58. package/dist/src/storages/workspaces/workspaces.d.ts +4 -0
  59. package/dist/src/storages/workspaces/workspaces.d.ts.map +1 -1
  60. package/dist/src/storages/workspaces/workspaces.impl.d.ts +1 -2
  61. package/dist/src/storages/workspaces/workspaces.impl.d.ts.map +1 -1
  62. package/dist/src/storages/workspaces/workspaces.impl.js +3 -3
  63. package/dist/src/storages/workspaces/workspaces.impl.js.map +1 -1
  64. package/dist/src/storages/workspaces/workspaces.js.map +1 -1
  65. package/package.json +1 -1
  66. package/src/commands/startCommandHandler.ts +6 -6
  67. package/src/dto/chatbotAccountResponse.ts +29 -0
  68. package/src/dto/instaResponse.ts +9 -0
  69. package/src/storages/chatbot/chatbotAccount.impl.ts +47 -0
  70. package/src/storages/chatbot/chatbotAccount.ts +15 -0
  71. package/src/storages/chatbot/chatbotAccounts.impl.ts +124 -0
  72. package/src/storages/chatbot/chatbotAccounts.ts +14 -0
  73. package/src/storages/chats/chats.impl.ts +2 -2
  74. package/src/storages/chats/chats.ts +5 -0
  75. package/src/storages/groups/groups.impl.ts +0 -4
  76. package/src/storages/insta/instaAccounts.impl.ts +21 -0
  77. package/src/storages/insta/instaAccounts.ts +3 -0
  78. package/src/storages/organizations/organization.impl.ts +14 -6
  79. package/src/storages/organizations/organization.ts +6 -0
  80. package/src/storages/queryFlows/queryFlows.impl.ts +2 -6
  81. package/src/storages/queryFlows/queryFlows.ts +1 -1
  82. package/src/storages/workspaces/workspaces.impl.ts +3 -4
  83. package/src/storages/workspaces/workspaces.ts +5 -0
@@ -0,0 +1,124 @@
1
+
2
+ import {OrganizationImpl} from "../organizations/organization.impl"
3
+ import {Context} from "../../context"
4
+ import {RpcService} from "../../services/rpcService"
5
+ import {ResponseUtils} from "../../services/responseUtils"
6
+ import { ChatbotAccounts } from "./chatbotAccounts"
7
+ import { ChatbotAccount } from "./chatbotAccount"
8
+ import { ChatbotAccountImpl } from "./chatbotAccount.impl"
9
+ import { ChatbotAccountDto, ChatbotAccountType, KeyValueItem } from "../../dto/chatbotAccountResponse"
10
+
11
+
12
+ export class ChatbotAccountsImpl extends ChatbotAccounts {
13
+ private _collection?: ChatbotAccountImpl[]
14
+
15
+ constructor(
16
+ public readonly organization: OrganizationImpl,
17
+ public readonly context: Context) {
18
+ super()
19
+ }
20
+
21
+ get collection(): ChatbotAccount[] {
22
+ if (this._collection !== undefined) {
23
+ return this._collection
24
+ }else {
25
+ throw new Error("Chatbot accounts collection is not loaded, please update it first")
26
+ }
27
+ }
28
+
29
+
30
+ async update(): Promise<void> {
31
+ const response = await this.context
32
+ .resolve(RpcService)
33
+ ?.requestBuilder("api/v1/ChatbotAccount/list")
34
+ .searchParam("organizationId", this.organization.id)
35
+ .sendGet()
36
+
37
+ // check response status
38
+ if (ResponseUtils.isFail(response)) {
39
+ await ResponseUtils.throwError(
40
+ `Chatbot accounts list for organization ${this.organization.id} failed`,
41
+ response
42
+ )
43
+ }
44
+
45
+ this._collection = []
46
+ const accounts = (await response!.json() as {accounts: ChatbotAccountDto[]}).accounts
47
+ this._collection = accounts.map(acc => new ChatbotAccountImpl(this.context, acc))
48
+ }
49
+
50
+ async add(type: ChatbotAccountType, name: string, accountId: string, token: string, accountContext: string, notificationDelays: number[], data: KeyValueItem[]): Promise<void> {
51
+
52
+ if (type === undefined || type === null) {
53
+ throw new Error("Add chatbot account, type can not be null")
54
+ }
55
+ if (name === undefined || name === null || name.trim() === "") {
56
+ throw new Error("Add chatbot account, name can not be null or empty")
57
+ }
58
+ if (accountId === undefined || accountId === null || accountId.trim() === "") {
59
+ throw new Error("Add chatbot account, accountId can not be null or empty")
60
+ }
61
+ if (token === undefined || token === null || token.trim() === "") {
62
+ throw new Error("Add chatbot account, token can not be null or empty")
63
+ }
64
+ if (accountContext === undefined || accountContext === null) {
65
+ throw new Error("Add chatbot account, accountContext can not be null or empty")
66
+ }
67
+ if (notificationDelays === undefined || notificationDelays === null) {
68
+ throw new Error("Add chatbot account, notificationDelays can not be null")
69
+ }
70
+ if (data === undefined || data === null) {
71
+ throw new Error("Add chatbot account, data can not be null")
72
+ }
73
+
74
+ // send create request to the server
75
+ const response = await this.context
76
+ .resolve(RpcService)
77
+ ?.requestBuilder("api/v1/ChatbotAccount")
78
+ .sendPostJson({
79
+ organizationId: this.organization.id,
80
+ accountType: type,
81
+ name: name,
82
+ token: token,
83
+ accountId: accountId,
84
+ context: accountContext,
85
+ data: data
86
+ })
87
+
88
+ // check response status
89
+ if (ResponseUtils.isFail(response)) {
90
+ await ResponseUtils.throwError(`Failed to add chatbot account in organization ${this.organization.id}`, response)
91
+ }
92
+
93
+ await this.update()
94
+ }
95
+
96
+
97
+ async delete(id: string): Promise<void> {
98
+ const account = this._collection?.find(acc => acc.id === id)
99
+
100
+ // check if account is found
101
+ if (!account) {
102
+ throw new Error(`Chatbot account ${id} is not found, organization: ${this.organization.id}`)
103
+ }
104
+
105
+ // send delete request to the server
106
+ const response = await this.context
107
+ .resolve(RpcService)
108
+ ?.requestBuilder("api/v1/ChatbotAccount")
109
+ .searchParam("id", id)
110
+ .sendDelete()
111
+
112
+ // check response status
113
+ if (ResponseUtils.isFail(response)) {
114
+ await ResponseUtils.throwError(
115
+ `Failed to delete chatbot account: ${id}, organization: ${this.organization.id}`,
116
+ response
117
+ )
118
+ }
119
+
120
+ await this.update()
121
+ }
122
+
123
+
124
+ }
@@ -0,0 +1,14 @@
1
+ import { ChatbotAccountType, KeyValueItem } from "../../dto/chatbotAccountResponse"
2
+ import { ChatbotAccount } from "./chatbotAccount"
3
+
4
+
5
+ export abstract class ChatbotAccounts {
6
+
7
+ abstract get collection(): ChatbotAccount[]
8
+
9
+ abstract update(): Promise<void>
10
+
11
+ abstract add(type: ChatbotAccountType, name: string, accountId: string, token: string, accountContext: string, notificationDelays: number[], data: KeyValueItem[]): Promise<void>
12
+
13
+ abstract delete(id: string): Promise<void>
14
+ }
@@ -20,8 +20,8 @@ export class ChatsImpl extends Chats {
20
20
  super()
21
21
  }
22
22
 
23
- async initFrom(organizationId: OrganizationId): Promise<void> {
24
- await this.loadOrganizationChats(organizationId)
23
+ async load(): Promise<void> {
24
+ await this.loadOrganizationChats(this.organization.id)
25
25
  const libraries = (this.context.resolve(LibrariesService) as LibrariesService).libraries.collection
26
26
  for (const library of libraries){
27
27
  await this.loadLibraryChats(library.id)
@@ -22,6 +22,11 @@ export abstract class Chats extends EventDispatcher<ChatsEvent, Chat> {
22
22
  */
23
23
  abstract get collection(): ReadonlyArray<Chat>
24
24
 
25
+ /**
26
+ * Load organization chats
27
+ */
28
+ abstract load(): Promise<void>
29
+
25
30
  /**
26
31
  * Create new chat.
27
32
  */
@@ -25,10 +25,6 @@ export class GroupsImpl extends Groups {
25
25
  return this._groups
26
26
  }
27
27
 
28
- async initialize() {
29
- await this.internalInit()
30
- }
31
-
32
28
  async reload(){
33
29
  this._groups = []
34
30
  await this.internalInit()
@@ -1,6 +1,7 @@
1
1
  import {InstaAccounts} from "./instaAccounts"
2
2
  import {
3
3
  InstaCutAccountDto,
4
+ InstaErrorDto,
4
5
  InstaPostDto,
5
6
  PostStatus,
6
7
  } from "../../dto/instaResponse"
@@ -242,5 +243,25 @@ export class InstaAccountsImpl extends InstaAccounts {
242
243
  await this.update()
243
244
  }
244
245
 
246
+ async errors(): Promise<InstaErrorDto[]> {
247
+ const response = await this.context
248
+ .resolve(RpcService)
249
+ ?.requestBuilder("api/v1/Insta/statistics")
250
+ .searchParam("organizationId", this.organization.id)
251
+ .sendGet()
252
+
253
+ // check response status
254
+ if (ResponseUtils.isFail(response)) {
255
+ await ResponseUtils.throwError(
256
+ `Insta errors list for organization ${this.organization.id} failed`,
257
+ response
258
+ )
259
+ }
260
+
261
+ const errors = (await response!.json() as {errors: InstaErrorDto[]}).errors
262
+
263
+ return errors
264
+ }
265
+
245
266
 
246
267
  }
@@ -1,4 +1,5 @@
1
1
 
2
+ import { InstaErrorDto } from "../../dto/instaResponse"
2
3
  import {InstaAccount} from "./instaAccount"
3
4
  import {InstaPost} from "./instaPost"
4
5
 
@@ -28,4 +29,6 @@ export abstract class InstaAccounts {
28
29
 
29
30
  abstract post(): Promise<void>
30
31
 
32
+ abstract errors(): Promise<InstaErrorDto[]>
33
+
31
34
  }
@@ -44,6 +44,8 @@ import {InstaAccountsImpl} from "../insta/instaAccounts.impl"
44
44
  import {InstaAccounts} from "../insta/instaAccounts"
45
45
  import {MessengerAccountsImpl} from "../messenger/messengerAccounts.impl"
46
46
  import {MessengerAccounts} from "../messenger/messengerAccounts"
47
+ import { ChatbotAccountsImpl } from "../chatbot/chatbotAccounts.impl"
48
+ import { ChatbotAccounts } from "../chatbot/chatbotAccounts"
47
49
 
48
50
  export class OrganizationImpl extends Organization implements Disposable {
49
51
  private _isDisposed: boolean = false
@@ -54,6 +56,7 @@ export class OrganizationImpl extends Organization implements Disposable {
54
56
  private readonly _queryFlows: QueryFlowsImpl
55
57
  private readonly _instaAccounts: InstaAccountsImpl
56
58
  private readonly _messengerAccounts: MessengerAccountsImpl
59
+ private readonly _chatbotAccounts: ChatbotAccountsImpl
57
60
  private readonly _chats: ChatsImpl
58
61
  private readonly _prompts: OrganizationPromptsImpl
59
62
 
@@ -65,6 +68,7 @@ export class OrganizationImpl extends Organization implements Disposable {
65
68
  this._queryFlows = new QueryFlowsImpl(this, this.context)
66
69
  this._instaAccounts = new InstaAccountsImpl(this, this.context)
67
70
  this._messengerAccounts = new MessengerAccountsImpl(this, this.context)
71
+ this._chatbotAccounts = new ChatbotAccountsImpl(this, this.context)
68
72
  this._prompts = new OrganizationPromptsImpl(this, this.context)
69
73
  }
70
74
 
@@ -76,13 +80,13 @@ export class OrganizationImpl extends Organization implements Disposable {
76
80
  this._isAdmin = isAdmin
77
81
 
78
82
  // init workspaces by organization id
79
- const promises = [
80
- this._workspaces.initFrom(content.id),
81
- this._chats.initFrom(content.id),
82
- this._accessGroups.initialize()
83
- ]
83
+ // const promises = [
84
+ // this._workspaces.initFrom(content.id),
85
+ // this._chats.initFrom(content.id),
86
+ // this._accessGroups.initialize()
87
+ // ]
84
88
 
85
- await Promise.all(promises)
89
+ // await Promise.all(promises)
86
90
 
87
91
  return this
88
92
  }
@@ -143,6 +147,10 @@ export class OrganizationImpl extends Organization implements Disposable {
143
147
  return this._messengerAccounts
144
148
  }
145
149
 
150
+ get chatbotAccounts(): ChatbotAccounts {
151
+ return this._chatbotAccounts
152
+ }
153
+
146
154
  get chats(): Chats {
147
155
  return this._chats
148
156
  }
@@ -20,6 +20,7 @@ import { QueryFlows } from "../queryFlows/queryFlows"
20
20
  import { OrganizationPrompts } from "./organizationPrompts"
21
21
  import {InstaAccounts} from "../insta/instaAccounts"
22
22
  import {MessengerAccounts} from "../messenger/messengerAccounts"
23
+ import { ChatbotAccounts } from "../chatbot/chatbotAccounts"
23
24
 
24
25
  /**
25
26
  * Organization event.
@@ -95,6 +96,11 @@ export abstract class Organization extends EventDispatcher<
95
96
  */
96
97
  abstract get messengerAccounts(): MessengerAccounts
97
98
 
99
+ /**
100
+ * Chatbot accounts
101
+ */
102
+ abstract get chatbotAccounts(): ChatbotAccounts
103
+
98
104
  /**
99
105
  * Get organization prompts
100
106
  */
@@ -85,16 +85,13 @@ export class QueryFlowsImpl extends QueryFlows {
85
85
  }
86
86
  }
87
87
 
88
- async create(name: string, workspaceIds: WorkspaceId[], file: UploadFile, table: UploadFile): Promise<FlowId> {
88
+ async create(name: string, workspaceIds: WorkspaceId[], table: UploadFile): Promise<FlowId> {
89
89
  if (name === undefined || name === null || name.trim() === "") {
90
90
  throw new Error("Name is required, must be not empty")
91
91
  }
92
92
  if (workspaceIds === undefined || workspaceIds === null) {
93
93
  throw new Error("WorkspaceIds is required, must be not empty")
94
94
  }
95
- if (file === undefined || file === null) {
96
- throw new Error("Create query flow, file is undefined or null")
97
- }
98
95
  if (table === undefined || table === null) {
99
96
  throw new Error("Create query flow, table is undefined or null")
100
97
  }
@@ -103,7 +100,6 @@ export class QueryFlowsImpl extends QueryFlows {
103
100
  const form = new FormData()
104
101
  form.append("organizationId", this.organization.id)
105
102
  form.append("name", name)
106
- form.append("file", file, file.name)
107
103
  form.append("tableFile", table, table.name)
108
104
  workspaceIds.forEach(item => {
109
105
  form.append("workspaceIds", item)
@@ -118,7 +114,7 @@ export class QueryFlowsImpl extends QueryFlows {
118
114
  // check response status
119
115
  if (ResponseUtils.isFail(response)) {
120
116
 
121
- await ResponseUtils.throwError(`Query flow creation for ${file.name}`, response)
117
+ await ResponseUtils.throwError(`Query flow creation for ${table.name}`, response)
122
118
  }
123
119
 
124
120
  const content = (await response!.json()) as QueryFlowResponse
@@ -24,7 +24,7 @@ export abstract class QueryFlows extends EventDispatcher<
24
24
 
25
25
  abstract getQueryFlows(): Promise<QueryFlow[]>
26
26
 
27
- abstract create(name: string, workspaceIds: WorkspaceId[], file: UploadFile, table: UploadFile ): Promise<FlowId>
27
+ abstract create(name: string, workspaceIds: WorkspaceId[], table: UploadFile ): Promise<FlowId>
28
28
 
29
29
  abstract delete(id: FlowId): Promise<void>
30
30
 
@@ -3,7 +3,6 @@ import { OrganizationImpl } from "../organizations/organization.impl"
3
3
  import { Context } from "../../context"
4
4
  import { Workspace } from "./workspace"
5
5
  import { WorkspaceImpl } from "./workspace.impl"
6
- import { OrganizationId } from "../organizations/organizations"
7
6
  import { RpcService } from "../../services/rpcService"
8
7
  import { OrganizationWorkspaces } from "../../dto/userInfoResponse"
9
8
  import { WorkspaceDto } from "../../dto/workspacesResponse"
@@ -170,18 +169,18 @@ export class WorkspacesImpl extends Workspaces {
170
169
  })
171
170
  }
172
171
 
173
- async initFrom(organizationId: OrganizationId): Promise<void> {
172
+ async load(): Promise<void> {
174
173
  // init workspaces from the server's response
175
174
  const response = await this.context
176
175
  .resolve(RpcService)
177
176
  ?.requestBuilder("api/v1/Organizations")
178
- .searchParam("id", organizationId)
177
+ .searchParam("id", this.organization.id)
179
178
  .sendGet()
180
179
 
181
180
  // check response status
182
181
  if (ResponseUtils.isFail(response)) {
183
182
  const userProfile = this.context.resolve(UserProfileService)?.userProfile as UserProfile
184
- await ResponseUtils.throwError(`Failed to fetch workspaces in organization: ${organizationId}, userId: ${userProfile.id}, email: ${userProfile.email}`, response)
183
+ await ResponseUtils.throwError(`Failed to fetch workspaces in organization: ${this.organization.id}, userId: ${userProfile.id}, email: ${userProfile.email}`, response)
185
184
  }
186
185
 
187
186
  // parse workspaces from the server's response
@@ -54,4 +54,9 @@ export abstract class Workspaces extends EventDispatcher<
54
54
  * Delete workspace.
55
55
  */
56
56
  abstract delete(id: WorkspaceId): Promise<void>
57
+
58
+ /**
59
+ * Load organization workspaces
60
+ */
61
+ abstract load(): Promise<void>
57
62
  }