@wabot-dev/framework 0.1.0-beta.29 → 0.1.0-beta.30
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/addon/async/pg/PgJobRepository.js +26 -0
- package/dist/src/addon/chat-bot/claude/ClaudeChatBotAdapter.js +107 -0
- package/dist/src/addon/chat-bot/deepseek/DeepSeekChatBotAdapter.js +103 -0
- package/dist/src/{ai → addon/chat-bot}/openia/OpenaiChatAdapter.js +3 -3
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +5 -4
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +5 -5
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +1 -1
- package/dist/src/addon/chat-controller/cmd/@cmd.js +22 -0
- package/dist/src/{channels → addon/chat-controller}/cmd/CmdChannel.js +5 -27
- package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +8 -4
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +6 -24
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
- package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +8 -4
- package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +5 -23
- package/dist/src/{channels → addon/chat-controller}/whatsapp/@whatsapp.js +8 -4
- package/dist/src/{channels → addon/chat-controller}/whatsapp/EnvWhatsAppRepository.js +2 -2
- package/dist/src/{channels → addon/chat-controller}/whatsapp/PgWhatsAppRepository.js +1 -1
- package/dist/src/{channels/wabot → addon/chat-controller/whatsapp}/WabotDevConnection.js +2 -2
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +1 -3
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiver.js +13 -10
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiverByDevConnection.js +3 -9
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiverByWebHook.js +2 -9
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +12 -7
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSenderByCloudApi.js +10 -7
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSenderByDevConnection.js +12 -9
- package/dist/src/{pre-made/module → addon/mindset}/html/HtmlModule.js +6 -6
- package/dist/src/{repository → addon/repository}/pg/PgCrudRepository.js +1 -1
- package/dist/src/addon/rest-controller/jwt/@jwtGuard.js +17 -0
- package/dist/src/{jwt → addon/rest-controller/jwt}/Jwt.js +7 -2
- package/dist/src/{jwt → addon/rest-controller/jwt}/JwtAccessAndRefreshTokenDto.js +3 -3
- package/dist/src/{jwt → addon/rest-controller/jwt}/JwtConfig.js +2 -2
- package/dist/src/{jwt → addon/rest-controller/jwt}/JwtGuardMiddleware.js +8 -3
- package/dist/src/addon/rest-controller/jwt/JwtRefreshToken.js +9 -0
- package/dist/src/{jwt → addon/rest-controller/jwt}/JwtRefreshTokenRepository.js +2 -2
- package/dist/src/{jwt → addon/rest-controller/jwt}/JwtSigner.js +2 -2
- package/dist/src/{jwt → addon/rest-controller/jwt}/JwtTokenDto.js +5 -5
- package/dist/src/{validation/metadata → addon/validation/is-boolean}/@isBoolean.js +3 -3
- package/dist/src/{validation/metadata → addon/validation/is-date}/@isDate.js +3 -3
- package/dist/src/{validation/metadata → addon/validation/is-not-empty}/@isNotEmpty.js +3 -3
- package/dist/src/{validation/metadata → addon/validation/is-number}/@isNumber.js +3 -3
- package/dist/src/{validation/metadata → addon/validation/is-present}/@isPresent.js +3 -3
- package/dist/src/{validation/metadata → addon/validation/is-string}/@isString.js +3 -3
- package/dist/src/{validation/metadata → addon/validation/max}/@max.js +3 -3
- package/dist/src/{validation/metadata → addon/validation/min}/@min.js +3 -3
- package/dist/src/core/{Entity.js → entity/Entity.js} +1 -1
- package/dist/src/{mapper → core/mapper}/Mapper.js +1 -3
- package/dist/src/{async → feature/async}/@command.js +1 -1
- package/dist/src/{async → feature/async}/@commandHandler.js +1 -1
- package/dist/src/{async → feature/async}/Async.js +1 -1
- package/dist/src/feature/async/Command.js +9 -0
- package/dist/src/{async → feature/async}/CommandMetadataStore.js +1 -1
- package/dist/src/{async → feature/async}/Job.js +2 -4
- package/dist/src/feature/async/JobRepository.js +31 -0
- package/dist/src/{async → feature/async}/JobRunner.js +1 -1
- package/dist/src/{async → feature/async}/JobsEventsHub.js +1 -1
- package/dist/src/{async → feature/async}/runCommandHandlers.js +1 -1
- package/dist/src/{core/chat → feature/chat-bot}/Chat.js +1 -1
- package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
- package/dist/src/feature/chat-bot/ChatBot.js +50 -0
- package/dist/src/feature/chat-bot/ChatItem.js +24 -0
- package/dist/src/feature/chat-bot/ChatMemory.js +10 -0
- package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js} +2 -8
- package/dist/src/feature/chat-bot/IChatItem.js +3 -0
- package/dist/src/{chatbot → feature/chat-bot}/metadata/@chatBot.js +1 -1
- package/dist/src/{chatbot → feature/chat-bot}/metadata/ChatBotMetadataStore.js +1 -1
- package/dist/src/{controller/channel → feature/chat-controller}/ChatResolver.js +5 -4
- package/dist/src/{controller → feature/chat-controller}/metadata/ControllerMetadataStore.js +1 -1
- package/dist/src/{controller → feature/chat-controller}/metadata/controller/@chatController.js +1 -1
- package/dist/src/feature/chat-controller/runChatControllers.js +69 -0
- package/dist/src/{channels → feature}/express/ExpressProvider.js +1 -1
- package/dist/src/{channels → feature}/http/HttpServerProvider.js +1 -1
- package/dist/src/{mindset → feature/mindset}/MindsetOperator.js +2 -61
- package/dist/src/{mindset → feature/mindset}/metadata/MindsetMetadataStore.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/functions/@mindsetFunction.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/mindsets/@mindset.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/modules/@mindsetModule.js +1 -2
- package/dist/src/{mindset → feature/mindset}/metadata/params/@param.js +1 -1
- package/dist/src/{auth → feature/rest-controller/auth}/Auth.js +2 -2
- package/dist/src/{rest-controller → feature/rest-controller}/metadata/@get.js +1 -1
- package/dist/src/{rest-controller → feature/rest-controller}/metadata/@middleware.js +1 -1
- package/dist/src/{rest-controller → feature/rest-controller}/metadata/@post.js +1 -1
- package/dist/src/{rest-controller → feature/rest-controller}/metadata/@restController.js +1 -1
- package/dist/src/{rest-controller → feature/rest-controller}/metadata/RestControllerMetadataStore.js +1 -1
- package/dist/src/{rest-controller → feature/rest-controller}/runRestControllers.js +6 -24
- package/dist/src/{channels → feature}/socket/SocketServerProvider.js +1 -1
- package/dist/src/index.d.ts +550 -724
- package/dist/src/index.js +118 -133
- package/package.json +1 -1
- package/dist/src/ai/claude/ClaudeChatBotAdapter.js +0 -112
- package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -107
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -88
- package/dist/src/async/Command.js +0 -11
- package/dist/src/async/JobRepository.js +0 -21
- package/dist/src/channels/cmd/@cmd.js +0 -18
- package/dist/src/chatbot/ChatBot.js +0 -50
- package/dist/src/chatbot/ChatBotAdapter.js +0 -70
- package/dist/src/controller/channel/UserResolver.js +0 -21
- package/dist/src/core/IMessageContext.js +0 -12
- package/dist/src/core/chat/ChatItem.js +0 -15
- package/dist/src/core/chat/IChatAdapter.js +0 -3
- package/dist/src/core/chat/repository/IChatMemory.js +0 -10
- package/dist/src/core/user/IUserRepository.js +0 -19
- package/dist/src/core/user/User.js +0 -26
- package/dist/src/jwt/@jwtGuard.js +0 -34
- package/dist/src/jwt/JwtRefreshToken.js +0 -11
- package/dist/src/pre-made/module/authentication/AuthenticationModule.js +0 -97
- package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -25
- package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -25
- package/dist/src/pre-made/module/register-user/RegisterUserModule.js +0 -56
- package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -25
- package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -33
- package/dist/src/pre-made/repository/user/ram/RamUserRepository.js +0 -27
- package/dist/src/pre-made/service/EmailService.js +0 -13
- package/dist/src/pre-made/service/OtpService.js +0 -14
- package/dist/src/server/prepareChatContainer.js +0 -43
- package/dist/src/server/runChannel.js +0 -27
- package/dist/src/server/runServer.js +0 -40
- /package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatMemory.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannelConfig.js +0 -0
- /package/dist/src/{channels/wabot → addon/chat-controller/whatsapp}/WabotDevSocketContracts.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppRepository.js +0 -0
- /package/dist/src/{repository → addon/repository}/pg/PgRepositoryBase.js +0 -0
- /package/dist/src/{validation/validators → addon/validation/is-boolean}/validateIsBoolean.js +0 -0
- /package/dist/src/{validation/validators → addon/validation/is-date}/validateIsDate.js +0 -0
- /package/dist/src/{validation/validators → addon/validation/is-not-empty}/validateIsNotEmpty.js +0 -0
- /package/dist/src/{validation/validators → addon/validation/is-number}/validateIsNumber.js +0 -0
- /package/dist/src/{validation/validators → addon/validation/is-present}/validateIsPresent.js +0 -0
- /package/dist/src/{validation/validators → addon/validation/is-string}/validateIsString.js +0 -0
- /package/dist/src/{validation/validators → addon/validation/max}/validateMax.js +0 -0
- /package/dist/src/{validation/validators → addon/validation/min}/validateMin.js +0 -0
- /package/dist/src/{env → core/env}/Env.js +0 -0
- /package/dist/src/{error → core/error}/CustomError.js +0 -0
- /package/dist/src/{injection → core/injection}/Container.js +0 -0
- /package/dist/src/{injection → core/injection}/index.js +0 -0
- /package/dist/src/{logger → core/logger}/Logger.js +0 -0
- /package/dist/src/{random → core/random}/Random.js +0 -0
- /package/dist/src/core/{Storable.js → storable/Storable.js} +0 -0
- /package/dist/src/{validation → core/validation}/metadata/@isArray.js +0 -0
- /package/dist/src/{validation → core/validation}/metadata/@isModel.js +0 -0
- /package/dist/src/{validation → core/validation}/metadata/@isOptional.js +0 -0
- /package/dist/src/{validation → core/validation}/metadata/ValidationMetadataStore.js +0 -0
- /package/dist/src/{validation → core/validation}/modelInfo.js +0 -0
- /package/dist/src/{validation → core/validation}/validate.js +0 -0
- /package/dist/src/{validation → core/validation}/validators/validateArray.js +0 -0
- /package/dist/src/{validation → core/validation}/validators/validateIsOptional.js +0 -0
- /package/dist/src/{validation → core/validation}/validators/validateModel.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/IMindset.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/functions/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/mindsets/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/modules/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/params/decoratorNames.js +0 -0
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import '../../controller/channel/ChatResolver.js';
|
|
2
|
-
import '../../controller/channel/UserResolver.js';
|
|
3
|
-
import { container } from '../../injection/index.js';
|
|
4
|
-
import { ControllerMetadataStore } from '../../controller/metadata/ControllerMetadataStore.js';
|
|
5
|
-
import { CmdChannel } from './CmdChannel.js';
|
|
6
|
-
|
|
7
|
-
function cmd() {
|
|
8
|
-
return function (target, propertyKey) {
|
|
9
|
-
const store = container.resolve(ControllerMetadataStore);
|
|
10
|
-
store.saveChannelMetadata({
|
|
11
|
-
channelConstructor: CmdChannel,
|
|
12
|
-
functionName: propertyKey.toString(),
|
|
13
|
-
controllerConstructor: target.constructor,
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { cmd };
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import { ChatMemory } from '../core/chat/repository/IChatMemory.js';
|
|
3
|
-
import '../core/chat/repository/IChatRepository.js';
|
|
4
|
-
import '../core/user/IUserRepository.js';
|
|
5
|
-
import { injectable } from '../injection/index.js';
|
|
6
|
-
import { ChatBotAdapter } from './ChatBotAdapter.js';
|
|
7
|
-
|
|
8
|
-
let ChatBot = class ChatBot {
|
|
9
|
-
memory;
|
|
10
|
-
adapter;
|
|
11
|
-
constructor(memory, adapter) {
|
|
12
|
-
this.memory = memory;
|
|
13
|
-
this.adapter = adapter;
|
|
14
|
-
this.memory = memory;
|
|
15
|
-
}
|
|
16
|
-
async sendMessage(message, callback) {
|
|
17
|
-
// const newChatItem = new ChatItem({
|
|
18
|
-
// type: 'CONNECTION_MESSAGE',
|
|
19
|
-
// content: message,
|
|
20
|
-
// })
|
|
21
|
-
// await this.memory.create(newChatItem)
|
|
22
|
-
// this.processLoop(callback)
|
|
23
|
-
}
|
|
24
|
-
async processLoop(callback) {
|
|
25
|
-
// const prevChatItems = await this.memory.findLastItems(10)
|
|
26
|
-
// if (prevChatItems.length === 0) {
|
|
27
|
-
// return
|
|
28
|
-
// }
|
|
29
|
-
// const lastChatItem = prevChatItems[prevChatItems.length - 1]
|
|
30
|
-
// const lastItemType = lastChatItem.getType()
|
|
31
|
-
// if (lastItemType === 'BOT_MESSAGE') {
|
|
32
|
-
// return
|
|
33
|
-
// }
|
|
34
|
-
// const newChatItem = await this.adapter.generateNextChatItem(prevChatItems)
|
|
35
|
-
// await this.memory.create(newChatItem)
|
|
36
|
-
// const newChatItemData = newChatItem.getData()
|
|
37
|
-
// if (newChatItemData.type === 'BOT_MESSAGE') {
|
|
38
|
-
// callback(newChatItemData.content)
|
|
39
|
-
// return
|
|
40
|
-
// }
|
|
41
|
-
// this.processLoop(callback)
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
ChatBot = __decorate([
|
|
45
|
-
injectable(),
|
|
46
|
-
__metadata("design:paramtypes", [ChatMemory,
|
|
47
|
-
ChatBotAdapter])
|
|
48
|
-
], ChatBot);
|
|
49
|
-
|
|
50
|
-
export { ChatBot };
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
class ChatBotAdapter {
|
|
2
|
-
mindset;
|
|
3
|
-
constructor(mindset) {
|
|
4
|
-
this.mindset = mindset;
|
|
5
|
-
}
|
|
6
|
-
generateNextChatItem(chatItems) {
|
|
7
|
-
throw new Error('Not implemented');
|
|
8
|
-
}
|
|
9
|
-
async systemPrompt() {
|
|
10
|
-
let [identity, skills, limits] = await Promise.all([
|
|
11
|
-
this.mindset.identity(),
|
|
12
|
-
this.mindset.skills(),
|
|
13
|
-
this.mindset.limits(),
|
|
14
|
-
]);
|
|
15
|
-
const language = identity.language.replaceAll('#', ' ');
|
|
16
|
-
const name = identity.name.replaceAll('#', ' ');
|
|
17
|
-
const age = identity.age ? identity.age.toString().replaceAll('#', ' ') : null;
|
|
18
|
-
const personality = identity.personality ? identity.personality.replaceAll('#', ' ') : null;
|
|
19
|
-
skills = skills.replaceAll('#', ' ');
|
|
20
|
-
limits = limits.replaceAll('#', ' ');
|
|
21
|
-
const systemPrompt = `
|
|
22
|
-
# System Instructions
|
|
23
|
-
you should act as a assistant.
|
|
24
|
-
your main language is ${language}.
|
|
25
|
-
your name is ${name}.
|
|
26
|
-
${age ? 'you are ' + age + ' years old.' : ''}
|
|
27
|
-
|
|
28
|
-
${personality ? '## Personality (in your main language) \n' + personality : ''}
|
|
29
|
-
|
|
30
|
-
## Skills (in your main language)
|
|
31
|
-
${skills}
|
|
32
|
-
|
|
33
|
-
## System limitations (in your main language)
|
|
34
|
-
${limits}
|
|
35
|
-
|
|
36
|
-
## Chat memory
|
|
37
|
-
Next you will receive a chat history,
|
|
38
|
-
you should use this information to answer the user.
|
|
39
|
-
`;
|
|
40
|
-
return systemPrompt;
|
|
41
|
-
}
|
|
42
|
-
async buildBotMessageItem(text) {
|
|
43
|
-
// const senderName = (await this.mindset.identity()).name
|
|
44
|
-
// const newBotMessage = new ChatItem({
|
|
45
|
-
// type: 'BOT_MESSAGE',
|
|
46
|
-
// content: {
|
|
47
|
-
// senderName,
|
|
48
|
-
// text,
|
|
49
|
-
// },
|
|
50
|
-
// })
|
|
51
|
-
// return newBotMessage
|
|
52
|
-
return 0;
|
|
53
|
-
}
|
|
54
|
-
async buildFunctionCallItem(id, functionName, functionArguments) {
|
|
55
|
-
// const functionResult = await this.mindset.callFunction(functionName, functionArguments)
|
|
56
|
-
// const newFunctionCall = new ChatItem({
|
|
57
|
-
// type: 'FUNCTION_CALL',
|
|
58
|
-
// content: {
|
|
59
|
-
// id,
|
|
60
|
-
// name: functionName,
|
|
61
|
-
// arguments: functionArguments,
|
|
62
|
-
// result: functionResult,
|
|
63
|
-
// },
|
|
64
|
-
// })
|
|
65
|
-
// return newFunctionCall
|
|
66
|
-
return 0;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export { ChatBotAdapter };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import '../../core/chat/repository/IChatRepository.js';
|
|
3
|
-
import { UserRepository } from '../../core/user/IUserRepository.js';
|
|
4
|
-
import { singleton } from '../../injection/index.js';
|
|
5
|
-
|
|
6
|
-
let UserResolver = class UserResolver {
|
|
7
|
-
userRepository;
|
|
8
|
-
constructor(userRepository) {
|
|
9
|
-
this.userRepository = userRepository;
|
|
10
|
-
}
|
|
11
|
-
async resolve(connection) {
|
|
12
|
-
let user = await this.userRepository.findByConnection(connection);
|
|
13
|
-
return user;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
UserResolver = __decorate([
|
|
17
|
-
singleton(),
|
|
18
|
-
__metadata("design:paramtypes", [UserRepository])
|
|
19
|
-
], UserResolver);
|
|
20
|
-
|
|
21
|
-
export { UserResolver };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { __decorate } from 'tslib';
|
|
2
|
-
import { singleton } from '../../injection/index.js';
|
|
3
|
-
|
|
4
|
-
let UserRepository = class UserRepository {
|
|
5
|
-
create(chat) {
|
|
6
|
-
throw new Error('Method not implemented.');
|
|
7
|
-
}
|
|
8
|
-
update(chat) {
|
|
9
|
-
throw new Error('Method not implemented.');
|
|
10
|
-
}
|
|
11
|
-
findByConnection(query) {
|
|
12
|
-
throw new Error('Method not implemented.');
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
UserRepository = __decorate([
|
|
16
|
-
singleton()
|
|
17
|
-
], UserRepository);
|
|
18
|
-
|
|
19
|
-
export { UserRepository };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Entity } from '../Entity.js';
|
|
2
|
-
|
|
3
|
-
class User extends Entity {
|
|
4
|
-
constructor(data) {
|
|
5
|
-
super(data);
|
|
6
|
-
}
|
|
7
|
-
hasConnection(connection) {
|
|
8
|
-
for (const con of this.data.connections) {
|
|
9
|
-
if (con.channelName === connection.channelName && con.id === connection.id) {
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
getValue(key) {
|
|
16
|
-
return this.data.keyValueData[key];
|
|
17
|
-
}
|
|
18
|
-
setValue(key, value) {
|
|
19
|
-
this.data.keyValueData[key] = value;
|
|
20
|
-
}
|
|
21
|
-
addConnection(connection) {
|
|
22
|
-
this.data.connections.push(connection);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export { User };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import '../injection/index.js';
|
|
2
|
-
import '../rest-controller/metadata/RestControllerMetadataStore.js';
|
|
3
|
-
import { middleware } from '../rest-controller/metadata/@middleware.js';
|
|
4
|
-
import '../controller/channel/ChatResolver.js';
|
|
5
|
-
import '../controller/channel/UserResolver.js';
|
|
6
|
-
import '../controller/metadata/ControllerMetadataStore.js';
|
|
7
|
-
import '../channels/cmd/CmdChannel.js';
|
|
8
|
-
import '../channels/express/ExpressProvider.js';
|
|
9
|
-
import '../channels/http/HttpServerProvider.js';
|
|
10
|
-
import '../channels/socket/SocketChannel.js';
|
|
11
|
-
import '../channels/socket/SocketChannelConfig.js';
|
|
12
|
-
import '../channels/socket/SocketServerProvider.js';
|
|
13
|
-
import '../channels/telegram/TelegramChannel.js';
|
|
14
|
-
import '../channels/whatsapp/WhatsAppChannel.js';
|
|
15
|
-
import '../channels/whatsapp/EnvWhatsAppRepository.js';
|
|
16
|
-
import '../channels/whatsapp/PgWhatsAppRepository.js';
|
|
17
|
-
import '../core/chat/repository/IChatRepository.js';
|
|
18
|
-
import '../core/user/IUserRepository.js';
|
|
19
|
-
import '../channels/whatsapp/WhatsAppReceiverByDevConnection.js';
|
|
20
|
-
import '../channels/whatsapp/WhatsAppReceiverByWebHook.js';
|
|
21
|
-
import '../channels/whatsapp/WhatsAppSenderByCloudApi.js';
|
|
22
|
-
import '../channels/whatsapp/WhatsAppSenderByDevConnection.js';
|
|
23
|
-
import 'debug';
|
|
24
|
-
import '../validation/metadata/ValidationMetadataStore.js';
|
|
25
|
-
import 'path';
|
|
26
|
-
import { JwtGuardMiddleware } from './JwtGuardMiddleware.js';
|
|
27
|
-
|
|
28
|
-
function jwtGuard() {
|
|
29
|
-
return function (target, propertyKey) {
|
|
30
|
-
middleware(JwtGuardMiddleware)(target, propertyKey);
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export { jwtGuard };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import '../core/chat/repository/IChatRepository.js';
|
|
2
|
-
import { Entity } from '../core/Entity.js';
|
|
3
|
-
import '../core/user/IUserRepository.js';
|
|
4
|
-
|
|
5
|
-
class JwtRefreshToken extends Entity {
|
|
6
|
-
get authInfo() {
|
|
7
|
-
return this.data.authInfo;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { JwtRefreshToken };
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import '../../../core/chat/repository/IChatRepository.js';
|
|
3
|
-
import { UserRepository } from '../../../core/user/IUserRepository.js';
|
|
4
|
-
import { MessageContext } from '../../../core/IMessageContext.js';
|
|
5
|
-
import { mindsetFunction } from '../../../mindset/metadata/functions/@mindsetFunction.js';
|
|
6
|
-
import 'reflect-metadata';
|
|
7
|
-
import '../../../injection/index.js';
|
|
8
|
-
import '../../../mindset/metadata/MindsetMetadataStore.js';
|
|
9
|
-
import { mindsetModule } from '../../../mindset/metadata/modules/@mindsetModule.js';
|
|
10
|
-
import '../../../mindset/MindsetOperator.js';
|
|
11
|
-
import { EmailService } from '../../service/EmailService.js';
|
|
12
|
-
import { OtpService } from '../../service/OtpService.js';
|
|
13
|
-
import { SendOneTimePasswordRequest } from './requests/SendOneTimePasswordRequest.js';
|
|
14
|
-
import { ValidateOneTimePasswordRequest } from './requests/ValidateOneTimePasswordRequest.js';
|
|
15
|
-
|
|
16
|
-
let AuthenticationModule = class AuthenticationModule {
|
|
17
|
-
userRepository;
|
|
18
|
-
emailService;
|
|
19
|
-
otpService;
|
|
20
|
-
context;
|
|
21
|
-
constructor(userRepository, emailService, otpService, context) {
|
|
22
|
-
this.userRepository = userRepository;
|
|
23
|
-
this.emailService = emailService;
|
|
24
|
-
this.otpService = otpService;
|
|
25
|
-
this.context = context;
|
|
26
|
-
}
|
|
27
|
-
async sendOneTimePassword(request) {
|
|
28
|
-
const user = await this.userRepository.findByConnection({
|
|
29
|
-
channelName: 'EmailChannel',
|
|
30
|
-
id: request.toEmail,
|
|
31
|
-
});
|
|
32
|
-
if (!user)
|
|
33
|
-
return 'success';
|
|
34
|
-
const otp = await this.otpService.generate();
|
|
35
|
-
const html = await this.generateOtpEmailHtml(otp, user);
|
|
36
|
-
const subject = await this.generateOtpEmailSubject();
|
|
37
|
-
await this.emailService.sendEmail({
|
|
38
|
-
from: request.fromEmail,
|
|
39
|
-
to: request.toEmail,
|
|
40
|
-
subject,
|
|
41
|
-
html,
|
|
42
|
-
});
|
|
43
|
-
user.setValue('OTP', otp);
|
|
44
|
-
await this.userRepository.update(user);
|
|
45
|
-
return 'success';
|
|
46
|
-
}
|
|
47
|
-
async validateOneTimePassword(request) {
|
|
48
|
-
const user = await this.userRepository.findByConnection({
|
|
49
|
-
channelName: 'EmailChannel',
|
|
50
|
-
id: request.userEmail,
|
|
51
|
-
});
|
|
52
|
-
if (!user) {
|
|
53
|
-
throw new Error('Invalid OTP');
|
|
54
|
-
}
|
|
55
|
-
const otp = user.getValue('OTP');
|
|
56
|
-
if (otp !== request.otp) {
|
|
57
|
-
throw new Error('Invalid OTP');
|
|
58
|
-
}
|
|
59
|
-
user.addConnection(this.context.message.userConnection);
|
|
60
|
-
await this.userRepository.update(user);
|
|
61
|
-
return 'success';
|
|
62
|
-
}
|
|
63
|
-
async generateOtpEmailHtml(otp, user) {
|
|
64
|
-
return `<p>Your OTP Code is ${otp}</p>`;
|
|
65
|
-
}
|
|
66
|
-
async generateOtpEmailSubject() {
|
|
67
|
-
return 'OTP Code';
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
__decorate([
|
|
71
|
-
mindsetFunction({
|
|
72
|
-
description: 'Send an One Time Password to the user when want authenticate',
|
|
73
|
-
}),
|
|
74
|
-
__metadata("design:type", Function),
|
|
75
|
-
__metadata("design:paramtypes", [SendOneTimePasswordRequest]),
|
|
76
|
-
__metadata("design:returntype", Promise)
|
|
77
|
-
], AuthenticationModule.prototype, "sendOneTimePassword", null);
|
|
78
|
-
__decorate([
|
|
79
|
-
mindsetFunction({
|
|
80
|
-
description: 'Send an One Time Password to the user when want authenticate',
|
|
81
|
-
}),
|
|
82
|
-
__metadata("design:type", Function),
|
|
83
|
-
__metadata("design:paramtypes", [ValidateOneTimePasswordRequest]),
|
|
84
|
-
__metadata("design:returntype", Promise)
|
|
85
|
-
], AuthenticationModule.prototype, "validateOneTimePassword", null);
|
|
86
|
-
AuthenticationModule = __decorate([
|
|
87
|
-
mindsetModule({
|
|
88
|
-
description: 'Provide authentication methods',
|
|
89
|
-
language: 'english',
|
|
90
|
-
}),
|
|
91
|
-
__metadata("design:paramtypes", [UserRepository,
|
|
92
|
-
EmailService,
|
|
93
|
-
OtpService,
|
|
94
|
-
MessageContext])
|
|
95
|
-
], AuthenticationModule);
|
|
96
|
-
|
|
97
|
-
export { AuthenticationModule };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import 'reflect-metadata';
|
|
3
|
-
import '../../../../injection/index.js';
|
|
4
|
-
import '../../../../mindset/metadata/MindsetMetadataStore.js';
|
|
5
|
-
import { param } from '../../../../mindset/metadata/params/@param.js';
|
|
6
|
-
import '../../../../mindset/MindsetOperator.js';
|
|
7
|
-
|
|
8
|
-
class SendOneTimePasswordRequest {
|
|
9
|
-
fromEmail = '';
|
|
10
|
-
toEmail = '';
|
|
11
|
-
}
|
|
12
|
-
__decorate([
|
|
13
|
-
param({
|
|
14
|
-
description: 'Sender Email address',
|
|
15
|
-
}),
|
|
16
|
-
__metadata("design:type", String)
|
|
17
|
-
], SendOneTimePasswordRequest.prototype, "fromEmail", void 0);
|
|
18
|
-
__decorate([
|
|
19
|
-
param({
|
|
20
|
-
description: 'Recipient Email Address, to send one time password',
|
|
21
|
-
}),
|
|
22
|
-
__metadata("design:type", String)
|
|
23
|
-
], SendOneTimePasswordRequest.prototype, "toEmail", void 0);
|
|
24
|
-
|
|
25
|
-
export { SendOneTimePasswordRequest };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import 'reflect-metadata';
|
|
3
|
-
import '../../../../injection/index.js';
|
|
4
|
-
import '../../../../mindset/metadata/MindsetMetadataStore.js';
|
|
5
|
-
import { param } from '../../../../mindset/metadata/params/@param.js';
|
|
6
|
-
import '../../../../mindset/MindsetOperator.js';
|
|
7
|
-
|
|
8
|
-
class ValidateOneTimePasswordRequest {
|
|
9
|
-
userEmail = '';
|
|
10
|
-
otp = '';
|
|
11
|
-
}
|
|
12
|
-
__decorate([
|
|
13
|
-
param({
|
|
14
|
-
description: 'User Email',
|
|
15
|
-
}),
|
|
16
|
-
__metadata("design:type", String)
|
|
17
|
-
], ValidateOneTimePasswordRequest.prototype, "userEmail", void 0);
|
|
18
|
-
__decorate([
|
|
19
|
-
param({
|
|
20
|
-
description: 'Otp provided by the User',
|
|
21
|
-
}),
|
|
22
|
-
__metadata("design:type", String)
|
|
23
|
-
], ValidateOneTimePasswordRequest.prototype, "otp", void 0);
|
|
24
|
-
|
|
25
|
-
export { ValidateOneTimePasswordRequest };
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import '../../../core/chat/repository/IChatRepository.js';
|
|
3
|
-
import { User } from '../../../core/user/User.js';
|
|
4
|
-
import { UserRepository } from '../../../core/user/IUserRepository.js';
|
|
5
|
-
import { MessageContext } from '../../../core/IMessageContext.js';
|
|
6
|
-
import { mindsetFunction } from '../../../mindset/metadata/functions/@mindsetFunction.js';
|
|
7
|
-
import 'reflect-metadata';
|
|
8
|
-
import '../../../injection/index.js';
|
|
9
|
-
import '../../../mindset/metadata/MindsetMetadataStore.js';
|
|
10
|
-
import { mindsetModule } from '../../../mindset/metadata/modules/@mindsetModule.js';
|
|
11
|
-
import '../../../mindset/MindsetOperator.js';
|
|
12
|
-
import { RegisterUserWithEmailRequest } from './requests/RegisterUserWithEmailRequest.js';
|
|
13
|
-
|
|
14
|
-
let RegisterUserModule = class RegisterUserModule {
|
|
15
|
-
userRepository;
|
|
16
|
-
context;
|
|
17
|
-
constructor(userRepository, context) {
|
|
18
|
-
this.userRepository = userRepository;
|
|
19
|
-
this.context = context;
|
|
20
|
-
}
|
|
21
|
-
async registerUserWithEmail(request) {
|
|
22
|
-
if (this.context.user) {
|
|
23
|
-
throw new Error('The User is already authenticated');
|
|
24
|
-
}
|
|
25
|
-
const user = new User({
|
|
26
|
-
shortName: request.shortName,
|
|
27
|
-
connections: [
|
|
28
|
-
{
|
|
29
|
-
channelName: 'EmailChannel',
|
|
30
|
-
id: request.email,
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
keyValueData: {},
|
|
34
|
-
});
|
|
35
|
-
await this.userRepository.create(user);
|
|
36
|
-
return 'success';
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
__decorate([
|
|
40
|
-
mindsetFunction({
|
|
41
|
-
description: 'Register a new user using email',
|
|
42
|
-
}),
|
|
43
|
-
__metadata("design:type", Function),
|
|
44
|
-
__metadata("design:paramtypes", [RegisterUserWithEmailRequest]),
|
|
45
|
-
__metadata("design:returntype", Promise)
|
|
46
|
-
], RegisterUserModule.prototype, "registerUserWithEmail", null);
|
|
47
|
-
RegisterUserModule = __decorate([
|
|
48
|
-
mindsetModule({
|
|
49
|
-
description: 'Provide functions to register an user',
|
|
50
|
-
language: 'english',
|
|
51
|
-
}),
|
|
52
|
-
__metadata("design:paramtypes", [UserRepository,
|
|
53
|
-
MessageContext])
|
|
54
|
-
], RegisterUserModule);
|
|
55
|
-
|
|
56
|
-
export { RegisterUserModule };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import 'reflect-metadata';
|
|
3
|
-
import '../../../../injection/index.js';
|
|
4
|
-
import '../../../../mindset/metadata/MindsetMetadataStore.js';
|
|
5
|
-
import { param } from '../../../../mindset/metadata/params/@param.js';
|
|
6
|
-
import '../../../../mindset/MindsetOperator.js';
|
|
7
|
-
|
|
8
|
-
class RegisterUserWithEmailRequest {
|
|
9
|
-
email = '';
|
|
10
|
-
shortName = '';
|
|
11
|
-
}
|
|
12
|
-
__decorate([
|
|
13
|
-
param({
|
|
14
|
-
description: 'Email of the User',
|
|
15
|
-
}),
|
|
16
|
-
__metadata("design:type", String)
|
|
17
|
-
], RegisterUserWithEmailRequest.prototype, "email", void 0);
|
|
18
|
-
__decorate([
|
|
19
|
-
param({
|
|
20
|
-
description: 'ShortName for the new User',
|
|
21
|
-
}),
|
|
22
|
-
__metadata("design:type", String)
|
|
23
|
-
], RegisterUserWithEmailRequest.prototype, "shortName", void 0);
|
|
24
|
-
|
|
25
|
-
export { RegisterUserWithEmailRequest };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import '../../../../core/chat/repository/IChatRepository.js';
|
|
3
|
-
import { User } from '../../../../core/user/User.js';
|
|
4
|
-
import '../../../../core/user/IUserRepository.js';
|
|
5
|
-
import { singleton } from '../../../../injection/index.js';
|
|
6
|
-
import { PgCrudRepository } from '../../../../repository/pg/PgCrudRepository.js';
|
|
7
|
-
import { Pool } from 'pg';
|
|
8
|
-
|
|
9
|
-
let PgUserRepository = class PgUserRepository extends PgCrudRepository {
|
|
10
|
-
constructor(pool) {
|
|
11
|
-
super(pool, {
|
|
12
|
-
table: 'user',
|
|
13
|
-
schema: 'wabot',
|
|
14
|
-
constructor: User,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
async findByConnection(query) {
|
|
18
|
-
const sql = `
|
|
19
|
-
SELECT ${this.columns}
|
|
20
|
-
FROM ${this.table}
|
|
21
|
-
WHERE data->'connections' @> $1::jsonb
|
|
22
|
-
LIMIT 1
|
|
23
|
-
`;
|
|
24
|
-
const items = await this.query(sql, [JSON.stringify([query])]);
|
|
25
|
-
return items.at(0) ?? null;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
PgUserRepository = __decorate([
|
|
29
|
-
singleton(),
|
|
30
|
-
__metadata("design:paramtypes", [Pool])
|
|
31
|
-
], PgUserRepository);
|
|
32
|
-
|
|
33
|
-
export { PgUserRepository };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { __decorate } from 'tslib';
|
|
2
|
-
import { v4 } from 'uuid';
|
|
3
|
-
import { singleton } from '../../../../injection/index.js';
|
|
4
|
-
|
|
5
|
-
let RamUserRepository = class RamUserRepository {
|
|
6
|
-
items = [];
|
|
7
|
-
async create(chat) {
|
|
8
|
-
if (chat.wasCreated()) {
|
|
9
|
-
throw new Error('User already created');
|
|
10
|
-
}
|
|
11
|
-
chat['data'].id = v4();
|
|
12
|
-
chat['data'].createdAt = new Date().getTime();
|
|
13
|
-
chat.validate();
|
|
14
|
-
this.items.push(chat);
|
|
15
|
-
}
|
|
16
|
-
async findByConnection(query) {
|
|
17
|
-
return this.items.find((item) => item.hasConnection(query)) ?? null;
|
|
18
|
-
}
|
|
19
|
-
async update(chat) {
|
|
20
|
-
// TODO
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
RamUserRepository = __decorate([
|
|
24
|
-
singleton()
|
|
25
|
-
], RamUserRepository);
|
|
26
|
-
|
|
27
|
-
export { RamUserRepository };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { __decorate } from 'tslib';
|
|
2
|
-
import { injectable } from '../../injection/index.js';
|
|
3
|
-
|
|
4
|
-
let EmailService = class EmailService {
|
|
5
|
-
async sendEmail(request) {
|
|
6
|
-
throw new Error('Not implemented');
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
EmailService = __decorate([
|
|
10
|
-
injectable()
|
|
11
|
-
], EmailService);
|
|
12
|
-
|
|
13
|
-
export { EmailService };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { __decorate } from 'tslib';
|
|
2
|
-
import { injectable } from '../../injection/index.js';
|
|
3
|
-
import { randomInt } from 'crypto';
|
|
4
|
-
|
|
5
|
-
let OtpService = class OtpService {
|
|
6
|
-
async generate() {
|
|
7
|
-
return randomInt(100000, 999999).toString();
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
OtpService = __decorate([
|
|
11
|
-
injectable()
|
|
12
|
-
], OtpService);
|
|
13
|
-
|
|
14
|
-
export { OtpService };
|