@wabot-dev/framework 0.1.0-beta.3 → 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.
Files changed (149) hide show
  1. package/dist/src/addon/async/pg/PgJobRepository.js +26 -0
  2. package/dist/src/addon/chat-bot/claude/ClaudeChatBotAdapter.js +107 -0
  3. package/dist/src/addon/chat-bot/deepseek/DeepSeekChatBotAdapter.js +103 -0
  4. package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +101 -0
  5. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +5 -4
  6. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +5 -5
  7. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
  8. package/dist/src/addon/chat-controller/cmd/@cmd.js +22 -0
  9. package/dist/src/{channels → addon/chat-controller}/cmd/CmdChannel.js +4 -26
  10. package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +8 -4
  11. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +5 -23
  12. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
  13. package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +8 -4
  14. package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
  15. package/dist/src/{channels → addon/chat-controller}/whatsapp/@whatsapp.js +8 -4
  16. package/dist/src/addon/chat-controller/whatsapp/EnvWhatsAppRepository.js +49 -0
  17. package/dist/src/{channels/whatsapp/WhatsAppRepository.js → addon/chat-controller/whatsapp/PgWhatsAppRepository.js} +5 -5
  18. package/dist/src/{channels/wabot → addon/chat-controller/whatsapp}/WabotDevConnection.js +2 -2
  19. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +5 -4
  20. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
  21. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiver.js +4 -7
  22. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiverByDevConnection.js +3 -9
  23. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiverByWebHook.js +2 -9
  24. package/dist/src/{core/chat/repository/IChatMemory.js → addon/chat-controller/whatsapp/WhatsAppRepository.js} +4 -4
  25. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +39 -10
  26. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSenderByCloudApi.js +10 -13
  27. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSenderByDevConnection.js +13 -15
  28. package/dist/src/addon/mindset/html/HtmlModule.js +70 -0
  29. package/dist/src/{repository → addon/repository}/pg/PgCrudRepository.js +23 -2
  30. package/dist/src/{repository → addon/repository}/pg/PgRepositoryBase.js +2 -2
  31. package/dist/src/addon/rest-controller/jwt/@jwtGuard.js +17 -0
  32. package/dist/src/addon/rest-controller/jwt/Jwt.js +36 -0
  33. package/dist/src/addon/rest-controller/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
  34. package/dist/src/addon/rest-controller/jwt/JwtConfig.js +28 -0
  35. package/dist/src/addon/rest-controller/jwt/JwtGuardMiddleware.js +50 -0
  36. package/dist/src/addon/rest-controller/jwt/JwtRefreshToken.js +9 -0
  37. package/dist/src/addon/rest-controller/jwt/JwtRefreshTokenRepository.js +21 -0
  38. package/dist/src/addon/rest-controller/jwt/JwtSigner.js +48 -0
  39. package/dist/src/addon/rest-controller/jwt/JwtTokenDto.js +22 -0
  40. package/dist/src/addon/validation/is-boolean/@isBoolean.js +17 -0
  41. package/dist/src/addon/validation/is-boolean/validateIsBoolean.js +12 -0
  42. package/dist/src/addon/validation/is-date/@isDate.js +17 -0
  43. package/dist/src/addon/validation/is-date/validateIsDate.js +16 -0
  44. package/dist/src/addon/validation/is-not-empty/@isNotEmpty.js +17 -0
  45. package/dist/src/addon/validation/is-not-empty/validateIsNotEmpty.js +12 -0
  46. package/dist/src/addon/validation/is-number/@isNumber.js +17 -0
  47. package/dist/src/addon/validation/is-number/validateIsNumber.js +12 -0
  48. package/dist/src/addon/validation/is-present/@isPresent.js +17 -0
  49. package/dist/src/addon/validation/is-present/validateIsPresent.js +12 -0
  50. package/dist/src/addon/validation/is-string/@isString.js +17 -0
  51. package/dist/src/addon/validation/is-string/validateIsString.js +12 -0
  52. package/dist/src/addon/validation/max/@max.js +18 -0
  53. package/dist/src/addon/validation/max/validateMax.js +17 -0
  54. package/dist/src/addon/validation/min/@min.js +18 -0
  55. package/dist/src/addon/validation/min/validateMin.js +17 -0
  56. package/dist/src/core/{Persistent.js → entity/Entity.js} +24 -9
  57. package/dist/src/core/env/Env.js +39 -0
  58. package/dist/src/core/error/CustomError.js +15 -0
  59. package/dist/src/core/injection/index.js +4 -0
  60. package/dist/src/core/mapper/Mapper.js +42 -0
  61. package/dist/src/core/random/Random.js +37 -0
  62. package/dist/src/core/storable/Storable.js +8 -0
  63. package/dist/src/core/validation/metadata/@isArray.js +18 -0
  64. package/dist/src/core/validation/metadata/@isModel.js +18 -0
  65. package/dist/src/core/validation/metadata/@isOptional.js +17 -0
  66. package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
  67. package/dist/src/core/validation/modelInfo.js +9 -0
  68. package/dist/src/core/validation/validate.js +11 -0
  69. package/dist/src/core/validation/validators/validateArray.js +41 -0
  70. package/dist/src/core/validation/validators/validateIsOptional.js +5 -0
  71. package/dist/src/core/validation/validators/validateModel.js +34 -0
  72. package/dist/src/feature/async/@command.js +11 -0
  73. package/dist/src/feature/async/@commandHandler.js +12 -0
  74. package/dist/src/feature/async/Async.js +38 -0
  75. package/dist/src/feature/async/Command.js +9 -0
  76. package/dist/src/feature/async/CommandMetadataStore.js +38 -0
  77. package/dist/src/feature/async/Job.js +24 -0
  78. package/dist/src/feature/async/JobRepository.js +31 -0
  79. package/dist/src/feature/async/JobRunner.js +45 -0
  80. package/dist/src/feature/async/JobsEventsHub.js +24 -0
  81. package/dist/src/feature/async/runCommandHandlers.js +29 -0
  82. package/dist/src/{core/chat → feature/chat-bot}/Chat.js +2 -2
  83. package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
  84. package/dist/src/feature/chat-bot/ChatBot.js +50 -0
  85. package/dist/src/feature/chat-bot/ChatItem.js +24 -0
  86. package/dist/src/feature/chat-bot/ChatMemory.js +10 -0
  87. package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js} +2 -8
  88. package/dist/src/feature/chat-bot/IChatItem.js +3 -0
  89. package/dist/src/{chatbot → feature/chat-bot}/metadata/@chatBot.js +1 -1
  90. package/dist/src/{chatbot → feature/chat-bot}/metadata/ChatBotMetadataStore.js +1 -1
  91. package/dist/src/{controller/channel → feature/chat-controller}/ChatResolver.js +5 -4
  92. package/dist/src/{controller → feature/chat-controller}/metadata/ControllerMetadataStore.js +1 -1
  93. package/dist/src/{controller → feature/chat-controller}/metadata/controller/@chatController.js +1 -1
  94. package/dist/src/feature/chat-controller/runChatControllers.js +69 -0
  95. package/dist/src/{channels → feature}/express/ExpressProvider.js +1 -1
  96. package/dist/src/{channels → feature}/http/HttpServerProvider.js +1 -1
  97. package/dist/src/{mindset → feature/mindset}/MindsetOperator.js +66 -42
  98. package/dist/src/{mindset → feature/mindset}/metadata/MindsetMetadataStore.js +1 -1
  99. package/dist/src/{mindset → feature/mindset}/metadata/functions/@mindsetFunction.js +1 -1
  100. package/dist/src/{mindset → feature/mindset}/metadata/mindsets/@mindset.js +1 -1
  101. package/dist/src/{mindset → feature/mindset}/metadata/modules/@mindsetModule.js +1 -2
  102. package/dist/src/{mindset → feature/mindset}/metadata/params/@param.js +1 -1
  103. package/dist/src/feature/rest-controller/auth/Auth.js +24 -0
  104. package/dist/src/feature/rest-controller/metadata/@get.js +19 -0
  105. package/dist/src/feature/rest-controller/metadata/@middleware.js +16 -0
  106. package/dist/src/feature/rest-controller/metadata/@post.js +19 -0
  107. package/dist/src/feature/rest-controller/metadata/@restController.js +15 -0
  108. package/dist/src/feature/rest-controller/metadata/RestControllerMetadataStore.js +50 -0
  109. package/dist/src/feature/rest-controller/runRestControllers.js +75 -0
  110. package/dist/src/{channels → feature}/socket/SocketServerProvider.js +1 -1
  111. package/dist/src/index.d.ts +785 -475
  112. package/dist/src/index.js +118 -74
  113. package/package.json +6 -3
  114. package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -106
  115. package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -84
  116. package/dist/src/channels/cmd/@cmd.js +0 -18
  117. package/dist/src/chatbot/ChatBot.js +0 -51
  118. package/dist/src/chatbot/ChatBotAdapter.js +0 -72
  119. package/dist/src/controller/channel/UserResolver.js +0 -21
  120. package/dist/src/core/IMessageContext.js +0 -12
  121. package/dist/src/core/chat/ChatItem.js +0 -15
  122. package/dist/src/core/user/IUserRepository.js +0 -19
  123. package/dist/src/core/user/User.js +0 -26
  124. package/dist/src/env/WabotEnv.js +0 -21
  125. package/dist/src/injection/index.js +0 -4
  126. package/dist/src/mindset/metadata/params/@isOptional.js +0 -21
  127. package/dist/src/pre-made/module/authentication/AuthenticationModule.js +0 -97
  128. package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -25
  129. package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -25
  130. package/dist/src/pre-made/module/register-user/RegisterUserModule.js +0 -56
  131. package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -25
  132. package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -33
  133. package/dist/src/pre-made/repository/user/ram/RamUserRepository.js +0 -27
  134. package/dist/src/pre-made/service/EmailService.js +0 -13
  135. package/dist/src/pre-made/service/OtpService.js +0 -14
  136. package/dist/src/server/prepareChatContainer.js +0 -43
  137. package/dist/src/server/runChannel.js +0 -27
  138. package/dist/src/server/runServer.js +0 -40
  139. /package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatMemory.js +0 -0
  140. /package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannelConfig.js +0 -0
  141. /package/dist/src/{channels/wabot → addon/chat-controller/whatsapp}/WabotDevSocketContracts.js +0 -0
  142. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
  143. /package/dist/src/{injection → core/injection}/Container.js +0 -0
  144. /package/dist/src/{logger → core/logger}/Logger.js +0 -0
  145. /package/dist/src/{mindset → feature/mindset}/IMindset.js +0 -0
  146. /package/dist/src/{mindset → feature/mindset}/metadata/functions/decoratorNames.js +0 -0
  147. /package/dist/src/{mindset → feature/mindset}/metadata/mindsets/decoratorNames.js +0 -0
  148. /package/dist/src/{mindset → feature/mindset}/metadata/modules/decoratorNames.js +0 -0
  149. /package/dist/src/{mindset → feature/mindset}/metadata/params/decoratorNames.js +0 -0
