@wabot-dev/framework 0.1.0-beta.4 → 0.1.0-beta.41

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 (154) hide show
  1. package/dist/src/addon/async/pg/PgJobRepository.js +26 -0
  2. package/dist/src/addon/chat-bot/anthropic/AnthropicChatAdapter.js +135 -0
  3. package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +137 -0
  4. package/dist/src/addon/chat-bot/google/GoogleChatAdapter.js +127 -0
  5. package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +116 -0
  6. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +5 -4
  7. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +5 -5
  8. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
  9. package/dist/src/addon/chat-controller/cmd/@cmd.js +22 -0
  10. package/dist/src/{channels → addon/chat-controller}/cmd/CmdChannel.js +4 -26
  11. package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +8 -4
  12. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +5 -23
  13. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
  14. package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +8 -4
  15. package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
  16. package/dist/src/{channels → addon/chat-controller}/whatsapp/@whatsapp.js +8 -4
  17. package/dist/src/{channels → addon/chat-controller}/whatsapp/EnvWhatsAppRepository.js +3 -3
  18. package/dist/src/{channels → addon/chat-controller}/whatsapp/PgWhatsAppRepository.js +1 -1
  19. package/dist/src/{channels/wabot → addon/chat-controller/whatsapp}/WabotDevConnection.js +2 -2
  20. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +2 -4
  21. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
  22. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiver.js +4 -7
  23. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiverByDevConnection.js +4 -10
  24. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppReceiverByWebHook.js +6 -12
  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/addon/money/MoneyDto.js +22 -0
  30. package/dist/src/{repository → addon/repository}/pg/PgCrudRepository.js +23 -2
  31. package/dist/src/{repository → addon/repository}/pg/PgRepositoryBase.js +2 -2
  32. package/dist/src/addon/rest-controller/jwt/@jwtGuard.js +17 -0
  33. package/dist/src/addon/rest-controller/jwt/Jwt.js +31 -0
  34. package/dist/src/addon/rest-controller/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
  35. package/dist/src/addon/rest-controller/jwt/JwtConfig.js +28 -0
  36. package/dist/src/addon/rest-controller/jwt/JwtGuardMiddleware.js +45 -0
  37. package/dist/src/addon/rest-controller/jwt/JwtRefreshToken.js +9 -0
  38. package/dist/src/addon/rest-controller/jwt/JwtRefreshTokenRepository.js +21 -0
  39. package/dist/src/addon/rest-controller/jwt/JwtSigner.js +48 -0
  40. package/dist/src/addon/rest-controller/jwt/JwtTokenDto.js +22 -0
  41. package/dist/src/addon/validation/is-boolean/@isBoolean.js +17 -0
  42. package/dist/src/addon/validation/is-boolean/validateIsBoolean.js +12 -0
  43. package/dist/src/addon/validation/is-date/@isDate.js +17 -0
  44. package/dist/src/addon/validation/is-date/validateIsDate.js +16 -0
  45. package/dist/src/addon/validation/is-not-empty/@isNotEmpty.js +17 -0
  46. package/dist/src/addon/validation/is-not-empty/validateIsNotEmpty.js +12 -0
  47. package/dist/src/addon/validation/is-number/@isNumber.js +17 -0
  48. package/dist/src/addon/validation/is-number/validateIsNumber.js +12 -0
  49. package/dist/src/addon/validation/is-present/@isPresent.js +17 -0
  50. package/dist/src/addon/validation/is-present/validateIsPresent.js +12 -0
  51. package/dist/src/addon/validation/is-string/@isString.js +17 -0
  52. package/dist/src/addon/validation/is-string/validateIsString.js +12 -0
  53. package/dist/src/addon/validation/max/@max.js +18 -0
  54. package/dist/src/addon/validation/max/validateMax.js +17 -0
  55. package/dist/src/addon/validation/min/@min.js +18 -0
  56. package/dist/src/addon/validation/min/validateMin.js +17 -0
  57. package/dist/src/core/auth/Auth.js +24 -0
  58. package/dist/src/core/{Persistent.js → entity/Entity.js} +24 -9
  59. package/dist/src/core/env/Env.js +39 -0
  60. package/dist/src/core/error/CustomError.js +15 -0
  61. package/dist/src/core/injection/index.js +4 -0
  62. package/dist/src/core/mapper/Mapper.js +42 -0
  63. package/dist/src/core/random/Random.js +37 -0
  64. package/dist/src/core/storable/Storable.js +8 -0
  65. package/dist/src/core/validation/metadata/@isArray.js +18 -0
  66. package/dist/src/core/validation/metadata/@isModel.js +18 -0
  67. package/dist/src/core/validation/metadata/@isOptional.js +17 -0
  68. package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
  69. package/dist/src/core/validation/modelInfo.js +9 -0
  70. package/dist/src/core/validation/validate.js +11 -0
  71. package/dist/src/core/validation/validators/validateArray.js +51 -0
  72. package/dist/src/core/validation/validators/validateIsOptional.js +5 -0
  73. package/dist/src/core/validation/validators/validateModel.js +36 -0
  74. package/dist/src/feature/async/@command.js +11 -0
  75. package/dist/src/feature/async/@commandHandler.js +12 -0
  76. package/dist/src/feature/async/Async.js +38 -0
  77. package/dist/src/feature/async/Command.js +9 -0
  78. package/dist/src/feature/async/CommandMetadataStore.js +38 -0
  79. package/dist/src/feature/async/Job.js +24 -0
  80. package/dist/src/feature/async/JobRepository.js +31 -0
  81. package/dist/src/feature/async/JobRunner.js +45 -0
  82. package/dist/src/feature/async/JobsEventsHub.js +24 -0
  83. package/dist/src/feature/async/runCommandHandlers.js +29 -0
  84. package/dist/src/{core/chat → feature/chat-bot}/Chat.js +2 -2
  85. package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
  86. package/dist/src/feature/chat-bot/ChatBot.js +50 -0
  87. package/dist/src/feature/chat-bot/ChatItem.js +24 -0
  88. package/dist/src/feature/chat-bot/ChatMemory.js +10 -0
  89. package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js} +2 -8
  90. package/dist/src/feature/chat-bot/IChatItem.js +3 -0
  91. package/dist/src/{chatbot → feature/chat-bot}/metadata/@chatBot.js +1 -1
  92. package/dist/src/{chatbot → feature/chat-bot}/metadata/ChatBotMetadataStore.js +1 -1
  93. package/dist/src/{controller/channel → feature/chat-controller}/ChatResolver.js +5 -4
  94. package/dist/src/{controller → feature/chat-controller}/metadata/ControllerMetadataStore.js +1 -1
  95. package/dist/src/{controller → feature/chat-controller}/metadata/controller/@chatController.js +1 -1
  96. package/dist/src/feature/chat-controller/runChatControllers.js +69 -0
  97. package/dist/src/{channels → feature}/express/ExpressProvider.js +2 -4
  98. package/dist/src/{channels → feature}/http/HttpServerProvider.js +2 -2
  99. package/dist/src/{mindset → feature/mindset}/MindsetOperator.js +66 -42
  100. package/dist/src/{mindset → feature/mindset}/metadata/MindsetMetadataStore.js +1 -1
  101. package/dist/src/{mindset → feature/mindset}/metadata/functions/@mindsetFunction.js +1 -1
  102. package/dist/src/{mindset → feature/mindset}/metadata/mindsets/@mindset.js +1 -1
  103. package/dist/src/{mindset → feature/mindset}/metadata/modules/@mindsetModule.js +1 -2
  104. package/dist/src/{mindset → feature/mindset}/metadata/params/@param.js +1 -1
  105. package/dist/src/feature/money/Money.js +61 -0
  106. package/dist/src/feature/rest-controller/injection-tokens.js +4 -0
  107. package/dist/src/feature/rest-controller/metadata/@get.js +19 -0
  108. package/dist/src/feature/rest-controller/metadata/@middleware.js +16 -0
  109. package/dist/src/feature/rest-controller/metadata/@post.js +19 -0
  110. package/dist/src/feature/rest-controller/metadata/@restController.js +15 -0
  111. package/dist/src/feature/rest-controller/metadata/RestControllerMetadataStore.js +50 -0
  112. package/dist/src/feature/rest-controller/runRestControllers.js +88 -0
  113. package/dist/src/{channels → feature}/socket/SocketServerProvider.js +2 -2
  114. package/dist/src/index.d.ts +848 -483
  115. package/dist/src/index.js +122 -76
  116. package/package.json +9 -3
  117. package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -106
  118. package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -84
  119. package/dist/src/channels/cmd/@cmd.js +0 -18
  120. package/dist/src/chatbot/ChatBot.js +0 -51
  121. package/dist/src/chatbot/ChatBotAdapter.js +0 -72
  122. package/dist/src/controller/channel/UserResolver.js +0 -21
  123. package/dist/src/core/IMessageContext.js +0 -12
  124. package/dist/src/core/chat/ChatItem.js +0 -15
  125. package/dist/src/core/chat/repository/IChatMemory.js +0 -10
  126. package/dist/src/core/user/IUserRepository.js +0 -19
  127. package/dist/src/core/user/User.js +0 -26
  128. package/dist/src/env/WabotEnv.js +0 -27
  129. package/dist/src/injection/index.js +0 -4
  130. package/dist/src/mindset/metadata/params/@isOptional.js +0 -21
  131. package/dist/src/pre-made/module/authentication/AuthenticationModule.js +0 -97
  132. package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -25
  133. package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -25
  134. package/dist/src/pre-made/module/register-user/RegisterUserModule.js +0 -56
  135. package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -25
  136. package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -33
  137. package/dist/src/pre-made/repository/user/ram/RamUserRepository.js +0 -27
  138. package/dist/src/pre-made/service/EmailService.js +0 -13
  139. package/dist/src/pre-made/service/OtpService.js +0 -14
  140. package/dist/src/server/prepareChatContainer.js +0 -43
  141. package/dist/src/server/runChannel.js +0 -27
  142. package/dist/src/server/runServer.js +0 -40
  143. /package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatMemory.js +0 -0
  144. /package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannelConfig.js +0 -0
  145. /package/dist/src/{channels/wabot → addon/chat-controller/whatsapp}/WabotDevSocketContracts.js +0 -0
  146. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
  147. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppRepository.js +0 -0
  148. /package/dist/src/{injection → core/injection}/Container.js +0 -0
  149. /package/dist/src/{logger → core/logger}/Logger.js +0 -0
  150. /package/dist/src/{mindset → feature/mindset}/IMindset.js +0 -0
  151. /package/dist/src/{mindset → feature/mindset}/metadata/functions/decoratorNames.js +0 -0
  152. /package/dist/src/{mindset → feature/mindset}/metadata/mindsets/decoratorNames.js +0 -0
  153. /package/dist/src/{mindset → feature/mindset}/metadata/modules/decoratorNames.js +0 -0
  154. /package/dist/src/{mindset → feature/mindset}/metadata/params/decoratorNames.js +0 -0
