@wabot-dev/framework 0.1.0-beta.7 → 0.1.0-beta.71
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/@apiKeyConnectionGuard.js +16 -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/ApiKeyConnectionGuardMiddleware.js +54 -0
- package/dist/src/addon/auth/api-key/ApiKeyGuardMiddleware.js +45 -0
- package/dist/src/addon/auth/api-key/ApiKeyRepository.js +35 -0
- package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +28 -0
- package/dist/src/addon/auth/api-key/RemoteApiKeyRepository.js +42 -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 +128 -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 +24 -0
- package/dist/src/addon/chat-controller/cmd/CmdChannel.js +91 -0
- package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +10 -4
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +9 -23
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
- package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +10 -4
- package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
- package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +26 -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 +15 -39
- 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 +27 -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 +61 -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 -12
- 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 +65 -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/{validation/metadata/@isBoolean.js → core/validation/metadata/@isArray.js} +5 -4
- package/dist/src/{validation/metadata/@isDate.js → core/validation/metadata/@isModel.js} +5 -4
- package/dist/src/{validation → core/validation}/metadata/@isOptional.js +2 -4
- package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
- package/dist/src/core/validation/modelInfo.js +9 -0
- package/dist/src/{validation/validateModel2.js → core/validation/validate.js} +3 -3
- package/dist/src/core/validation/validators/is-boolean/@isBoolean.js +17 -0
- package/dist/src/core/validation/validators/is-date/@isDate.js +17 -0
- package/dist/src/core/validation/validators/is-in/@isIn.js +18 -0
- package/dist/src/core/validation/validators/is-in/validateIsIn.js +12 -0
- package/dist/src/{validation/metadata → core/validation/validators/is-not-empty}/@isNotEmpty.js +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/is-number}/@isNumber.js +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/is-present}/@isPresent.js +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/is-string}/@isString.js +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/max}/@max.js +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/min}/@min.js +3 -3
- 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 +27 -0
- package/dist/src/feature/async/JobRepository.js +31 -0
- package/dist/src/feature/async/JobRunner.js +48 -0
- package/dist/src/feature/async/JobsEventsHub.js +36 -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 +83 -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 +6 -0
- package/dist/src/feature/mindset/MindsetOperator.js +180 -0
- 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 +30 -9
- 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/@middleware.js +16 -0
- package/dist/src/feature/rest-controller/metadata/@onDelete.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@onGet.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@onPost.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@onPut.js +7 -0
- package/dist/src/{rest-controller → feature/rest-controller}/metadata/@restController.js +2 -2
- package/dist/src/{rest-controller → feature/rest-controller}/metadata/RestControllerMetadataStore.js +14 -1
- package/dist/src/{rest-controller/metadata/@get.js → feature/rest-controller/metadata/methodDecorator.js} +5 -5
- package/dist/src/feature/rest-controller/runRestControllers.js +103 -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 +99 -0
- package/dist/src/index.d.ts +1219 -710
- package/dist/src/index.js +147 -100
- package/package.json +10 -2
- package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -107
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -88
- package/dist/src/channels/cmd/@cmd.js +0 -18
- package/dist/src/channels/cmd/CmdChannel.js +0 -73
- 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/MindsetOperator.js +0 -101
- 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/rest-controller/runRestControllers.js +0 -75
- 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/validation/metadata/@validable.js +0 -14
- package/dist/src/validation/metadata/ValidationMetadataStore.js +0 -55
- package/dist/src/validation/validators/validateModel.js +0 -47
- /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/{validation/validators → core/validation/validators/is-boolean}/validateIsBoolean.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-date}/validateIsDate.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-not-empty}/validateIsNotEmpty.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-number}/validateIsNumber.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-present}/validateIsPresent.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-string}/validateIsString.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/max}/validateMax.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/min}/validateMin.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,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 };
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import '../injection/index.js';
|
|
2
|
-
import { RestControllerMetadataStore } from './metadata/RestControllerMetadataStore.js';
|
|
3
|
-
import '../controller/channel/ChatResolver.js';
|
|
4
|
-
import '../controller/channel/UserResolver.js';
|
|
5
|
-
import '../controller/metadata/ControllerMetadataStore.js';
|
|
6
|
-
import '../channels/cmd/CmdChannel.js';
|
|
7
|
-
import { ExpressProvider } from '../channels/express/ExpressProvider.js';
|
|
8
|
-
import '../channels/http/HttpServerProvider.js';
|
|
9
|
-
import '../channels/socket/SocketChannel.js';
|
|
10
|
-
import '../channels/socket/SocketChannelConfig.js';
|
|
11
|
-
import '../channels/socket/SocketServerProvider.js';
|
|
12
|
-
import '../channels/telegram/TelegramChannel.js';
|
|
13
|
-
import '../channels/whatsapp/WhatsAppChannel.js';
|
|
14
|
-
import '../core/chat/repository/IChatRepository.js';
|
|
15
|
-
import '../core/user/IUserRepository.js';
|
|
16
|
-
import '../channels/whatsapp/WhatsAppReceiverByDevConnection.js';
|
|
17
|
-
import '../channels/whatsapp/WhatsAppReceiverByWebHook.js';
|
|
18
|
-
import '../channels/whatsapp/WhatsAppSenderByDevConnection.js';
|
|
19
|
-
import '../channels/whatsapp/WhatsAppSenderByCloudApi.js';
|
|
20
|
-
import '../channels/whatsapp/PgWhatsAppRepository.js';
|
|
21
|
-
import '../channels/whatsapp/EnvWhatsAppRepository.js';
|
|
22
|
-
import path from 'path';
|
|
23
|
-
import { Logger } from '../logger/Logger.js';
|
|
24
|
-
|
|
25
|
-
function buildRequest(req) {
|
|
26
|
-
return Object.assign({}, req.body, req.query, req.params);
|
|
27
|
-
}
|
|
28
|
-
function runRestControllers(controllers, container) {
|
|
29
|
-
const logger = new Logger('wabot:rest');
|
|
30
|
-
const metadataStore = container.resolve(RestControllerMetadataStore);
|
|
31
|
-
const expressProvider = container.resolve(ExpressProvider);
|
|
32
|
-
const expressApp = expressProvider.getExpress();
|
|
33
|
-
controllers.forEach((controller) => {
|
|
34
|
-
const endPoints = metadataStore.getControllerEndPointsInfo(controller);
|
|
35
|
-
endPoints.forEach((endPoint) => {
|
|
36
|
-
debugger;
|
|
37
|
-
const method = endPoint.method;
|
|
38
|
-
const route = path.join(endPoint.controller.path, endPoint.path ?? '');
|
|
39
|
-
logger.info(`config ${endPoint.method.toUpperCase()} ${route}`);
|
|
40
|
-
expressApp[method](route, async (req, res) => {
|
|
41
|
-
const requestContainer = container.createChildContainer();
|
|
42
|
-
const controllerInstance = requestContainer.resolve(endPoint.controllerConstructor);
|
|
43
|
-
const endPointArgs = [];
|
|
44
|
-
let defaultArgFound = false;
|
|
45
|
-
for (let paramIndex = 0; paramIndex < endPoint.paramsTypes.length; paramIndex++) {
|
|
46
|
-
const paramType = endPoint.paramsTypes[paramIndex];
|
|
47
|
-
if (defaultArgFound) {
|
|
48
|
-
throw new Error(`Cant determine de parameter ${paramIndex} value`);
|
|
49
|
-
}
|
|
50
|
-
defaultArgFound = true;
|
|
51
|
-
if (typeof paramType === 'function' && typeof paramType.__validate__ === 'function') {
|
|
52
|
-
const { value, error } = paramType.__validate__(buildRequest(req));
|
|
53
|
-
debugger;
|
|
54
|
-
if (error) {
|
|
55
|
-
res.status(400).json({ error });
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
endPointArgs.push(value);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
try {
|
|
62
|
-
const response = await controllerInstance[endPoint.functionName].apply(controllerInstance, endPointArgs);
|
|
63
|
-
res.status(200).json(response);
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
res.sendStatus(500);
|
|
67
|
-
}
|
|
68
|
-
requestContainer.dispose();
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
expressProvider.listen();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export { runRestControllers };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import '../injection/index.js';
|
|
2
|
-
import 'reflect-metadata';
|
|
3
|
-
import '../mindset/metadata/MindsetMetadataStore.js';
|
|
4
|
-
import { Mindset } from '../mindset/IMindset.js';
|
|
5
|
-
import '../mindset/MindsetOperator.js';
|
|
6
|
-
import { ChatMemory } from '../core/chat/repository/IChatMemory.js';
|
|
7
|
-
import { ChatRepository } from '../core/chat/repository/IChatRepository.js';
|
|
8
|
-
import '../core/user/IUserRepository.js';
|
|
9
|
-
import { MessageContext } from '../core/IMessageContext.js';
|
|
10
|
-
import 'uuid';
|
|
11
|
-
import { ChatBotMetadataStore } from '../chatbot/metadata/ChatBotMetadataStore.js';
|
|
12
|
-
import { ChatBot } from '../chatbot/ChatBot.js';
|
|
13
|
-
import { Container } from '../injection/Container.js';
|
|
14
|
-
|
|
15
|
-
async function prepareChatContainer(container, context, mindsetCtor) {
|
|
16
|
-
const chatContainer = container.createChildContainer();
|
|
17
|
-
chatContainer.register(Container, { useValue: chatContainer });
|
|
18
|
-
chatContainer.register(MessageContext, {
|
|
19
|
-
useValue: new MessageContext(context.message, context.chat, context.user),
|
|
20
|
-
});
|
|
21
|
-
const chatRepository = container.resolve(ChatRepository);
|
|
22
|
-
const chatMemory = await chatRepository.findMemory(context.chat.getId());
|
|
23
|
-
if (!chatMemory) {
|
|
24
|
-
throw new Error('Not found Chat Memory for Chat with Id=' + context.chat.getId());
|
|
25
|
-
}
|
|
26
|
-
chatContainer.register(ChatMemory, { useValue: chatMemory });
|
|
27
|
-
const chatBotMetadataStore = container.resolve(ChatBotMetadataStore);
|
|
28
|
-
const chatBots = chatBotMetadataStore.getChatBotsMetadata();
|
|
29
|
-
for (const chatBotMetadata of chatBots) {
|
|
30
|
-
chatContainer.beforeResolution(chatBotMetadata.constructor, (a, b) => {
|
|
31
|
-
const subContainer = chatContainer.createChildContainer();
|
|
32
|
-
subContainer.register(Mindset, { useClass: chatBotMetadata.mindsetConstructor });
|
|
33
|
-
const chatBot = subContainer.resolve(ChatBot);
|
|
34
|
-
chatContainer.register(chatBotMetadata.injectionToken, { useValue: chatBot });
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
if (mindsetCtor) {
|
|
38
|
-
chatContainer.register(Mindset, { useClass: mindsetCtor });
|
|
39
|
-
}
|
|
40
|
-
return chatContainer;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { prepareChatContainer };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { container } from '../injection/index.js';
|
|
2
|
-
import 'uuid';
|
|
3
|
-
import '../chatbot/metadata/ChatBotMetadataStore.js';
|
|
4
|
-
import { ChatBot } from '../chatbot/ChatBot.js';
|
|
5
|
-
import { ChatBotAdapter } from '../chatbot/ChatBotAdapter.js';
|
|
6
|
-
import { ChatRepository } from '../core/chat/repository/IChatRepository.js';
|
|
7
|
-
import '../core/user/IUserRepository.js';
|
|
8
|
-
import { prepareChatContainer } from './prepareChatContainer.js';
|
|
9
|
-
|
|
10
|
-
function runChannel(props) {
|
|
11
|
-
container.registerSingleton(ChatRepository, props.chatRepository);
|
|
12
|
-
container.register(ChatBotAdapter, { useClass: props.chatBotAdapter });
|
|
13
|
-
if (props.channelConfig) {
|
|
14
|
-
container.register(props.channelConfig.constructor, { useValue: props.channelConfig });
|
|
15
|
-
}
|
|
16
|
-
const channel = container.resolve(props.channel);
|
|
17
|
-
channel.listen(async (context) => {
|
|
18
|
-
const channelContainer = await prepareChatContainer(container, context, props.mindset);
|
|
19
|
-
const chatBot = channelContainer.resolve(ChatBot);
|
|
20
|
-
chatBot.sendMessage(context.message, (replyMessage) => {
|
|
21
|
-
context.reply(replyMessage);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
channel.connect();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { runChannel };
|
|
@@ -1,40 +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 { prepareChatContainer } from './prepareChatContainer.js';
|
|
6
|
-
|
|
7
|
-
function runServer(config) {
|
|
8
|
-
for (const provider of config.providers ?? []) {
|
|
9
|
-
if (provider.singleton) {
|
|
10
|
-
container.registerSingleton(provider.replace, provider.with);
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
container.register(provider.replace, provider.with);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
const metadataStore = container.resolve(ControllerMetadataStore);
|
|
17
|
-
for (const controllerCtor of config.controllers) {
|
|
18
|
-
const chatControllerMetadata = metadataStore.getChatControllerMetadata(controllerCtor);
|
|
19
|
-
if (!chatControllerMetadata) {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
for (const channelMetadata of chatControllerMetadata.channels) {
|
|
23
|
-
const channelContainer = container.createChildContainer();
|
|
24
|
-
if (channelMetadata.channelConfig) {
|
|
25
|
-
channelContainer.register(channelMetadata.channelConfig.constructor, {
|
|
26
|
-
useValue: channelMetadata.channelConfig,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
const channel = channelContainer.resolve(channelMetadata.channelConstructor);
|
|
30
|
-
channel.listen(async (messageContext) => {
|
|
31
|
-
const chatContainer = await prepareChatContainer(channelContainer, messageContext);
|
|
32
|
-
const chatController = chatContainer.resolve(channelMetadata.controllerConstructor);
|
|
33
|
-
chatController[channelMetadata.functionName](messageContext);
|
|
34
|
-
});
|
|
35
|
-
channel.connect();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export { runServer };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { container } from 'tsyringe';
|
|
2
|
-
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
3
|
-
import { validateModel } from '../validators/validateModel.js';
|
|
4
|
-
|
|
5
|
-
function validable() {
|
|
6
|
-
return function (target) {
|
|
7
|
-
target.__validate__ = function (value) {
|
|
8
|
-
const info = container.resolve(ValidationMetadataStore).getModelValidatorsInfo(target);
|
|
9
|
-
return validateModel(value, info);
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { validable };
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { __decorate } from 'tslib';
|
|
2
|
-
import { singleton } from '../../injection/index.js';
|
|
3
|
-
import { _IS_OPTIONAL_DUMMY_VALIDATOR_ } from './@isOptional.js';
|
|
4
|
-
|
|
5
|
-
let ValidationMetadataStore = class ValidationMetadataStore {
|
|
6
|
-
validators = new Map();
|
|
7
|
-
saveValidatorMetadata(validatorMetadata) {
|
|
8
|
-
let modelValidators = this.validators.get(validatorMetadata.modelConstructor);
|
|
9
|
-
if (!modelValidators) {
|
|
10
|
-
this.validators.set(validatorMetadata.modelConstructor, (modelValidators = new Map()));
|
|
11
|
-
}
|
|
12
|
-
let propertyValidators = modelValidators.get(validatorMetadata.propertyName);
|
|
13
|
-
if (!propertyValidators) {
|
|
14
|
-
propertyValidators = [];
|
|
15
|
-
modelValidators.set(validatorMetadata.propertyName, propertyValidators);
|
|
16
|
-
}
|
|
17
|
-
propertyValidators.unshift(validatorMetadata);
|
|
18
|
-
}
|
|
19
|
-
getModelValidatorsInfo(modelConstructor) {
|
|
20
|
-
const modelValidators = {
|
|
21
|
-
modelConstructor: modelConstructor,
|
|
22
|
-
properties: {},
|
|
23
|
-
};
|
|
24
|
-
[...(this.validators.get(modelConstructor)?.values() ?? [])].forEach((propertyValidatorsMetadata) => {
|
|
25
|
-
const propertyName = propertyValidatorsMetadata.at(0)?.propertyName;
|
|
26
|
-
if (!propertyName) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
let propertyInfo = modelValidators.properties[propertyName];
|
|
30
|
-
if (!propertyInfo) {
|
|
31
|
-
propertyInfo = {};
|
|
32
|
-
modelValidators.properties[propertyName] = propertyInfo;
|
|
33
|
-
}
|
|
34
|
-
let validators = propertyInfo.validators;
|
|
35
|
-
if (!validators) {
|
|
36
|
-
validators = [];
|
|
37
|
-
propertyInfo.validators = validators;
|
|
38
|
-
}
|
|
39
|
-
propertyValidatorsMetadata.forEach((propertyValidatorMetadata) => {
|
|
40
|
-
if (propertyValidatorMetadata.validator === _IS_OPTIONAL_DUMMY_VALIDATOR_) {
|
|
41
|
-
propertyInfo.isOptional = true;
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
validators.push(propertyValidatorMetadata);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
return modelValidators;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
ValidationMetadataStore = __decorate([
|
|
52
|
-
singleton()
|
|
53
|
-
], ValidationMetadataStore);
|
|
54
|
-
|
|
55
|
-
export { ValidationMetadataStore };
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
function validateModel(value, info) {
|
|
2
|
-
const result = {};
|
|
3
|
-
if (typeof value !== 'object') {
|
|
4
|
-
result.error = {
|
|
5
|
-
model: [
|
|
6
|
-
{
|
|
7
|
-
description: `the value should be an object`,
|
|
8
|
-
},
|
|
9
|
-
],
|
|
10
|
-
properties: [],
|
|
11
|
-
};
|
|
12
|
-
return result;
|
|
13
|
-
}
|
|
14
|
-
const validatedValue = new info.modelConstructor();
|
|
15
|
-
for (const propertyName in info.properties) {
|
|
16
|
-
const propertyInfo = info.properties[propertyName];
|
|
17
|
-
const propertyValidators = propertyInfo.validators ?? [];
|
|
18
|
-
validatedValue[propertyName] = value[propertyName] ?? validatedValue[propertyName];
|
|
19
|
-
if (validatedValue[propertyName] == null && propertyInfo.isOptional) {
|
|
20
|
-
validatedValue[propertyName] = null;
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
for (let propertyValidatorInfo of propertyValidators) {
|
|
24
|
-
const propertyValidatorResult = propertyValidatorInfo.validator(validatedValue[propertyName], propertyValidatorInfo.validatorOptions);
|
|
25
|
-
validatedValue[propertyName] = propertyValidatorResult.value;
|
|
26
|
-
if (propertyValidatorResult.error) {
|
|
27
|
-
let resultError = result.error;
|
|
28
|
-
if (!resultError) {
|
|
29
|
-
resultError = { model: [], properties: [] };
|
|
30
|
-
result.error = resultError;
|
|
31
|
-
}
|
|
32
|
-
let propertyErrors = resultError.properties.find((x) => x.name === propertyName);
|
|
33
|
-
if (!propertyErrors) {
|
|
34
|
-
propertyErrors = { name: propertyName, errors: [] };
|
|
35
|
-
resultError.properties.push(propertyErrors);
|
|
36
|
-
}
|
|
37
|
-
propertyErrors.errors.push(propertyValidatorResult.error);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (!result.error) {
|
|
42
|
-
result.value = validatedValue;
|
|
43
|
-
}
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export { validateModel };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/src/{validation/validators → core/validation/validators/is-date}/validateIsDate.js
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/src/{validation/validators → core/validation/validators/is-number}/validateIsNumber.js
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/src/{validation/validators → core/validation/validators/is-string}/validateIsString.js
RENAMED
|
File without changes
|