@wabot-dev/framework 0.1.0-beta.5 → 0.1.0-beta.51
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/auth/api-key/@apiKeyGuard.js +17 -0
- package/dist/src/addon/auth/api-key/ApiKey.js +53 -0
- package/dist/src/addon/auth/api-key/ApiKeyGuardMiddleware.js +45 -0
- package/dist/src/addon/auth/api-key/ApiKeyRepository.js +13 -0
- package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +21 -0
- package/dist/src/addon/auth/jwt/@jwtConnectionGuard.js +16 -0
- package/dist/src/addon/auth/jwt/@jwtGuard.js +17 -0
- package/dist/src/addon/auth/jwt/Jwt.js +53 -0
- package/dist/src/addon/auth/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
- package/dist/src/addon/auth/jwt/JwtConfig.js +28 -0
- package/dist/src/addon/auth/jwt/JwtConnectionGuardMiddleware.js +57 -0
- package/dist/src/addon/auth/jwt/JwtGuardMiddleware.js +45 -0
- package/dist/src/addon/auth/jwt/JwtRefreshToken.js +56 -0
- package/dist/src/addon/auth/jwt/JwtRefreshTokenRepository.js +25 -0
- package/dist/src/addon/auth/jwt/JwtSigner.js +36 -0
- package/dist/src/addon/auth/jwt/JwtTokenDto.js +22 -0
- package/dist/src/addon/auth/jwt/PgJwtRefreshTokenRepository.js +21 -0
- package/dist/src/addon/chat-bot/anthropic/AnthropicChatAdapter.js +135 -0
- package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +137 -0
- package/dist/src/addon/chat-bot/google/GoogleChatAdapter.js +145 -0
- package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +117 -0
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +6 -4
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +6 -5
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
- package/dist/src/addon/chat-bot/wabot/WabotChatAdapter.js +41 -0
- package/dist/src/addon/chat-controller/cmd/@cmd.js +23 -0
- package/dist/src/{channels → addon/chat-controller}/cmd/CmdChannel.js +4 -26
- package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +9 -4
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +5 -23
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
- package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +9 -4
- package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
- package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +25 -0
- package/dist/src/{channels → addon/chat-controller}/whatsapp/EnvWhatsAppRepository.js +3 -3
- package/dist/src/{channels → addon/chat-controller}/whatsapp/PgWhatsAppRepository.js +2 -2
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +2 -4
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppReceiver.js +10 -0
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +20 -41
- package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppReceiverByCloudApi.js +97 -0
- package/dist/src/{channels/whatsapp → addon/chat-controller/whatsapp/cloud-api}/WhatsAppSenderByCloudApi.js +26 -20
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppProxyContracts.js +5 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppReceiverByWabotProxy.js +65 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppSenderByWabotProxy.js +60 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppWabotProxyConnection.js +45 -0
- package/dist/src/addon/mindset/html/HtmlModule.js +70 -0
- package/dist/src/core/auth/Auth.js +24 -0
- package/dist/src/core/{Persistent.js → entity/Entity.js} +24 -9
- package/dist/src/core/env/Env.js +39 -0
- package/dist/src/core/error/CustomError.js +15 -0
- package/dist/src/core/injection/index.js +4 -0
- package/dist/src/core/mapper/Mapper.js +42 -0
- package/dist/src/core/password/Password.js +30 -0
- package/dist/src/core/random/Random.js +47 -0
- package/dist/src/core/storable/Storable.js +8 -0
- package/dist/src/core/validation/core/validateArray.js +51 -0
- package/dist/src/core/validation/core/validateIsOptional.js +5 -0
- package/dist/src/core/validation/core/validateModel.js +36 -0
- package/dist/src/core/validation/metadata/@isArray.js +18 -0
- package/dist/src/core/validation/metadata/@isModel.js +18 -0
- package/dist/src/core/validation/metadata/@isOptional.js +17 -0
- package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
- package/dist/src/core/validation/modelInfo.js +9 -0
- package/dist/src/core/validation/validate.js +11 -0
- package/dist/src/core/validation/validators/is-boolean/@isBoolean.js +17 -0
- package/dist/src/core/validation/validators/is-boolean/validateIsBoolean.js +12 -0
- package/dist/src/core/validation/validators/is-date/@isDate.js +17 -0
- package/dist/src/core/validation/validators/is-date/validateIsDate.js +16 -0
- package/dist/src/core/validation/validators/is-not-empty/@isNotEmpty.js +17 -0
- package/dist/src/core/validation/validators/is-not-empty/validateIsNotEmpty.js +12 -0
- package/dist/src/core/validation/validators/is-number/@isNumber.js +17 -0
- package/dist/src/core/validation/validators/is-number/validateIsNumber.js +12 -0
- package/dist/src/core/validation/validators/is-present/@isPresent.js +17 -0
- package/dist/src/core/validation/validators/is-present/validateIsPresent.js +12 -0
- package/dist/src/core/validation/validators/is-string/@isString.js +17 -0
- package/dist/src/core/validation/validators/is-string/validateIsString.js +12 -0
- package/dist/src/core/validation/validators/max/@max.js +18 -0
- package/dist/src/core/validation/validators/max/validateMax.js +17 -0
- package/dist/src/core/validation/validators/min/@min.js +18 -0
- package/dist/src/core/validation/validators/min/validateMin.js +17 -0
- package/dist/src/feature/async/@command.js +11 -0
- package/dist/src/feature/async/@commandHandler.js +12 -0
- package/dist/src/feature/async/Async.js +38 -0
- package/dist/src/feature/async/Command.js +9 -0
- package/dist/src/feature/async/CommandMetadataStore.js +38 -0
- package/dist/src/feature/async/Job.js +24 -0
- package/dist/src/feature/async/JobRepository.js +31 -0
- package/dist/src/feature/async/JobRunner.js +45 -0
- package/dist/src/feature/async/JobsEventsHub.js +24 -0
- package/dist/src/feature/async/runCommandHandlers.js +29 -0
- package/dist/src/{core/chat → feature/chat-bot}/Chat.js +2 -2
- package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
- package/dist/src/feature/chat-bot/ChatBot.js +73 -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 +6 -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 +2 -4
- package/dist/src/{channels → feature}/http/HttpServerProvider.js +2 -2
- package/dist/src/{mindset → feature/mindset}/IMindset.js +3 -0
- package/dist/src/{mindset → feature/mindset}/MindsetOperator.js +69 -42
- 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/feature/money/Money.js +61 -0
- package/dist/src/feature/money/MoneyDto.js +22 -0
- package/dist/src/{repository → feature}/pg/PgCrudRepository.js +25 -2
- package/dist/src/{repository → feature}/pg/PgRepositoryBase.js +2 -2
- package/dist/src/feature/rest-controller/injection-tokens.js +4 -0
- package/dist/src/feature/rest-controller/metadata/@get.js +19 -0
- package/dist/src/feature/rest-controller/metadata/@middleware.js +16 -0
- package/dist/src/feature/rest-controller/metadata/@post.js +19 -0
- package/dist/src/feature/rest-controller/metadata/@restController.js +15 -0
- package/dist/src/feature/rest-controller/metadata/RestControllerMetadataStore.js +50 -0
- package/dist/src/feature/rest-controller/runRestControllers.js +102 -0
- package/dist/src/{channels → feature}/socket/SocketServerProvider.js +2 -2
- package/dist/src/feature/socket-controller/metadata/@connectionMiddleware.js +16 -0
- package/dist/src/feature/socket-controller/metadata/@socketConnection.js +18 -0
- package/dist/src/feature/socket-controller/metadata/@socketController.js +15 -0
- package/dist/src/feature/socket-controller/metadata/@socketEvent.js +18 -0
- package/dist/src/feature/socket-controller/metadata/SocketControllerMetadataStore.js +65 -0
- package/dist/src/feature/socket-controller/runSocketControllers.js +98 -0
- package/dist/src/index.d.ts +1151 -575
- package/dist/src/index.js +140 -76
- package/package.json +10 -4
- package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -106
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -84
- package/dist/src/channels/cmd/@cmd.js +0 -18
- package/dist/src/channels/wabot/WabotDevConnection.js +0 -57
- package/dist/src/channels/wabot/WabotDevSocketContracts.js +0 -10
- package/dist/src/channels/whatsapp/@whatsapp.js +0 -20
- package/dist/src/channels/whatsapp/WhatsAppReceiver.js +0 -59
- package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +0 -32
- package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +0 -63
- package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +0 -61
- package/dist/src/chatbot/ChatBot.js +0 -51
- package/dist/src/chatbot/ChatBotAdapter.js +0 -72
- 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/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/env/WabotEnv.js +0 -27
- package/dist/src/injection/index.js +0 -4
- package/dist/src/mindset/metadata/params/@isOptional.js +0 -21
- 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 → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppRepository.js +0 -0
- /package/dist/src/{injection → core/injection}/Container.js +0 -0
- /package/dist/src/{logger → core/logger}/Logger.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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { WhatsAppReceiver } from '../WhatsAppReceiver.js';
|
|
3
|
+
import { injectable } from '../../../../core/injection/index.js';
|
|
4
|
+
import { Logger } from '../../../../core/logger/Logger.js';
|
|
5
|
+
import { WHATSAPP_MESSAGE_EVENT } from './WhatsAppProxyContracts.js';
|
|
6
|
+
import { WhatsAppWabotProxyConnection } from './WhatsAppWabotProxyConnection.js';
|
|
7
|
+
|
|
8
|
+
let WhatsAppReceiverByWabotProxy = class WhatsAppReceiverByWabotProxy extends WhatsAppReceiver {
|
|
9
|
+
connection;
|
|
10
|
+
loger = new Logger('wabot:whats-app-receiver-by-wabot-proxy');
|
|
11
|
+
constructor(connection) {
|
|
12
|
+
super();
|
|
13
|
+
this.connection = connection;
|
|
14
|
+
}
|
|
15
|
+
async connect() {
|
|
16
|
+
// Nothing
|
|
17
|
+
}
|
|
18
|
+
listenMessage(request) {
|
|
19
|
+
this.connection.getSocket().then(async (socket) => {
|
|
20
|
+
const req = {
|
|
21
|
+
event: 'listenMessage',
|
|
22
|
+
data: {
|
|
23
|
+
to: [request.to],
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const response = await socket.emitWithAck(req.event, req.data);
|
|
27
|
+
if (response && typeof response == 'object' && response['error']) {
|
|
28
|
+
this.loger.error(response.error);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
else if (!response ||
|
|
32
|
+
typeof response !== 'object' ||
|
|
33
|
+
!Array.isArray(response.from) ||
|
|
34
|
+
!Array.isArray(response.to)) {
|
|
35
|
+
this.loger.error('unknown response');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this.loger.trace(`succes add whats-app proxy listener for messages from [${response.from.join(',')}] to [${response.to.join(',')}]`);
|
|
39
|
+
socket.on(WHATSAPP_MESSAGE_EVENT, (data, callback) => {
|
|
40
|
+
if (data.to !== request.to) {
|
|
41
|
+
throw new Error(`expecting message to '${request.to}' but received to='${data.to}'`);
|
|
42
|
+
}
|
|
43
|
+
callback({ success: true });
|
|
44
|
+
this.loger.trace(`success receive message from '${data.from}' to '${data.to}'`);
|
|
45
|
+
request.listener({
|
|
46
|
+
chatConnection: {
|
|
47
|
+
channelName: 'WhatsAppChannel',
|
|
48
|
+
id: data.from,
|
|
49
|
+
},
|
|
50
|
+
message: {
|
|
51
|
+
text: data.content.text,
|
|
52
|
+
senderName: data.senderName,
|
|
53
|
+
senderId: data.from,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
WhatsAppReceiverByWabotProxy = __decorate([
|
|
61
|
+
injectable(),
|
|
62
|
+
__metadata("design:paramtypes", [WhatsAppWabotProxyConnection])
|
|
63
|
+
], WhatsAppReceiverByWabotProxy);
|
|
64
|
+
|
|
65
|
+
export { WhatsAppReceiverByWabotProxy };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { WhatsAppSender } from '../WhatsAppSender.js';
|
|
3
|
+
import { singleton } from '../../../../core/injection/index.js';
|
|
4
|
+
import { Logger } from '../../../../core/logger/Logger.js';
|
|
5
|
+
import '../../../../feature/chat-bot/ChatBot.js';
|
|
6
|
+
import { ChatRepository } from '../../../../feature/chat-bot/ChatRepository.js';
|
|
7
|
+
import 'uuid';
|
|
8
|
+
import '../../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
9
|
+
import '../../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
|
|
10
|
+
import { ChatResolver } from '../../../../feature/chat-controller/ChatResolver.js';
|
|
11
|
+
import 'reflect-metadata';
|
|
12
|
+
import '../../../../feature/mindset/metadata/MindsetMetadataStore.js';
|
|
13
|
+
import '../../../../feature/mindset/MindsetOperator.js';
|
|
14
|
+
import { WhatsAppRepository } from '../WhatsAppRepository.js';
|
|
15
|
+
import { WhatsAppWabotProxyConnection } from './WhatsAppWabotProxyConnection.js';
|
|
16
|
+
|
|
17
|
+
let WhatsAppSenderByWabotProxy = class WhatsAppSenderByWabotProxy extends WhatsAppSender {
|
|
18
|
+
wabotDevConnection;
|
|
19
|
+
logger = new Logger('wabot:whatsapp-sender-by-wabot-proxy');
|
|
20
|
+
constructor(wabotDevConnection, chatRepository, chatResolver, whatsAppRepository) {
|
|
21
|
+
super(chatRepository, chatResolver, whatsAppRepository);
|
|
22
|
+
this.wabotDevConnection = wabotDevConnection;
|
|
23
|
+
}
|
|
24
|
+
async sendWhatsApp(request, options) {
|
|
25
|
+
try {
|
|
26
|
+
const socket = await this.wabotDevConnection.getSocket();
|
|
27
|
+
const req = {
|
|
28
|
+
event: 'sendMessage',
|
|
29
|
+
data: {
|
|
30
|
+
from: request.from,
|
|
31
|
+
to: request.to,
|
|
32
|
+
content: {
|
|
33
|
+
text: request.message.text ?? 'No Text',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const ack = await socket.timeout(5000).emitWithAck(req.event, req.data);
|
|
38
|
+
if (!ack || !ack.success) {
|
|
39
|
+
throw new Error(`not success ack, when send whatsapp from '${request.from}' to '${request.to}'`);
|
|
40
|
+
}
|
|
41
|
+
this.logger.trace(`success send whatsapp from '${request.from}' to '${request.to}'`);
|
|
42
|
+
if (options?.writeChatMemory) {
|
|
43
|
+
await this.writePrivateChatMemory(request.message, request.to);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
this.logger.error(err);
|
|
48
|
+
throw new Error(undefined, { cause: err });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
WhatsAppSenderByWabotProxy = __decorate([
|
|
53
|
+
singleton(),
|
|
54
|
+
__metadata("design:paramtypes", [WhatsAppWabotProxyConnection,
|
|
55
|
+
ChatRepository,
|
|
56
|
+
ChatResolver,
|
|
57
|
+
WhatsAppRepository])
|
|
58
|
+
], WhatsAppSenderByWabotProxy);
|
|
59
|
+
|
|
60
|
+
export { WhatsAppSenderByWabotProxy };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { Env } from '../../../../core/env/Env.js';
|
|
3
|
+
import { injectable } from '../../../../core/injection/index.js';
|
|
4
|
+
import { Logger } from '../../../../core/logger/Logger.js';
|
|
5
|
+
import { io } from 'socket.io-client';
|
|
6
|
+
|
|
7
|
+
let WhatsAppWabotProxyConnection = class WhatsAppWabotProxyConnection {
|
|
8
|
+
baseUrl;
|
|
9
|
+
socket = null;
|
|
10
|
+
apiKey;
|
|
11
|
+
logger = new Logger('wabot:whats-app-wabot-proxy-connection');
|
|
12
|
+
constructor(env) {
|
|
13
|
+
this.apiKey = env.requireString('WABOT_API_KEY');
|
|
14
|
+
this.baseUrl = env.requireString('WABOT_PROXY_URL');
|
|
15
|
+
while (this.baseUrl.endsWith('/')) {
|
|
16
|
+
this.baseUrl = this.baseUrl.substring(0, this.baseUrl.length - 1);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async getSocket() {
|
|
20
|
+
if (this.socket) {
|
|
21
|
+
return this.socket;
|
|
22
|
+
}
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
const socket = io(`${this.baseUrl}/whats-app`, {
|
|
25
|
+
autoConnect: false,
|
|
26
|
+
auth: { token: this.apiKey },
|
|
27
|
+
reconnection: true,
|
|
28
|
+
});
|
|
29
|
+
socket.on('connect', async () => {
|
|
30
|
+
this.socket = socket;
|
|
31
|
+
resolve(socket);
|
|
32
|
+
});
|
|
33
|
+
socket.on('connect_error', (err) => {
|
|
34
|
+
reject(new Error(err && err.message ? err.message : 'connection error', { cause: err }));
|
|
35
|
+
});
|
|
36
|
+
socket.connect();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
WhatsAppWabotProxyConnection = __decorate([
|
|
41
|
+
injectable(),
|
|
42
|
+
__metadata("design:paramtypes", [Env])
|
|
43
|
+
], WhatsAppWabotProxyConnection);
|
|
44
|
+
|
|
45
|
+
export { WhatsAppWabotProxyConnection };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { mindsetFunction } from '../../../feature/mindset/metadata/functions/@mindsetFunction.js';
|
|
3
|
+
import 'reflect-metadata';
|
|
4
|
+
import '../../../core/injection/index.js';
|
|
5
|
+
import '../../../feature/mindset/metadata/MindsetMetadataStore.js';
|
|
6
|
+
import { mindsetModule } from '../../../feature/mindset/metadata/modules/@mindsetModule.js';
|
|
7
|
+
import { param } from '../../../feature/mindset/metadata/params/@param.js';
|
|
8
|
+
import '../../../feature/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 };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { CustomError } from '../error/CustomError.js';
|
|
3
|
+
import { scoped, Lifecycle } from '../injection/index.js';
|
|
4
|
+
|
|
5
|
+
let Auth = class Auth {
|
|
6
|
+
authInfo = null;
|
|
7
|
+
require() {
|
|
8
|
+
if (!this.authInfo) {
|
|
9
|
+
throw new CustomError({ message: 'Unauthorized', httpCode: 401 });
|
|
10
|
+
}
|
|
11
|
+
return this.authInfo;
|
|
12
|
+
}
|
|
13
|
+
assign(authInfo) {
|
|
14
|
+
if (this.authInfo) {
|
|
15
|
+
throw new CustomError({ message: 'Authorization info already assigned', httpCode: 401 });
|
|
16
|
+
}
|
|
17
|
+
this.authInfo = authInfo;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
Auth = __decorate([
|
|
21
|
+
scoped(Lifecycle.ContainerScoped)
|
|
22
|
+
], Auth);
|
|
23
|
+
|
|
24
|
+
export { Auth };
|
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
getId() {
|
|
1
|
+
import { Storable } from '../storable/Storable.js';
|
|
2
|
+
|
|
3
|
+
class Entity extends Storable {
|
|
4
|
+
get id() {
|
|
7
5
|
if (!this.data.id) {
|
|
8
6
|
throw new Error('id is required');
|
|
9
7
|
}
|
|
10
8
|
return this.data.id;
|
|
11
9
|
}
|
|
12
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated use id
|
|
12
|
+
*/
|
|
13
|
+
getId() {
|
|
14
|
+
return this.id;
|
|
15
|
+
}
|
|
16
|
+
get createdAt() {
|
|
13
17
|
if (!this.data.createdAt) {
|
|
14
18
|
throw new Error('createdAt is required');
|
|
15
19
|
}
|
|
16
20
|
return new Date(this.data.createdAt);
|
|
17
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated use createdAt
|
|
24
|
+
*/
|
|
25
|
+
getCreatedAt() {
|
|
26
|
+
return this.createdAt;
|
|
27
|
+
}
|
|
18
28
|
update(newData) {
|
|
19
|
-
this.data = newData;
|
|
29
|
+
this.data = { ...this.data, ...newData, updatedAt: new Date().getTime() };
|
|
20
30
|
}
|
|
21
31
|
wasCreated() {
|
|
22
32
|
return !!this.data.createdAt || !!this.data.id;
|
|
@@ -33,5 +43,10 @@ class Persistent {
|
|
|
33
43
|
this.data.discardedAt = new Date().getTime();
|
|
34
44
|
}
|
|
35
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Should use Entity
|
|
48
|
+
*/
|
|
49
|
+
class Persistent extends Entity {
|
|
50
|
+
}
|
|
36
51
|
|
|
37
|
-
export { Persistent };
|
|
52
|
+
export { Entity, Persistent };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { singleton } from '../injection/index.js';
|
|
3
|
+
|
|
4
|
+
let Env = class Env {
|
|
5
|
+
envType;
|
|
6
|
+
constructor() {
|
|
7
|
+
this.envType = process.env.WABOT_ENV ?? 'development';
|
|
8
|
+
}
|
|
9
|
+
isDevelopment() {
|
|
10
|
+
return this.envType === 'development';
|
|
11
|
+
}
|
|
12
|
+
isProduction() {
|
|
13
|
+
return this.envType === 'production';
|
|
14
|
+
}
|
|
15
|
+
isTesting() {
|
|
16
|
+
return this.envType === 'testing';
|
|
17
|
+
}
|
|
18
|
+
requireString(varName, options) {
|
|
19
|
+
const value = process.env[varName] ?? options?.default;
|
|
20
|
+
if (!value)
|
|
21
|
+
throw new Error(`Env Variable ${varName} is required`);
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
requireNumber(varName, options) {
|
|
25
|
+
const strValue = this.requireString(varName, {
|
|
26
|
+
default: options?.default != null ? String(options.default) : undefined,
|
|
27
|
+
});
|
|
28
|
+
const value = Number(strValue);
|
|
29
|
+
if (isNaN(value))
|
|
30
|
+
throw new Error(`Env Variable ${varName} should have number format`);
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
Env = __decorate([
|
|
35
|
+
singleton(),
|
|
36
|
+
__metadata("design:paramtypes", [])
|
|
37
|
+
], Env);
|
|
38
|
+
|
|
39
|
+
export { Env };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class CustomError extends Error {
|
|
2
|
+
humanMessage;
|
|
3
|
+
code;
|
|
4
|
+
httpCode;
|
|
5
|
+
info;
|
|
6
|
+
constructor(data) {
|
|
7
|
+
super(data.message, { cause: data.cause });
|
|
8
|
+
this.humanMessage = data.humanMessage;
|
|
9
|
+
this.code = data.code;
|
|
10
|
+
this.httpCode = data.httpCode;
|
|
11
|
+
this.info = data.info;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { CustomError };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Storable } from '../storable/Storable.js';
|
|
2
|
+
import { CustomError } from '../error/CustomError.js';
|
|
3
|
+
import '../injection/index.js';
|
|
4
|
+
import '../validation/metadata/ValidationMetadataStore.js';
|
|
5
|
+
import { validate } from '../validation/validate.js';
|
|
6
|
+
|
|
7
|
+
function deepCopyWithStorable(obj) {
|
|
8
|
+
if (obj === null || typeof obj !== 'object') {
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
if (obj instanceof Date) {
|
|
12
|
+
return obj.getTime();
|
|
13
|
+
}
|
|
14
|
+
if (obj instanceof Storable) {
|
|
15
|
+
return deepCopyWithStorable(obj['data']);
|
|
16
|
+
}
|
|
17
|
+
if (Array.isArray(obj)) {
|
|
18
|
+
return obj.map((item) => deepCopyWithStorable(item));
|
|
19
|
+
}
|
|
20
|
+
const copy = {};
|
|
21
|
+
for (const key in obj) {
|
|
22
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
23
|
+
copy[key] = deepCopyWithStorable(obj[key]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return copy;
|
|
27
|
+
}
|
|
28
|
+
class Mapper {
|
|
29
|
+
map(data, ctor) {
|
|
30
|
+
const validationResult = validate(deepCopyWithStorable(data), ctor);
|
|
31
|
+
if (validationResult.error) {
|
|
32
|
+
throw new CustomError({
|
|
33
|
+
httpCode: 500,
|
|
34
|
+
message: `Cant map value to ${ctor.name}`,
|
|
35
|
+
info: validationResult.error,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return validationResult.value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { Mapper };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { randomBytes, scryptSync, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { Random } from '../random/Random.js';
|
|
3
|
+
|
|
4
|
+
class Password {
|
|
5
|
+
static hash(options) {
|
|
6
|
+
const { password: secret, saltLength = 16, keyLength = 64 } = options;
|
|
7
|
+
const salt = randomBytes(saltLength).toString('hex');
|
|
8
|
+
const derivedKey = scryptSync(secret, salt, keyLength);
|
|
9
|
+
return `${salt}:${derivedKey.toString('hex')}`;
|
|
10
|
+
}
|
|
11
|
+
static isValid(req) {
|
|
12
|
+
const [salt, storedKeyHex] = req.hash.split(':');
|
|
13
|
+
if (!salt || !storedKeyHex)
|
|
14
|
+
return false;
|
|
15
|
+
try {
|
|
16
|
+
const keyLength = Buffer.from(storedKeyHex, 'hex').length;
|
|
17
|
+
const derivedKey = scryptSync(req.password, salt, keyLength);
|
|
18
|
+
const storedKey = Buffer.from(storedKeyHex, 'hex');
|
|
19
|
+
return timingSafeEqual(derivedKey, storedKey);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
static generate(length) {
|
|
26
|
+
return Random.alphaNumeric(length);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { Password };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
const DIGITS = '0123456789';
|
|
4
|
+
const ALPHA_NUMERIC_CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
5
|
+
const ALPHA_NUMERIC_LOWER_CASE_CHARSET = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
6
|
+
class Random {
|
|
7
|
+
static slug(name, options) {
|
|
8
|
+
const base = name
|
|
9
|
+
.toLowerCase()
|
|
10
|
+
.trim()
|
|
11
|
+
.replace(/[\s\_]+/g, '-') // spaces/underscores to hyphens
|
|
12
|
+
.replace(/[^a-z0-9\-]/g, '') // remove non-alphanumeric except hyphens
|
|
13
|
+
.replace(/\-+/g, '-') // collapse multiple hyphens
|
|
14
|
+
.replace(/^\-+|\-+$/g, ''); // trim hyphens from ends
|
|
15
|
+
const random = this.alphaNumericLowerCase(options.randomLength);
|
|
16
|
+
return `${base}-${random}`;
|
|
17
|
+
}
|
|
18
|
+
static alphaNumeric(length) {
|
|
19
|
+
const bytes = randomBytes(length);
|
|
20
|
+
let result = '';
|
|
21
|
+
for (let i = 0; i < length; i++) {
|
|
22
|
+
const index = bytes[i] % ALPHA_NUMERIC_CHARSET.length;
|
|
23
|
+
result += ALPHA_NUMERIC_CHARSET[index];
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
static alphaNumericLowerCase(length) {
|
|
28
|
+
const bytes = randomBytes(length);
|
|
29
|
+
let result = '';
|
|
30
|
+
for (let i = 0; i < length; i++) {
|
|
31
|
+
const index = bytes[i] % ALPHA_NUMERIC_LOWER_CASE_CHARSET.length;
|
|
32
|
+
result += ALPHA_NUMERIC_LOWER_CASE_CHARSET[index];
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
static numberCode(length) {
|
|
37
|
+
const bytes = randomBytes(length);
|
|
38
|
+
let result = '';
|
|
39
|
+
for (let i = 0; i < length; i++) {
|
|
40
|
+
const index = bytes[i] % 10; // 0–9
|
|
41
|
+
result += DIGITS[index];
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { Random };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
function validateArray(value, options) {
|
|
2
|
+
if (!Array.isArray(value)) {
|
|
3
|
+
return {
|
|
4
|
+
error: { description: 'Should be an array', items: [] },
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
if (options?.minLength != null && value.length < options.minLength) {
|
|
8
|
+
return {
|
|
9
|
+
error: { description: 'exceeds the established min length limit', items: [] },
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (options?.maxLength != null && value.length > options.maxLength) {
|
|
13
|
+
return {
|
|
14
|
+
error: { description: 'exceeds the established max length limit', items: [] },
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const { itemsValidator } = options ?? {};
|
|
18
|
+
const valueOut = [];
|
|
19
|
+
const errorItems = [];
|
|
20
|
+
for (const item of value) {
|
|
21
|
+
let itemOut = item;
|
|
22
|
+
const itemErrors = [];
|
|
23
|
+
for (const itemValidator of itemsValidator ?? []) {
|
|
24
|
+
const { error, value } = itemValidator.validator(itemOut, itemValidator.options);
|
|
25
|
+
if (error) {
|
|
26
|
+
itemErrors.push(error);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
itemOut = value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (itemErrors.length == 0) {
|
|
33
|
+
valueOut.push(itemOut);
|
|
34
|
+
errorItems.push(null);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
valueOut.push(null);
|
|
38
|
+
errorItems.push(itemErrors);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (errorItems.some((x) => x != null)) {
|
|
42
|
+
return {
|
|
43
|
+
error: { description: 'Error on some items', items: errorItems },
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
value: valueOut,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { validateArray };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
function validateModel(value, info) {
|
|
2
|
+
if (typeof value !== 'object' || value === null) {
|
|
3
|
+
return { error: { description: 'Invalid object', properties: {} } };
|
|
4
|
+
}
|
|
5
|
+
let propertiesErrors = {};
|
|
6
|
+
let resultValue = new info.modelConstructor();
|
|
7
|
+
for (const propertyName in info.properties) {
|
|
8
|
+
const propertyInfo = info.properties[propertyName];
|
|
9
|
+
const propertyValidators = propertyInfo.validators ?? [];
|
|
10
|
+
resultValue[propertyName] = propertyInfo.isOptional
|
|
11
|
+
? (value[propertyName] ?? resultValue[propertyName])
|
|
12
|
+
: value[propertyName];
|
|
13
|
+
if (resultValue[propertyName] == null && propertyInfo.isOptional) {
|
|
14
|
+
resultValue[propertyName] = undefined;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
for (let propertyValidatorInfo of propertyValidators) {
|
|
18
|
+
const propertyValidatorResult = propertyValidatorInfo.validator(resultValue[propertyName], propertyValidatorInfo.validatorOptions);
|
|
19
|
+
resultValue[propertyName] = propertyValidatorResult.value;
|
|
20
|
+
if (propertyValidatorResult.error) {
|
|
21
|
+
let propertyErrors = propertiesErrors[propertyName];
|
|
22
|
+
if (!propertyErrors) {
|
|
23
|
+
propertyErrors = [];
|
|
24
|
+
propertiesErrors[propertyName] = propertyErrors;
|
|
25
|
+
}
|
|
26
|
+
propertyErrors.push(propertyValidatorResult.error.description);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (Object.keys(propertiesErrors).length > 0) {
|
|
31
|
+
return { error: { description: 'Invalid properties', properties: propertiesErrors } };
|
|
32
|
+
}
|
|
33
|
+
return { value: resultValue };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { validateModel };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { validateArray } from '../core/validateArray.js';
|
|
3
|
+
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
4
|
+
|
|
5
|
+
function isArray(options) {
|
|
6
|
+
return function (target, propertyKey) {
|
|
7
|
+
const propertyName = propertyKey.toString();
|
|
8
|
+
const store = container.resolve(ValidationMetadataStore);
|
|
9
|
+
store.saveValidatorMetadata({
|
|
10
|
+
modelConstructor: target.constructor,
|
|
11
|
+
propertyName,
|
|
12
|
+
validator: validateArray,
|
|
13
|
+
validatorOptions: options,
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { isArray };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { validateModel } from '../core/validateModel.js';
|
|
3
|
+
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
4
|
+
|
|
5
|
+
function isModel(model) {
|
|
6
|
+
return function (target, propertyKey) {
|
|
7
|
+
const propertyName = propertyKey.toString();
|
|
8
|
+
const store = container.resolve(ValidationMetadataStore);
|
|
9
|
+
store.saveValidatorMetadata({
|
|
10
|
+
modelConstructor: target.constructor,
|
|
11
|
+
propertyName,
|
|
12
|
+
validator: validateModel,
|
|
13
|
+
validatorOptions: store.getModelValidatorsInfo(model),
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { isModel };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
3
|
+
import { _IS_OPTIONAL_DUMMY_VALIDATOR_ } from '../core/validateIsOptional.js';
|
|
4
|
+
|
|
5
|
+
function isOptional() {
|
|
6
|
+
return function (target, propertyKey) {
|
|
7
|
+
const propertyName = propertyKey.toString();
|
|
8
|
+
const store = container.resolve(ValidationMetadataStore);
|
|
9
|
+
store.saveValidatorMetadata({
|
|
10
|
+
modelConstructor: target.constructor,
|
|
11
|
+
propertyName,
|
|
12
|
+
validator: _IS_OPTIONAL_DUMMY_VALIDATOR_,
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { isOptional };
|