@wabot-dev/framework 0.1.0-beta.2 → 0.1.0-beta.21
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.
- package/dist/src/ai/claude/ClaudeChatBotAdapter.js +113 -0
- package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +12 -13
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +9 -7
- package/dist/src/channels/cmd/@cmd.js +0 -4
- package/dist/src/channels/cmd/CmdChannel.js +0 -4
- package/dist/src/channels/express/ExpressProvider.js +46 -0
- package/dist/src/channels/http/HttpServerProvider.js +31 -0
- package/dist/src/channels/{socket-io → socket}/@socket.js +0 -4
- package/dist/src/channels/{socket-io → socket}/SocketChannel.js +12 -11
- package/dist/src/channels/socket/SocketServerProvider.js +50 -0
- package/dist/src/channels/telegram/@telegram.js +0 -4
- package/dist/src/channels/telegram/TelegramChannel.js +0 -4
- package/dist/src/channels/wabot/WabotDevConnection.js +57 -0
- package/dist/src/channels/{whatsapp/WhatsAppDevSocketContracts.js → wabot/WabotDevSocketContracts.js} +3 -3
- package/dist/src/channels/whatsapp/@whatsapp.js +0 -4
- package/dist/src/channels/whatsapp/EnvWhatsAppRepository.js +49 -0
- package/dist/src/channels/whatsapp/PgWhatsAppRepository.js +41 -0
- package/dist/src/channels/whatsapp/WhatsApp.js +32 -0
- package/dist/src/channels/whatsapp/WhatsAppChannel.js +33 -32
- package/dist/src/channels/whatsapp/{WhatsAppConnection.js → WhatsAppReceiver.js} +4 -6
- package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +32 -0
- package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +63 -0
- package/dist/src/channels/whatsapp/WhatsAppRepository.js +10 -0
- package/dist/src/channels/whatsapp/WhatsAppSender.js +107 -20
- package/dist/src/channels/whatsapp/WhatsAppSenderByCloudApi.js +118 -0
- package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +56 -0
- package/dist/src/chatbot/ChatBotAdapter.js +1 -5
- package/dist/src/chatbot/metadata/@chatBot.js +0 -5
- package/dist/src/chatbot/metadata/ChatBotMetadataStore.js +0 -5
- package/dist/src/controller/metadata/ControllerMetadataStore.js +0 -2
- package/dist/src/controller/metadata/controller/@chatController.js +0 -2
- package/dist/src/core/{Persistent.js → Entity.js} +24 -9
- package/dist/src/core/IMessageContext.js +0 -2
- package/dist/src/core/Storable.js +8 -0
- package/dist/src/core/chat/Chat.js +2 -2
- package/dist/src/core/chat/ChatItem.js +2 -2
- package/dist/src/core/user/User.js +2 -2
- package/dist/src/env/Env.js +39 -0
- package/dist/src/error/CustomError.js +15 -0
- package/dist/src/index.d.ts +539 -240
- package/dist/src/index.js +65 -34
- package/dist/src/mindset/MindsetOperator.js +1 -3
- package/dist/src/mindset/metadata/MindsetMetadataStore.js +0 -2
- package/dist/src/mindset/metadata/mindsets/@mindset.js +0 -2
- package/dist/src/mindset/metadata/modules/@mindsetModule.js +0 -2
- package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -2
- package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -2
- package/dist/src/pre-made/module/html/HtmlModule.js +70 -0
- package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -2
- package/dist/src/pre-made/repository/chat/pg/PgChatMemory.js +1 -7
- package/dist/src/pre-made/repository/chat/pg/PgChatRepository.js +0 -5
- package/dist/src/pre-made/repository/chat/ram/RamChatRepository.js +1 -1
- package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -5
- package/dist/src/repository/pg/PgCrudRepository.js +13 -3
- package/dist/src/repository/pg/PgRepositoryBase.js +2 -2
- package/dist/src/rest-controller/metadata/@get.js +19 -0
- package/dist/src/rest-controller/metadata/@middleware.js +16 -0
- package/dist/src/rest-controller/metadata/@post.js +19 -0
- package/dist/src/rest-controller/metadata/@restController.js +15 -0
- package/dist/src/rest-controller/metadata/RestControllerMetadataStore.js +50 -0
- package/dist/src/rest-controller/runRestControllers.js +93 -0
- package/dist/src/server/prepareChatContainer.js +6 -6
- package/dist/src/server/runChannel.js +2 -10
- package/dist/src/server/runServer.js +0 -43
- package/dist/src/validation/metadata/@isBoolean.js +17 -0
- package/dist/src/validation/metadata/@isDate.js +17 -0
- package/dist/src/validation/metadata/@isModel.js +18 -0
- package/dist/src/validation/metadata/@isNotEmpty.js +17 -0
- package/dist/src/validation/metadata/@isNumber.js +17 -0
- package/dist/src/validation/metadata/@isOptional.js +17 -0
- package/dist/src/validation/metadata/@isPresent.js +17 -0
- package/dist/src/validation/metadata/@isString.js +17 -0
- package/dist/src/validation/metadata/@max.js +18 -0
- package/dist/src/validation/metadata/@min.js +18 -0
- package/dist/src/validation/metadata/ValidationMetadataStore.js +70 -0
- package/dist/src/validation/validate.js +11 -0
- package/dist/src/validation/validators/validateIsBoolean.js +12 -0
- package/dist/src/validation/validators/validateIsDate.js +16 -0
- package/dist/src/validation/validators/validateIsNotEmpty.js +12 -0
- package/dist/src/validation/validators/validateIsNumber.js +12 -0
- package/dist/src/validation/validators/validateIsOptional.js +5 -0
- package/dist/src/validation/validators/validateIsPresent.js +12 -0
- package/dist/src/validation/validators/validateIsString.js +12 -0
- package/dist/src/validation/validators/validateMax.js +17 -0
- package/dist/src/validation/validators/validateMin.js +17 -0
- package/dist/src/validation/validators/validateModel.js +34 -0
- package/package.json +5 -6
- package/dist/src/channels/whatsapp/WhatsAppDevConnection.js +0 -69
- package/dist/src/channels/whatsapp/WhatsAppProdConnection.js +0 -39
- package/dist/src/controller/express/Express.js +0 -5
- package/dist/src/controller/socket.io/SocketIO.js +0 -5
- package/dist/src/env/WabotEnv.js +0 -21
- package/dist/src/mindset/metadata/params/@isOptional.js +0 -21
- package/dist/src/pre-made/repository/chat/sqlite/SqliteChatMemory.js +0 -23
- package/dist/src/pre-made/repository/chat/sqlite/SqliteChatRepository.js +0 -30
- package/dist/src/pre-made/repository/user/sqlite/SqliteUserRepository.js +0 -23
- package/dist/src/repository/sqlite/SqliteCrudRepository.js +0 -85
- package/dist/src/repository/sqlite/SqlitePersistentMapper.js +0 -17
- /package/dist/src/channels/{socket-io → socket}/SocketChannelConfig.js +0 -0
package/dist/src/index.js
CHANGED
|
@@ -1,27 +1,38 @@
|
|
|
1
|
-
export { OpenaiChatBotAdapter } from './ai/openia/OpenaiChatBotAdapter.js';
|
|
2
1
|
export { DeepSeekChatBotAdapter } from './ai/deepseek/DeepSeekChatBotAdapter.js';
|
|
2
|
+
export { OpenaiChatBotAdapter } from './ai/openia/OpenaiChatBotAdapter.js';
|
|
3
|
+
export { ClaudeChatBotAdapter } from './ai/claude/ClaudeChatBotAdapter.js';
|
|
3
4
|
export { cmd } from './channels/cmd/@cmd.js';
|
|
4
5
|
export { CmdChannel } from './channels/cmd/CmdChannel.js';
|
|
6
|
+
export { ExpressProvider } from './channels/express/ExpressProvider.js';
|
|
7
|
+
export { HttpServerProvider } from './channels/http/HttpServerProvider.js';
|
|
8
|
+
export { socket } from './channels/socket/@socket.js';
|
|
9
|
+
export { SocketChannel } from './channels/socket/SocketChannel.js';
|
|
10
|
+
export { SocketChannelConfig } from './channels/socket/SocketChannelConfig.js';
|
|
11
|
+
export { SocketServerProvider } from './channels/socket/SocketServerProvider.js';
|
|
5
12
|
export { telegram } from './channels/telegram/@telegram.js';
|
|
6
13
|
export { TelegramChannelConfig } from './channels/telegram/TelegramChannelConfig.js';
|
|
7
14
|
export { TelegramChannel } from './channels/telegram/TelegramChannel.js';
|
|
8
15
|
export { whatsapp } from './channels/whatsapp/@whatsapp.js';
|
|
16
|
+
export { EnvWhatsAppRepository } from './channels/whatsapp/EnvWhatsAppRepository.js';
|
|
17
|
+
export { PgWhatsAppRepository } from './channels/whatsapp/PgWhatsAppRepository.js';
|
|
18
|
+
export { WhatsApp } from './channels/whatsapp/WhatsApp.js';
|
|
9
19
|
export { WhatsAppChannel } from './channels/whatsapp/WhatsAppChannel.js';
|
|
10
20
|
export { WhatsappChannelConfig } from './channels/whatsapp/WhatsAppChannelConfig.js';
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
21
|
+
export { WhatsAppReceiver } from './channels/whatsapp/WhatsAppReceiver.js';
|
|
22
|
+
export { WhatsAppReceiverByDevConnection } from './channels/whatsapp/WhatsAppReceiverByDevConnection.js';
|
|
23
|
+
export { WhatsAppReceiverByWebHook } from './channels/whatsapp/WhatsAppReceiverByWebHook.js';
|
|
24
|
+
export { WhatsAppRepository } from './channels/whatsapp/WhatsAppRepository.js';
|
|
15
25
|
export { WhatsAppSender } from './channels/whatsapp/WhatsAppSender.js';
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
18
|
-
export { SocketChannelConfig } from './channels/socket-io/SocketChannelConfig.js';
|
|
26
|
+
export { WhatsAppSenderByCloudApi } from './channels/whatsapp/WhatsAppSenderByCloudApi.js';
|
|
27
|
+
export { WhatsAppSenderByDevConnection } from './channels/whatsapp/WhatsAppSenderByDevConnection.js';
|
|
19
28
|
export { chatBot } from './chatbot/metadata/@chatBot.js';
|
|
20
29
|
export { ChatBotMetadataStore } from './chatbot/metadata/ChatBotMetadataStore.js';
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
30
|
+
export { ChatBot } from './chatbot/ChatBot.js';
|
|
31
|
+
export { ChatBotAdapter } from './chatbot/ChatBotAdapter.js';
|
|
32
|
+
export { ChatResolver } from './controller/channel/ChatResolver.js';
|
|
33
|
+
export { UserResolver } from './controller/channel/UserResolver.js';
|
|
34
|
+
export { chatController } from './controller/metadata/controller/@chatController.js';
|
|
35
|
+
export { ControllerMetadataStore } from './controller/metadata/ControllerMetadataStore.js';
|
|
25
36
|
export { ChatMemory } from './core/chat/repository/IChatMemory.js';
|
|
26
37
|
export { ChatRepository } from './core/chat/repository/IChatRepository.js';
|
|
27
38
|
export { Chat } from './core/chat/Chat.js';
|
|
@@ -29,47 +40,67 @@ export { ChatItem } from './core/chat/ChatItem.js';
|
|
|
29
40
|
export { User } from './core/user/User.js';
|
|
30
41
|
export { UserRepository } from './core/user/IUserRepository.js';
|
|
31
42
|
export { MessageContext } from './core/IMessageContext.js';
|
|
32
|
-
export { Persistent } from './core/
|
|
43
|
+
export { Entity, Persistent } from './core/Entity.js';
|
|
44
|
+
export { Storable } from './core/Storable.js';
|
|
45
|
+
export { Env } from './env/Env.js';
|
|
46
|
+
export { CustomError } from './error/CustomError.js';
|
|
47
|
+
export { container, inject, injectable, singleton } from './injection/index.js';
|
|
48
|
+
export { Logger } from './logger/Logger.js';
|
|
49
|
+
export { mindsetFunction } from './mindset/metadata/functions/@mindsetFunction.js';
|
|
50
|
+
export { MINDSET_FUNCTION_DECORATION_FUNCTION } from './mindset/metadata/functions/decoratorNames.js';
|
|
51
|
+
export { mindset } from './mindset/metadata/mindsets/@mindset.js';
|
|
52
|
+
export { MINDSET_DECORATION_MINDSET } from './mindset/metadata/mindsets/decoratorNames.js';
|
|
33
53
|
export { mindsetModule } from './mindset/metadata/modules/@mindsetModule.js';
|
|
34
54
|
export { MINDSET_MODULE_DECORATION_MODULE } from './mindset/metadata/modules/decoratorNames.js';
|
|
35
|
-
export { isOptional } from './mindset/metadata/params/@isOptional.js';
|
|
36
55
|
export { param } from './mindset/metadata/params/@param.js';
|
|
37
56
|
export { PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM } from './mindset/metadata/params/decoratorNames.js';
|
|
38
|
-
export { Mindset } from './mindset/IMindset.js';
|
|
39
57
|
export { MindsetMetadataStore } from './mindset/metadata/MindsetMetadataStore.js';
|
|
58
|
+
export { Mindset } from './mindset/IMindset.js';
|
|
40
59
|
export { MindsetOperator } from './mindset/MindsetOperator.js';
|
|
41
|
-
export { ChatBot } from './chatbot/ChatBot.js';
|
|
42
|
-
export { ChatBotAdapter } from './chatbot/ChatBotAdapter.js';
|
|
43
|
-
export { ChatResolver } from './controller/channel/ChatResolver.js';
|
|
44
|
-
export { UserResolver } from './controller/channel/UserResolver.js';
|
|
45
|
-
export { chatController } from './controller/metadata/controller/@chatController.js';
|
|
46
|
-
export { ControllerMetadataStore } from './controller/metadata/ControllerMetadataStore.js';
|
|
47
|
-
export { ExpressApp } from './controller/express/Express.js';
|
|
48
|
-
export { SocketIoApp } from './controller/socket.io/SocketIO.js';
|
|
49
|
-
export { container, inject, injectable, singleton } from './injection/index.js';
|
|
50
|
-
export { prepareChatContainer } from './server/prepareChatContainer.js';
|
|
51
|
-
export { runChannel } from './server/runChannel.js';
|
|
52
|
-
export { runServer } from './server/runServer.js';
|
|
53
60
|
export { SendOneTimePasswordRequest } from './pre-made/module/authentication/requests/SendOneTimePasswordRequest.js';
|
|
54
61
|
export { ValidateOneTimePasswordRequest } from './pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js';
|
|
55
62
|
export { AuthenticationModule } from './pre-made/module/authentication/AuthenticationModule.js';
|
|
56
63
|
export { RegisterUserWithEmailRequest } from './pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js';
|
|
57
64
|
export { RegisterUserModule } from './pre-made/module/register-user/RegisterUserModule.js';
|
|
65
|
+
export { HtmlModule } from './pre-made/module/html/HtmlModule.js';
|
|
58
66
|
export { EmailService } from './pre-made/service/EmailService.js';
|
|
59
67
|
export { OtpService } from './pre-made/service/OtpService.js';
|
|
60
68
|
export { PgUserRepository } from './pre-made/repository/user/pg/PgUserRepository.js';
|
|
61
69
|
export { RamUserRepository } from './pre-made/repository/user/ram/RamUserRepository.js';
|
|
62
|
-
export { SqliteUserRepository } from './pre-made/repository/user/sqlite/SqliteUserRepository.js';
|
|
63
70
|
export { PgChatRepository } from './pre-made/repository/chat/pg/PgChatRepository.js';
|
|
64
71
|
export { PgChatMemory } from './pre-made/repository/chat/pg/PgChatMemory.js';
|
|
65
|
-
export { SqliteChatMemory } from './pre-made/repository/chat/sqlite/SqliteChatMemory.js';
|
|
66
|
-
export { SqliteChatRepository } from './pre-made/repository/chat/sqlite/SqliteChatRepository.js';
|
|
67
72
|
export { RamChatMemory } from './pre-made/repository/chat/ram/RamChatMemory.js';
|
|
68
73
|
export { RamChatRepository } from './pre-made/repository/chat/ram/RamChatRepository.js';
|
|
69
74
|
export { PgCrudRepository } from './repository/pg/PgCrudRepository.js';
|
|
70
75
|
export { PgRepositoryBase } from './repository/pg/PgRepositoryBase.js';
|
|
71
|
-
export {
|
|
72
|
-
export {
|
|
73
|
-
export {
|
|
74
|
-
export {
|
|
76
|
+
export { get } from './rest-controller/metadata/@get.js';
|
|
77
|
+
export { middleware } from './rest-controller/metadata/@middleware.js';
|
|
78
|
+
export { post } from './rest-controller/metadata/@post.js';
|
|
79
|
+
export { restController } from './rest-controller/metadata/@restController.js';
|
|
80
|
+
export { RestControllerMetadataStore } from './rest-controller/metadata/RestControllerMetadataStore.js';
|
|
81
|
+
export { runRestControllers } from './rest-controller/runRestControllers.js';
|
|
82
|
+
export { prepareChatContainer } from './server/prepareChatContainer.js';
|
|
83
|
+
export { runChannel } from './server/runChannel.js';
|
|
84
|
+
export { runServer } from './server/runServer.js';
|
|
85
|
+
export { isBoolean } from './validation/metadata/@isBoolean.js';
|
|
86
|
+
export { isDate } from './validation/metadata/@isDate.js';
|
|
87
|
+
export { isModel } from './validation/metadata/@isModel.js';
|
|
88
|
+
export { isNotEmpty } from './validation/metadata/@isNotEmpty.js';
|
|
89
|
+
export { isNumber } from './validation/metadata/@isNumber.js';
|
|
90
|
+
export { isOptional } from './validation/metadata/@isOptional.js';
|
|
91
|
+
export { isPresent } from './validation/metadata/@isPresent.js';
|
|
92
|
+
export { isString } from './validation/metadata/@isString.js';
|
|
93
|
+
export { max } from './validation/metadata/@max.js';
|
|
94
|
+
export { min } from './validation/metadata/@min.js';
|
|
95
|
+
export { ValidationMetadataStore } from './validation/metadata/ValidationMetadataStore.js';
|
|
96
|
+
export { validateIsBoolean } from './validation/validators/validateIsBoolean.js';
|
|
97
|
+
export { validateIsDate } from './validation/validators/validateIsDate.js';
|
|
98
|
+
export { validateIsNotEmpty } from './validation/validators/validateIsNotEmpty.js';
|
|
99
|
+
export { validateIsNumber } from './validation/validators/validateIsNumber.js';
|
|
100
|
+
export { validateIsString } from './validation/validators/validateIsString.js';
|
|
101
|
+
export { validateMax } from './validation/validators/validateMax.js';
|
|
102
|
+
export { validateMin } from './validation/validators/validateMin.js';
|
|
103
|
+
export { validateIsPresent } from './validation/validators/validateIsPresent.js';
|
|
104
|
+
export { validateModel } from './validation/validators/validateModel.js';
|
|
105
|
+
export { validate } from './validation/validate.js';
|
|
75
106
|
export { Container } from './injection/Container.js';
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import { injectable } from '../injection/index.js';
|
|
3
3
|
import { Mindset } from './IMindset.js';
|
|
4
|
-
import '../core/chat/repository/IChatRepository.js';
|
|
5
|
-
import '../core/user/IUserRepository.js';
|
|
6
4
|
import { MindsetMetadataStore } from './metadata/MindsetMetadataStore.js';
|
|
7
5
|
import { Container } from '../injection/Container.js';
|
|
8
6
|
|
|
@@ -62,7 +60,7 @@ let MindsetOperator = class MindsetOperator {
|
|
|
62
60
|
...prev,
|
|
63
61
|
[param.name]: this.toolParam(param),
|
|
64
62
|
}), {}),
|
|
65
|
-
required: fn.params.filter((param) => !param.config.optional).map((param) => param.name)
|
|
63
|
+
required: fn.params.filter((param) => !param.config.optional).map((param) => param.name),
|
|
66
64
|
},
|
|
67
65
|
};
|
|
68
66
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
2
|
import { singleton } from '../../injection/index.js';
|
|
3
|
-
import '../../core/chat/repository/IChatRepository.js';
|
|
4
|
-
import '../../core/user/IUserRepository.js';
|
|
5
3
|
import { MINDSET_FUNCTION_DECORATION_FUNCTION } from './functions/decoratorNames.js';
|
|
6
4
|
import { MINDSET_DECORATION_MINDSET } from './mindsets/decoratorNames.js';
|
|
7
5
|
import { MINDSET_MODULE_DECORATION_MODULE } from './modules/decoratorNames.js';
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import '../../../core/chat/repository/IChatRepository.js';
|
|
3
|
-
import '../../../core/user/IUserRepository.js';
|
|
4
2
|
import { container, injectable } from '../../../injection/index.js';
|
|
5
3
|
import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
|
|
6
4
|
import { MINDSET_DECORATION_MINDSET } from './decoratorNames.js';
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { container, injectable } from '../../../injection/index.js';
|
|
3
|
-
import '../../../core/chat/repository/IChatRepository.js';
|
|
4
|
-
import '../../../core/user/IUserRepository.js';
|
|
5
3
|
import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
|
|
6
4
|
import { MINDSET_MODULE_DECORATION_MODULE } from './decoratorNames.js';
|
|
7
5
|
|
|
@@ -2,8 +2,6 @@ import { __decorate, __metadata } from 'tslib';
|
|
|
2
2
|
import 'reflect-metadata';
|
|
3
3
|
import '../../../../injection/index.js';
|
|
4
4
|
import '../../../../mindset/metadata/MindsetMetadataStore.js';
|
|
5
|
-
import '../../../../core/chat/repository/IChatRepository.js';
|
|
6
|
-
import '../../../../core/user/IUserRepository.js';
|
|
7
5
|
import { param } from '../../../../mindset/metadata/params/@param.js';
|
|
8
6
|
import '../../../../mindset/MindsetOperator.js';
|
|
9
7
|
|
|
@@ -2,8 +2,6 @@ import { __decorate, __metadata } from 'tslib';
|
|
|
2
2
|
import 'reflect-metadata';
|
|
3
3
|
import '../../../../injection/index.js';
|
|
4
4
|
import '../../../../mindset/metadata/MindsetMetadataStore.js';
|
|
5
|
-
import '../../../../core/chat/repository/IChatRepository.js';
|
|
6
|
-
import '../../../../core/user/IUserRepository.js';
|
|
7
5
|
import { param } from '../../../../mindset/metadata/params/@param.js';
|
|
8
6
|
import '../../../../mindset/MindsetOperator.js';
|
|
9
7
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { mindsetFunction } from '../../../mindset/metadata/functions/@mindsetFunction.js';
|
|
3
|
+
import 'reflect-metadata';
|
|
4
|
+
import '../../../injection/index.js';
|
|
5
|
+
import '../../../mindset/metadata/MindsetMetadataStore.js';
|
|
6
|
+
import { mindsetModule } from '../../../mindset/metadata/modules/@mindsetModule.js';
|
|
7
|
+
import { param } from '../../../mindset/metadata/params/@param.js';
|
|
8
|
+
import '../../../mindset/MindsetOperator.js';
|
|
9
|
+
import { convert } from 'html-to-text';
|
|
10
|
+
|
|
11
|
+
function toPascalCaseFunctionName(title) {
|
|
12
|
+
const cleaned = title.replace(/[^a-zA-Z0-9]+/g, ' ');
|
|
13
|
+
const words = cleaned
|
|
14
|
+
.trim()
|
|
15
|
+
.split(/\s+/)
|
|
16
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase());
|
|
17
|
+
return words.join('');
|
|
18
|
+
}
|
|
19
|
+
async function fetchRawHtml(url) {
|
|
20
|
+
try {
|
|
21
|
+
const response = await fetch(url);
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
24
|
+
}
|
|
25
|
+
const html = await response.text();
|
|
26
|
+
return html;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw new Error(`Failed to fetch HTML from ${url}: ${error.message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
class KeywordsReq {
|
|
33
|
+
keywords = '';
|
|
34
|
+
}
|
|
35
|
+
__decorate([
|
|
36
|
+
param({
|
|
37
|
+
description: 'Keywords separated by space',
|
|
38
|
+
}),
|
|
39
|
+
__metadata("design:type", String)
|
|
40
|
+
], KeywordsReq.prototype, "keywords", void 0);
|
|
41
|
+
function HtmlModule(options) {
|
|
42
|
+
var _a;
|
|
43
|
+
const standaricedTitle = toPascalCaseFunctionName(options.title);
|
|
44
|
+
let documentText = null;
|
|
45
|
+
let HtmlModuleIntern = class HtmlModuleIntern {
|
|
46
|
+
async [_a = `searchInTheDocument${standaricedTitle}`](req) {
|
|
47
|
+
if (!documentText) {
|
|
48
|
+
const rawHtml = await fetchRawHtml(options.url);
|
|
49
|
+
documentText = convert(rawHtml);
|
|
50
|
+
}
|
|
51
|
+
return documentText;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
__decorate([
|
|
55
|
+
mindsetFunction({
|
|
56
|
+
description: `Search information using keywords in the document "${options.title}". Priorize this info.`,
|
|
57
|
+
}),
|
|
58
|
+
__metadata("design:type", Function),
|
|
59
|
+
__metadata("design:paramtypes", [KeywordsReq]),
|
|
60
|
+
__metadata("design:returntype", Promise)
|
|
61
|
+
], HtmlModuleIntern.prototype, _a, null);
|
|
62
|
+
HtmlModuleIntern = __decorate([
|
|
63
|
+
mindsetModule({
|
|
64
|
+
description: `Search information using keywords in the document ${options.title}`,
|
|
65
|
+
})
|
|
66
|
+
], HtmlModuleIntern);
|
|
67
|
+
return HtmlModuleIntern;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { HtmlModule };
|
|
@@ -2,8 +2,6 @@ import { __decorate, __metadata } from 'tslib';
|
|
|
2
2
|
import 'reflect-metadata';
|
|
3
3
|
import '../../../../injection/index.js';
|
|
4
4
|
import '../../../../mindset/metadata/MindsetMetadataStore.js';
|
|
5
|
-
import '../../../../core/chat/repository/IChatRepository.js';
|
|
6
|
-
import '../../../../core/user/IUserRepository.js';
|
|
7
5
|
import { param } from '../../../../mindset/metadata/params/@param.js';
|
|
8
6
|
import '../../../../mindset/MindsetOperator.js';
|
|
9
7
|
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import { ChatItem } from '../../../../core/chat/ChatItem.js';
|
|
2
1
|
import '../../../../core/chat/repository/IChatRepository.js';
|
|
2
|
+
import { ChatItem } from '../../../../core/chat/ChatItem.js';
|
|
3
3
|
import '../../../../core/user/IUserRepository.js';
|
|
4
4
|
import { PgCrudRepository } from '../../../../repository/pg/PgCrudRepository.js';
|
|
5
|
-
import 'fs';
|
|
6
|
-
import 'path';
|
|
7
|
-
import 'sqlite';
|
|
8
|
-
import 'sqlite3';
|
|
9
|
-
import 'uuid';
|
|
10
|
-
import 'pg';
|
|
11
5
|
|
|
12
6
|
class PgChatMemory extends PgCrudRepository {
|
|
13
7
|
chatId;
|
|
@@ -6,11 +6,6 @@ import { singleton } from '../../../../injection/index.js';
|
|
|
6
6
|
import { Pool } from 'pg';
|
|
7
7
|
import { PgChatMemory } from './PgChatMemory.js';
|
|
8
8
|
import { PgCrudRepository } from '../../../../repository/pg/PgCrudRepository.js';
|
|
9
|
-
import 'fs';
|
|
10
|
-
import 'path';
|
|
11
|
-
import 'sqlite';
|
|
12
|
-
import 'sqlite3';
|
|
13
|
-
import 'uuid';
|
|
14
9
|
|
|
15
10
|
let PgChatRepository = class PgChatRepository extends PgCrudRepository {
|
|
16
11
|
constructor(pool) {
|
|
@@ -4,11 +4,6 @@ import { User } from '../../../../core/user/User.js';
|
|
|
4
4
|
import '../../../../core/user/IUserRepository.js';
|
|
5
5
|
import { singleton } from '../../../../injection/index.js';
|
|
6
6
|
import { PgCrudRepository } from '../../../../repository/pg/PgCrudRepository.js';
|
|
7
|
-
import 'fs';
|
|
8
|
-
import 'path';
|
|
9
|
-
import 'sqlite';
|
|
10
|
-
import 'sqlite3';
|
|
11
|
-
import 'uuid';
|
|
12
7
|
import { Pool } from 'pg';
|
|
13
8
|
|
|
14
9
|
let PgUserRepository = class PgUserRepository extends PgCrudRepository {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import 'pg';
|
|
2
1
|
import * as shortUUID from 'short-uuid';
|
|
3
2
|
import { PgRepositoryBase } from './PgRepositoryBase.js';
|
|
3
|
+
import { CustomError } from '../../error/CustomError.js';
|
|
4
4
|
|
|
5
5
|
class PgCrudRepository extends PgRepositoryBase {
|
|
6
6
|
config;
|
|
@@ -18,6 +18,16 @@ class PgCrudRepository extends PgRepositoryBase {
|
|
|
18
18
|
const items = await this.query(sql, [id]);
|
|
19
19
|
return items.at(0) ?? null;
|
|
20
20
|
}
|
|
21
|
+
async findOrThrow(id) {
|
|
22
|
+
const item = await this.find(id);
|
|
23
|
+
if (!item) {
|
|
24
|
+
throw new CustomError({
|
|
25
|
+
message: `Not found ${this.config.constructor.name} with id = '${id}'}`,
|
|
26
|
+
httpCode: 404,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return item;
|
|
30
|
+
}
|
|
21
31
|
async findAll() {
|
|
22
32
|
const sql = `
|
|
23
33
|
SELECT ${this.columns}
|
|
@@ -47,10 +57,10 @@ class PgCrudRepository extends PgRepositoryBase {
|
|
|
47
57
|
SET ${this.updates}
|
|
48
58
|
WHERE id = $${this.columnsList.length + 1}
|
|
49
59
|
`;
|
|
50
|
-
await this.exec(sql, [...this.values(item), item.
|
|
60
|
+
await this.exec(sql, [...this.values(item), item.id]);
|
|
51
61
|
}
|
|
52
62
|
async discard(item) {
|
|
53
|
-
const _item = await this.find(item.
|
|
63
|
+
const _item = await this.find(item.id);
|
|
54
64
|
if (!_item) {
|
|
55
65
|
throw new Error('Not found');
|
|
56
66
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { RestControllerMetadataStore } from './RestControllerMetadataStore.js';
|
|
3
|
+
|
|
4
|
+
function get(config) {
|
|
5
|
+
return function (target, propertyKey) {
|
|
6
|
+
const functionName = propertyKey.toString();
|
|
7
|
+
const paramsTypes = Reflect.getMetadata('design:paramtypes', target, functionName);
|
|
8
|
+
const store = container.resolve(RestControllerMetadataStore);
|
|
9
|
+
store.saveEndPointMetadata({
|
|
10
|
+
controllerConstructor: target.constructor,
|
|
11
|
+
functionName,
|
|
12
|
+
method: 'get',
|
|
13
|
+
path: typeof config === 'string' ? config : config?.path,
|
|
14
|
+
paramsTypes,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { get };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { RestControllerMetadataStore } from './RestControllerMetadataStore.js';
|
|
3
|
+
|
|
4
|
+
function middleware(middlewareConstructor) {
|
|
5
|
+
return function (target, propertyKey) {
|
|
6
|
+
const functionName = propertyKey.toString();
|
|
7
|
+
const store = container.resolve(RestControllerMetadataStore);
|
|
8
|
+
store.saveMiddlewareMetadata({
|
|
9
|
+
controllerConstructor: target.constructor,
|
|
10
|
+
functionName,
|
|
11
|
+
middlewareConstructor: middlewareConstructor,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { middleware };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { RestControllerMetadataStore } from './RestControllerMetadataStore.js';
|
|
3
|
+
|
|
4
|
+
function post(config) {
|
|
5
|
+
return function (target, propertyKey) {
|
|
6
|
+
const functionName = propertyKey.toString();
|
|
7
|
+
const paramsTypes = Reflect.getMetadata('design:paramtypes', target, functionName);
|
|
8
|
+
const store = container.resolve(RestControllerMetadataStore);
|
|
9
|
+
store.saveEndPointMetadata({
|
|
10
|
+
controllerConstructor: target.constructor,
|
|
11
|
+
functionName,
|
|
12
|
+
method: 'post',
|
|
13
|
+
path: typeof config === 'string' ? config : config?.path,
|
|
14
|
+
paramsTypes,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { post };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { container, injectable } from '../../injection/index.js';
|
|
2
|
+
import { RestControllerMetadataStore } from './RestControllerMetadataStore.js';
|
|
3
|
+
|
|
4
|
+
function restController(config) {
|
|
5
|
+
return function (target) {
|
|
6
|
+
const metaDataStore = container.resolve(RestControllerMetadataStore);
|
|
7
|
+
metaDataStore.saveControllerMetadata({
|
|
8
|
+
controllerConstructor: target,
|
|
9
|
+
path: typeof config === 'string' ? config : config.path,
|
|
10
|
+
});
|
|
11
|
+
injectable()(target);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { restController };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { singleton } from 'tsyringe';
|
|
3
|
+
|
|
4
|
+
let RestControllerMetadataStore = class RestControllerMetadataStore {
|
|
5
|
+
endPoints = new Map();
|
|
6
|
+
middlewares = new Map();
|
|
7
|
+
restControllers = new Map();
|
|
8
|
+
saveControllerMetadata(controllerMetadata) {
|
|
9
|
+
this.restControllers.set(controllerMetadata.controllerConstructor, controllerMetadata);
|
|
10
|
+
}
|
|
11
|
+
saveEndPointMetadata(endPointMetadata) {
|
|
12
|
+
let controllerEndPoints = this.endPoints.get(endPointMetadata.controllerConstructor);
|
|
13
|
+
if (!controllerEndPoints) {
|
|
14
|
+
this.endPoints.set(endPointMetadata.controllerConstructor, (controllerEndPoints = new Map()));
|
|
15
|
+
}
|
|
16
|
+
controllerEndPoints.set(endPointMetadata.functionName, endPointMetadata);
|
|
17
|
+
}
|
|
18
|
+
saveMiddlewareMetadata(middlewareMetadata) {
|
|
19
|
+
let controllerMiddlewares = this.middlewares.get(middlewareMetadata.controllerConstructor);
|
|
20
|
+
if (!controllerMiddlewares) {
|
|
21
|
+
this.middlewares.set(middlewareMetadata.controllerConstructor, (controllerMiddlewares = new Map()));
|
|
22
|
+
}
|
|
23
|
+
let methodMiddlewares = controllerMiddlewares.get(middlewareMetadata.functionName);
|
|
24
|
+
if (!methodMiddlewares) {
|
|
25
|
+
controllerMiddlewares.set(middlewareMetadata.functionName, (methodMiddlewares = []));
|
|
26
|
+
}
|
|
27
|
+
methodMiddlewares.unshift(middlewareMetadata);
|
|
28
|
+
}
|
|
29
|
+
getControllerEndPointsInfo(controllerConstructor) {
|
|
30
|
+
const controller = this.restControllers.get(controllerConstructor);
|
|
31
|
+
if (!controller) {
|
|
32
|
+
throw new Error(`${controllerConstructor.name} should be decorated with @restController`);
|
|
33
|
+
}
|
|
34
|
+
const endPoints = this.endPoints.get(controllerConstructor);
|
|
35
|
+
if (!endPoints?.size) {
|
|
36
|
+
// TODO: Warning
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
return [...endPoints.values()].map((endPoint) => ({
|
|
40
|
+
...endPoint,
|
|
41
|
+
middlewares: this.middlewares.get(endPoint.controllerConstructor)?.get(endPoint.functionName) ?? [],
|
|
42
|
+
controller: this.restControllers.get(endPoint.controllerConstructor),
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
RestControllerMetadataStore = __decorate([
|
|
47
|
+
singleton()
|
|
48
|
+
], RestControllerMetadataStore);
|
|
49
|
+
|
|
50
|
+
export { RestControllerMetadataStore };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import '../controller/channel/ChatResolver.js';
|
|
2
|
+
import '../controller/channel/UserResolver.js';
|
|
3
|
+
import { container } from '../injection/index.js';
|
|
4
|
+
import '../controller/metadata/ControllerMetadataStore.js';
|
|
5
|
+
import '../channels/cmd/CmdChannel.js';
|
|
6
|
+
import { ExpressProvider } from '../channels/express/ExpressProvider.js';
|
|
7
|
+
import '../channels/http/HttpServerProvider.js';
|
|
8
|
+
import '../channels/socket/SocketChannel.js';
|
|
9
|
+
import '../channels/socket/SocketChannelConfig.js';
|
|
10
|
+
import '../channels/socket/SocketServerProvider.js';
|
|
11
|
+
import '../channels/telegram/TelegramChannel.js';
|
|
12
|
+
import '../channels/whatsapp/WhatsAppChannel.js';
|
|
13
|
+
import '../channels/whatsapp/EnvWhatsAppRepository.js';
|
|
14
|
+
import '../channels/whatsapp/PgWhatsAppRepository.js';
|
|
15
|
+
import '../core/chat/repository/IChatRepository.js';
|
|
16
|
+
import '../core/user/IUserRepository.js';
|
|
17
|
+
import '../channels/whatsapp/WhatsAppReceiverByDevConnection.js';
|
|
18
|
+
import '../channels/whatsapp/WhatsAppReceiverByWebHook.js';
|
|
19
|
+
import '../channels/whatsapp/WhatsAppSenderByCloudApi.js';
|
|
20
|
+
import '../channels/whatsapp/WhatsAppSenderByDevConnection.js';
|
|
21
|
+
import { Logger } from '../logger/Logger.js';
|
|
22
|
+
import '../validation/metadata/ValidationMetadataStore.js';
|
|
23
|
+
import { validate } from '../validation/validate.js';
|
|
24
|
+
import path from 'path';
|
|
25
|
+
import { RestControllerMetadataStore } from './metadata/RestControllerMetadataStore.js';
|
|
26
|
+
import { CustomError } from '../error/CustomError.js';
|
|
27
|
+
|
|
28
|
+
function buildRequest(req) {
|
|
29
|
+
return Object.assign({}, req.body, req.query, req.params);
|
|
30
|
+
}
|
|
31
|
+
function runRestControllers(controllers) {
|
|
32
|
+
const logger = new Logger('wabot:rest');
|
|
33
|
+
const metadataStore = container.resolve(RestControllerMetadataStore);
|
|
34
|
+
const expressProvider = container.resolve(ExpressProvider);
|
|
35
|
+
const expressApp = expressProvider.getExpress();
|
|
36
|
+
controllers.forEach((controller) => {
|
|
37
|
+
const endPoints = metadataStore.getControllerEndPointsInfo(controller);
|
|
38
|
+
endPoints.forEach((endPoint) => {
|
|
39
|
+
const method = endPoint.method;
|
|
40
|
+
const route = path.join(endPoint.controller.path, endPoint.path ?? '');
|
|
41
|
+
logger.info(`config ${endPoint.method.toUpperCase()} ${route}`);
|
|
42
|
+
expressApp[method](route, async (req, res) => {
|
|
43
|
+
const requestContainer = container.createChildContainer();
|
|
44
|
+
try {
|
|
45
|
+
const middlewares = endPoint.middlewares.map((x) => requestContainer.resolve(x.middlewareConstructor));
|
|
46
|
+
for (const middleware of middlewares) {
|
|
47
|
+
await middleware.handle(req, res, requestContainer);
|
|
48
|
+
}
|
|
49
|
+
const controllerInstance = requestContainer.resolve(endPoint.controllerConstructor);
|
|
50
|
+
const endPointArgs = [];
|
|
51
|
+
let defaultArgFound = false;
|
|
52
|
+
for (let paramIndex = 0; paramIndex < endPoint.paramsTypes.length; paramIndex++) {
|
|
53
|
+
const paramType = endPoint.paramsTypes[paramIndex];
|
|
54
|
+
if (defaultArgFound) {
|
|
55
|
+
throw new Error(`Cant determine de parameter ${paramIndex} value`);
|
|
56
|
+
}
|
|
57
|
+
defaultArgFound = true;
|
|
58
|
+
if (typeof paramType === 'function') {
|
|
59
|
+
const { value, error } = validate(buildRequest(req), paramType);
|
|
60
|
+
if (error) {
|
|
61
|
+
throw new CustomError({ httpCode: 400, message: error.description, info: error });
|
|
62
|
+
}
|
|
63
|
+
endPointArgs.push(value);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const response = await controllerInstance[endPoint.functionName].apply(controllerInstance, endPointArgs);
|
|
67
|
+
res.status(200).json(response);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
if (err instanceof Error) {
|
|
71
|
+
const keys = Object.keys(err).filter((key) => !['message', 'stack'].includes(key));
|
|
72
|
+
const { httpCode, ...info } = keys.reduce((acc, key) => {
|
|
73
|
+
acc[key] = err[key];
|
|
74
|
+
return acc;
|
|
75
|
+
}, {});
|
|
76
|
+
res
|
|
77
|
+
.status(httpCode ?? 500)
|
|
78
|
+
.json({ error: { message: err.message, stack: err.stack, ...info } });
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
res.status(500).json({ error: { message: 'Unknown error' } });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
requestContainer.dispose();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
expressProvider.listen();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { runRestControllers };
|