@@ -0,0 +1,50 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { CustomError } from '../../../core/error/CustomError.js';
3
+ import { injectable } from '../../../core/injection/index.js';
4
+ import '../../../feature/rest-controller/metadata/RestControllerMetadataStore.js';
5
+ import 'path';
6
+ import 'debug';
7
+ import '../../../feature/express/ExpressProvider.js';
8
+ import '../../../core/validation/metadata/ValidationMetadataStore.js';
9
+ import { Auth } from '../../../feature/rest-controller/auth/Auth.js';
10
+ import jwt from 'jsonwebtoken';
11
+ import { JwtConfig } from './JwtConfig.js';
12
+
13
+ let JwtGuardMiddleware = class JwtGuardMiddleware {
14
+ config;
15
+ auth;
16
+ constructor(config, auth) {
17
+ this.config = config;
18
+ this.auth = auth;
19
+ }
20
+ async handle(req, res, container) {
21
+ const authorization = req.header('Authorization');
22
+ if (!authorization) {
23
+ throw new CustomError({ httpCode: 401, message: 'Authorization header not available' });
24
+ }
25
+ const [bearer, token] = authorization.split(' ');
26
+ if (bearer.toLowerCase() !== 'bearer' || !token) {
27
+ throw new CustomError({ httpCode: 401, message: 'Authorization should be a bearer token' });
28
+ }
29
+ try {
30
+ const jwtPayload = jwt.verify(token, this.config.secretOrPublicKey, {
31
+ algorithms: [this.config.algorithm],
32
+ });
33
+ this.auth.assign(jwtPayload);
34
+ }
35
+ catch (err) {
36
+ throw new CustomError({
37
+ httpCode: 401,
38
+ message: err instanceof Error ? `Invalid token: ${err.message}` : 'Invalid token',
39
+ cause: err instanceof Error ? err : undefined,
40
+ });
41
+ }
42
+ }
43
+ };
44
+ JwtGuardMiddleware = __decorate([
45
+ injectable(),
46
+ __metadata("design:paramtypes", [JwtConfig,
47
+ Auth])
48
+ ], JwtGuardMiddleware);
49
+
50
+ export { JwtGuardMiddleware };
@@ -0,0 +1,9 @@
1
+ import { Entity } from '../../../core/entity/Entity.js';
2
+
3
+ class JwtRefreshToken extends Entity {
4
+ get authInfo() {
5
+ return this.data.authInfo;
6
+ }
7
+ }
8
+
9
+ export { JwtRefreshToken };
@@ -0,0 +1,21 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { singleton } from '../../../core/injection/index.js';
3
+ import { JwtRefreshToken } from './JwtRefreshToken.js';
4
+ import { Pool } from 'pg';
5
+ import { PgCrudRepository } from '../../repository/pg/PgCrudRepository.js';
6
+
7
+ let JwtRefreshTokenRepository = class JwtRefreshTokenRepository extends PgCrudRepository {
8
+ constructor(pool) {
9
+ super(pool, {
10
+ schema: 'wabot',
11
+ table: 'jwt_refresh_token',
12
+ constructor: JwtRefreshToken,
13
+ });
14
+ }
15
+ };
16
+ JwtRefreshTokenRepository = __decorate([
17
+ singleton(),
18
+ __metadata("design:paramtypes", [Pool])
19
+ ], JwtRefreshTokenRepository);
20
+
21
+ export { JwtRefreshTokenRepository };
@@ -0,0 +1,48 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { JwtConfig } from './JwtConfig.js';
3
+ import jwt from 'jsonwebtoken';
4
+ import { JwtTokenDto } from './JwtTokenDto.js';
5
+ import { JwtRefreshToken } from './JwtRefreshToken.js';
6
+ import { JwtAccessAndRefreshTokenDto } from './JwtAccessAndRefreshTokenDto.js';
7
+ import { injectable } from '../../../core/injection/index.js';
8
+ import { Mapper } from '../../../core/mapper/Mapper.js';
9
+
10
+ let JwtSigner = class JwtSigner {
11
+ config;
12
+ mapper;
13
+ constructor(config, mapper) {
14
+ this.config = config;
15
+ this.mapper = mapper;
16
+ }
17
+ async signAccessToken(info) {
18
+ const _authInfo = info instanceof JwtRefreshToken
19
+ ? {
20
+ ...info.authInfo,
21
+ refreshTokenId: info.id,
22
+ }
23
+ : info;
24
+ const token = jwt.sign(_authInfo, this.config.secretOrPrivateKey, {
25
+ expiresIn: this.config.accessExpirationSeconds,
26
+ });
27
+ const expiration = new Date().getTime() + this.config.accessExpirationSeconds * 1000;
28
+ return this.mapper.map({ token, expiration }, JwtTokenDto);
29
+ }
30
+ async signRefreshToken(refreshToken) {
31
+ const token = jwt.sign({ refreshTokenId: refreshToken.id }, this.config.secretOrPrivateKey, {
32
+ expiresIn: this.config.refreshExpirationSeconds,
33
+ });
34
+ const expiration = new Date().getTime() + this.config.refreshExpirationSeconds * 1000;
35
+ return this.mapper.map({ token, expiration }, JwtTokenDto);
36
+ }
37
+ async signAccessAndRefreshToken(refreshToken) {
38
+ const access = await this.signAccessToken(refreshToken);
39
+ const refresh = await this.signRefreshToken(refreshToken);
40
+ return this.mapper.map({ access, refresh }, JwtAccessAndRefreshTokenDto);
41
+ }
42
+ };
43
+ JwtSigner = __decorate([
44
+ injectable(),
45
+ __metadata("design:paramtypes", [JwtConfig, Mapper])
46
+ ], JwtSigner);
47
+
48
+ export { JwtSigner };
@@ -0,0 +1,22 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import '../../../core/injection/index.js';
3
+ import '../../../core/validation/metadata/ValidationMetadataStore.js';
4
+ import { isDate } from '../../validation/is-date/@isDate.js';
5
+ import { isNotEmpty } from '../../validation/is-not-empty/@isNotEmpty.js';
6
+ import { isString } from '../../validation/is-string/@isString.js';
7
+
8
+ class JwtTokenDto {
9
+ token;
10
+ expiration;
11
+ }
12
+ __decorate([
13
+ isString(),
14
+ isNotEmpty(),
15
+ __metadata("design:type", String)
16
+ ], JwtTokenDto.prototype, "token", void 0);
17
+ __decorate([
18
+ isDate(),
19
+ __metadata("design:type", Date)
20
+ ], JwtTokenDto.prototype, "expiration", void 0);
21
+
22
+ export { JwtTokenDto };
@@ -0,0 +1,17 @@
1
+ import { container } from '../../../core/injection/index.js';
2
+ import { ValidationMetadataStore } from '../../../core/validation/metadata/ValidationMetadataStore.js';
3
+ import { validateIsBoolean } from './validateIsBoolean.js';
4
+
5
+ function isBoolean() {
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: validateIsBoolean,
13
+ });
14
+ };
15
+ }
16
+
17
+ export { isBoolean };
@@ -0,0 +1,12 @@
1
+ function validateIsBoolean(value) {
2
+ if (typeof value !== 'boolean') {
3
+ return {
4
+ error: { description: `boolean value is required` },
5
+ };
6
+ }
7
+ return {
8
+ value,
9
+ };
10
+ }
11
+
12
+ export { validateIsBoolean };
@@ -0,0 +1,17 @@
1
+ import { container } from '../../../core/injection/index.js';
2
+ import { validateIsDate } from './validateIsDate.js';
3
+ import { ValidationMetadataStore } from '../../../core/validation/metadata/ValidationMetadataStore.js';
4
+
5
+ function isDate() {
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: validateIsDate,
13
+ });
14
+ };
15
+ }
16
+
17
+ export { isDate };
@@ -0,0 +1,16 @@
1
+ function validateIsDate(value) {
2
+ const _value = new Date(value);
3
+ const time = _value.getTime();
4
+ if ((typeof value !== 'number' && typeof value !== 'string' && !(value instanceof Date)) ||
5
+ isNaN(time) ||
6
+ time < 0) {
7
+ return {
8
+ error: { description: `Date value is not valid` },
9
+ };
10
+ }
11
+ return {
12
+ value: _value,
13
+ };
14
+ }
15
+
16
+ export { validateIsDate };
@@ -0,0 +1,17 @@
1
+ import { container } from '../../../core/injection/index.js';
2
+ import { ValidationMetadataStore } from '../../../core/validation/metadata/ValidationMetadataStore.js';
3
+ import { validateIsNotEmpty } from './validateIsNotEmpty.js';
4
+
5
+ function isNotEmpty() {
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: validateIsNotEmpty,
13
+ });
14
+ };
15
+ }
16
+
17
+ export { isNotEmpty };
@@ -0,0 +1,12 @@
1
+ function validateIsNotEmpty(value) {
2
+ if (value === '' || (Array.isArray(value) && value.length === 0)) {
3
+ return {
4
+ error: { description: `empty value not allowed` },
5
+ };
6
+ }
7
+ return {
8
+ value,
9
+ };
10
+ }
11
+
12
+ export { validateIsNotEmpty };
@@ -0,0 +1,17 @@
1
+ import { container } from '../../../core/injection/index.js';
2
+ import { validateIsNumber } from './validateIsNumber.js';
3
+ import { ValidationMetadataStore } from '../../../core/validation/metadata/ValidationMetadataStore.js';
4
+
5
+ function isNumber() {
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: validateIsNumber,
13
+ });
14
+ };
15
+ }
16
+
17
+ export { isNumber };
@@ -0,0 +1,12 @@
1
+ function validateIsNumber(value) {
2
+ if (typeof value !== 'number') {
3
+ return {
4
+ error: { description: `number value is required` },
5
+ };
6
+ }
7
+ return {
8
+ value,
9
+ };
10
+ }
11
+
12
+ export { validateIsNumber };
@@ -0,0 +1,17 @@
1
+ import { container } from '../../../core/injection/index.js';
2
+ import { ValidationMetadataStore } from '../../../core/validation/metadata/ValidationMetadataStore.js';
3
+ import { validateIsPresent } from './validateIsPresent.js';
4
+
5
+ function isPresent() {
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: validateIsPresent,
13
+ });
14
+ };
15
+ }
16
+
17
+ export { isPresent };
@@ -0,0 +1,12 @@
1
+ function validateIsPresent(value) {
2
+ if (value == null) {
3
+ return {
4
+ error: { description: `not present` },
5
+ };
6
+ }
7
+ return {
8
+ value,
9
+ };
10
+ }
11
+
12
+ export { validateIsPresent };
@@ -0,0 +1,17 @@
1
+ import { container } from '../../../core/injection/index.js';
2
+ import { ValidationMetadataStore } from '../../../core/validation/metadata/ValidationMetadataStore.js';
3
+ import { validateIsString } from './validateIsString.js';
4
+
5
+ function isString() {
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: validateIsString,
13
+ });
14
+ };
15
+ }
16
+
17
+ export { isString };
@@ -0,0 +1,12 @@
1
+ function validateIsString(value) {
2
+ if (typeof value !== 'string') {
3
+ return {
4
+ error: { description: `string value is required` },
5
+ };
6
+ }
7
+ return {
8
+ value,
9
+ };
10
+ }
11
+
12
+ export { validateIsString };
@@ -0,0 +1,18 @@
1
+ import { container } from '../../../core/injection/index.js';
2
+ import { ValidationMetadataStore } from '../../../core/validation/metadata/ValidationMetadataStore.js';
3
+ import { validateMax } from './validateMax.js';
4
+
5
+ function max(limit) {
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: validateMax,
13
+ validatorOptions: { limit },
14
+ });
15
+ };
16
+ }
17
+
18
+ export { max };
@@ -0,0 +1,17 @@
1
+ function validateMax(value, options) {
2
+ if (value == null) {
3
+ return {
4
+ error: { description: `null or undefined value can't be validated with max` },
5
+ };
6
+ }
7
+ if (Number(value) > Number(options.limit)) {
8
+ return {
9
+ error: { description: `exceeds the established max limit` },
10
+ };
11
+ }
12
+ return {
13
+ value,
14
+ };
15
+ }
16
+
17
+ export { validateMax };
@@ -0,0 +1,18 @@
1
+ import { container } from '../../../core/injection/index.js';
2
+ import { ValidationMetadataStore } from '../../../core/validation/metadata/ValidationMetadataStore.js';
3
+ import { validateMin } from './validateMin.js';
4
+
5
+ function min(limit) {
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: validateMin,
13
+ validatorOptions: { limit },
14
+ });
15
+ };
16
+ }
17
+
18
+ export { min };
@@ -0,0 +1,17 @@
1
+ function validateMin(value, options) {
2
+ if (value == null) {
3
+ return {
4
+ error: { description: `null or undefined value can't be validated with min` },
5
+ };
6
+ }
7
+ if (Number(value) < Number(options.limit)) {
8
+ return {
9
+ error: { description: `exceeds the established min limit` },
10
+ };
11
+ }
12
+ return {
13
+ value,
14
+ };
15
+ }
16
+
17
+ export { validateMin };
@@ -1,22 +1,32 @@
1
- class Persistent {
2
- data;
3
- constructor(data) {
4
- this.data = data;
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
- getCreatedAt() {
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 'tsyringe';
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,4 @@
1
+ await import('reflect-metadata');
2
+ const { injectable, container, singleton, inject, scoped, Lifecycle } = await import('tsyringe');
3
+
4
+ export { Lifecycle, container, inject, injectable, scoped, singleton };
@@ -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,37 @@
1
+ import { randomBytes } from 'node:crypto';
2
+
3
+ const DIGITS = '0123456789';
4
+ const CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
5
+ class Random {
6
+ static slug(name, options) {
7
+ const base = name
8
+ .toLowerCase()
9
+ .trim()
10
+ .replace(/[\s\_]+/g, '-') // spaces/underscores to hyphens
11
+ .replace(/[^a-z0-9\-]/g, '') // remove non-alphanumeric except hyphens
12
+ .replace(/\-+/g, '-') // collapse multiple hyphens
13
+ .replace(/^\-+|\-+$/g, ''); // trim hyphens from ends
14
+ const random = this.string(options.randomLength);
15
+ return `${base}-${random}`;
16
+ }
17
+ static string(length) {
18
+ const bytes = randomBytes(length);
19
+ let result = '';
20
+ for (let i = 0; i < length; i++) {
21
+ const index = bytes[i] % CHARSET.length;
22
+ result += CHARSET[index];
23
+ }
24
+ return result;
25
+ }
26
+ static numberCode(length) {
27
+ const bytes = randomBytes(length);
28
+ let result = '';
29
+ for (let i = 0; i < length; i++) {
30
+ const index = bytes[i] % 10; // 0–9
31
+ result += DIGITS[index];
32
+ }
33
+ return result;
34
+ }
35
+ }
36
+
37
+ export { Random };
@@ -0,0 +1,8 @@
1
+ class Storable {
2
+ data;
3
+ constructor(data) {
4
+ this.data = data;
5
+ }
6
+ }
7
+
8
+ export { Storable };
@@ -0,0 +1,18 @@
1
+ import { container } from '../../injection/index.js';
2
+ import { validateArray } from '../validators/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 };