@@ -1,5 +1,6 @@
1
1
  import * as shortUUID from 'short-uuid';
2
2
  import { PgRepositoryBase } from './PgRepositoryBase.js';
3
+ import { CustomError } from '../../../core/error/CustomError.js';
3
4
 
4
5
  class PgCrudRepository extends PgRepositoryBase {
5
6
  config;
@@ -17,6 +18,26 @@ class PgCrudRepository extends PgRepositoryBase {
17
18
  const items = await this.query(sql, [id]);
18
19
  return items.at(0) ?? null;
19
20
  }
21
+ async findByIds(ids) {
22
+ const sql = `
23
+ SELECT ${this.columns}
24
+ FROM ${this.table}
25
+ WHERE id IN (${ids.map((_, i) => '$' + (i + 1)).join(',')})
26
+ LIMIT 1
27
+ `;
28
+ const items = await this.query(sql, ids);
29
+ return items;
30
+ }
31
+ async findOrThrow(id) {
32
+ const item = await this.find(id);
33
+ if (!item) {
34
+ throw new CustomError({
35
+ message: `Not found ${this.config.constructor.name} with id = '${id}'}`,
36
+ httpCode: 404,
37
+ });
38
+ }
39
+ return item;
40
+ }
20
41
  async findAll() {
21
42
  const sql = `
22
43
  SELECT ${this.columns}
@@ -46,10 +67,10 @@ class PgCrudRepository extends PgRepositoryBase {
46
67
  SET ${this.updates}
47
68
  WHERE id = $${this.columnsList.length + 1}
48
69
  `;
49
- await this.exec(sql, [...this.values(item), item.getId()]);
70
+ await this.exec(sql, [...this.values(item), item.id]);
50
71
  }
51
72
  async discard(item) {
52
- const _item = await this.find(item.getId());
73
+ const _item = await this.find(item.id);
53
74
  if (!_item) {
54
75
  throw new Error('Not found');
55
76
  }
@@ -32,8 +32,8 @@ class PgRepositoryBase {
32
32
  }
33
33
  values(item) {
34
34
  return [
35
- item.getId(),
36
- item.getCreatedAt(),
35
+ item.id,
36
+ item.createdAt,
37
37
  JSON.stringify(item['data']),
38
38
  ...this.columnsList.slice(3).map((x) => this.addColumns[x].value(item)),
39
39
  ];
@@ -0,0 +1,17 @@
1
+ import '../../../core/injection/index.js';
2
+ import '../../../feature/rest-controller/metadata/RestControllerMetadataStore.js';
3
+ import { middleware } from '../../../feature/rest-controller/metadata/@middleware.js';
4
+ import 'debug';
5
+ import '../../../core/validation/metadata/ValidationMetadataStore.js';
6
+ import '../../../feature/express/ExpressProvider.js';
7
+ import 'express';
8
+ import 'path';
9
+ import { JwtGuardMiddleware } from './JwtGuardMiddleware.js';
10
+
11
+ function jwtGuard() {
12
+ return function (target, propertyKey) {
13
+ middleware(JwtGuardMiddleware)(target, propertyKey);
14
+ };
15
+ }
16
+
17
+ export { jwtGuard };
@@ -0,0 +1,31 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { JwtSigner } from './JwtSigner.js';
3
+ import { JwtRefreshTokenRepository } from './JwtRefreshTokenRepository.js';
4
+ import { JwtRefreshToken } from './JwtRefreshToken.js';
5
+ import { injectable } from '../../../core/injection/index.js';
6
+ import { Auth } from '../../../core/auth/Auth.js';
7
+
8
+ let Jwt = class Jwt {
9
+ auth;
10
+ jwtSigner;
11
+ jwtRefreshTokenRepository;
12
+ constructor(auth, jwtSigner, jwtRefreshTokenRepository) {
13
+ this.auth = auth;
14
+ this.jwtSigner = jwtSigner;
15
+ this.jwtRefreshTokenRepository = jwtRefreshTokenRepository;
16
+ }
17
+ async createToken() {
18
+ const authInfo = this.auth.require();
19
+ const refreshToken = new JwtRefreshToken({ authInfo });
20
+ await this.jwtRefreshTokenRepository.create(refreshToken);
21
+ return await this.jwtSigner.signAccessAndRefreshToken(refreshToken);
22
+ }
23
+ };
24
+ Jwt = __decorate([
25
+ injectable(),
26
+ __metadata("design:paramtypes", [Auth,
27
+ JwtSigner,
28
+ JwtRefreshTokenRepository])
29
+ ], Jwt);
30
+
31
+ export { Jwt };
@@ -0,0 +1,20 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { isModel } from '../../../core/validation/metadata/@isModel.js';
3
+ import '../../../core/injection/index.js';
4
+ import '../../../core/validation/metadata/ValidationMetadataStore.js';
5
+ import { JwtTokenDto } from './JwtTokenDto.js';
6
+
7
+ class JwtAccessAndRefreshTokenDto {
8
+ access;
9
+ refresh;
10
+ }
11
+ __decorate([
12
+ isModel(JwtTokenDto),
13
+ __metadata("design:type", JwtTokenDto)
14
+ ], JwtAccessAndRefreshTokenDto.prototype, "access", void 0);
15
+ __decorate([
16
+ isModel(JwtTokenDto),
17
+ __metadata("design:type", JwtTokenDto)
18
+ ], JwtAccessAndRefreshTokenDto.prototype, "refresh", void 0);
19
+
20
+ export { JwtAccessAndRefreshTokenDto };
@@ -0,0 +1,28 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { Env } from '../../../core/env/Env.js';
3
+ import { singleton } from '../../../core/injection/index.js';
4
+
5
+ let JwtConfig = class JwtConfig {
6
+ secretOrPublicKey;
7
+ secretOrPrivateKey;
8
+ algorithm;
9
+ accessExpirationSeconds;
10
+ refreshExpirationSeconds;
11
+ constructor(env) {
12
+ this.algorithm = env.requireString('JWT_ALGORITHM', { default: 'HS256' });
13
+ this.secretOrPublicKey = env.requireString('JWT_SECRET');
14
+ this.secretOrPrivateKey = env.requireString('JWT_SECRET');
15
+ this.accessExpirationSeconds = env.requireNumber('JWT_ACCESS_EXPIRATION_SECONDS', {
16
+ default: 10 * 60,
17
+ });
18
+ this.refreshExpirationSeconds = env.requireNumber('JWT_REFRESH_EXPIRATION_SECONDS', {
19
+ default: 365 * 24 * 3600,
20
+ });
21
+ }
22
+ };
23
+ JwtConfig = __decorate([
24
+ singleton(),
25
+ __metadata("design:paramtypes", [Env])
26
+ ], JwtConfig);
27
+
28
+ export { JwtConfig };
@@ -0,0 +1,45 @@
1
+ import { __decorate, __metadata } from 'tslib';
2
+ import { CustomError } from '../../../core/error/CustomError.js';
3
+ import { injectable } from '../../../core/injection/index.js';
4
+ import jwt from 'jsonwebtoken';
5
+ import { JwtConfig } from './JwtConfig.js';
6
+ import { Auth } from '../../../core/auth/Auth.js';
7
+
8
+ let JwtGuardMiddleware = class JwtGuardMiddleware {
9
+ config;
10
+ auth;
11
+ constructor(config, auth) {
12
+ this.config = config;
13
+ this.auth = auth;
14
+ }
15
+ async handle(req, res, container) {
16
+ const authorization = req.header('Authorization');
17
+ if (!authorization) {
18
+ throw new CustomError({ httpCode: 401, message: 'Authorization header not available' });
19
+ }
20
+ const [bearer, token] = authorization.split(' ');
21
+ if (bearer.toLowerCase() !== 'bearer' || !token) {
22
+ throw new CustomError({ httpCode: 401, message: 'Authorization should be a bearer token' });
23
+ }
24
+ try {
25
+ const jwtPayload = jwt.verify(token, this.config.secretOrPublicKey, {
26
+ algorithms: [this.config.algorithm],
27
+ });
28
+ this.auth.assign(jwtPayload);
29
+ }
30
+ catch (err) {
31
+ throw new CustomError({
32
+ httpCode: 401,
33
+ message: err instanceof Error ? `Invalid token: ${err.message}` : 'Invalid token',
34
+ cause: err instanceof Error ? err : undefined,
35
+ });
36
+ }
37
+ }
38
+ };
39
+ JwtGuardMiddleware = __decorate([
40
+ injectable(),
41
+ __metadata("design:paramtypes", [JwtConfig,
42
+ Auth])
43
+ ], JwtGuardMiddleware);
44
+
45
+ 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 };
@@ -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
- 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 };