@wabot-dev/framework 0.1.0-beta.24 → 0.1.0-beta.25
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/index.d.ts +121 -64
- package/dist/src/index.js +9 -0
- package/dist/src/jwt/@jwtGuard.js +34 -0
- package/dist/src/jwt/Jwt.js +31 -0
- package/dist/src/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
- package/dist/src/jwt/JwtConfig.js +28 -0
- package/dist/src/jwt/JwtGuardMiddleware.js +45 -0
- package/dist/src/jwt/JwtRefreshToken.js +11 -0
- package/dist/src/jwt/JwtRefreshTokenRepository.js +21 -0
- package/dist/src/jwt/JwtSigner.js +48 -0
- package/dist/src/jwt/JwtTokenDto.js +22 -0
- package/package.json +1 -1
package/dist/src/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { Socket } from 'socket.io-client';
|
|
|
9
9
|
import * as tsyringe from 'tsyringe';
|
|
10
10
|
import { DependencyContainer as DependencyContainer$1 } from 'tsyringe';
|
|
11
11
|
export { DependencyContainer } from 'tsyringe';
|
|
12
|
+
import { Algorithm } from 'jsonwebtoken';
|
|
12
13
|
|
|
13
14
|
interface IMindsetFunctionConfig {
|
|
14
15
|
description: string;
|
|
@@ -1005,10 +1006,129 @@ declare class CustomError extends Error {
|
|
|
1005
1006
|
constructor(data: ICustomErrorData);
|
|
1006
1007
|
}
|
|
1007
1008
|
|
|
1009
|
+
declare function jwtGuard(): (target: object, propertyKey: string | symbol) => void;
|
|
1010
|
+
|
|
1011
|
+
declare class JwtTokenDto {
|
|
1012
|
+
token?: string;
|
|
1013
|
+
expiration?: Date;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
declare class JwtAccessAndRefreshTokenDto {
|
|
1017
|
+
access?: JwtTokenDto;
|
|
1018
|
+
refresh?: JwtTokenDto;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
declare class JwtConfig {
|
|
1022
|
+
secretOrPublicKey: string;
|
|
1023
|
+
secretOrPrivateKey: string;
|
|
1024
|
+
algorithm: Algorithm;
|
|
1025
|
+
accessExpirationSeconds: number;
|
|
1026
|
+
refreshExpirationSeconds: number;
|
|
1027
|
+
constructor(env: Env);
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
interface IJwtRefreshTokenData<A extends IStorableData> extends IEntityData {
|
|
1031
|
+
authInfo: A;
|
|
1032
|
+
}
|
|
1033
|
+
declare class JwtRefreshToken<A extends IStorableData> extends Entity<IJwtRefreshTokenData<A>> {
|
|
1034
|
+
get authInfo(): A;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1008
1037
|
declare class Mapper {
|
|
1009
1038
|
map<T>(data: any, ctor: IConstructor<T>): T;
|
|
1010
1039
|
}
|
|
1011
1040
|
|
|
1041
|
+
declare class JwtSigner {
|
|
1042
|
+
private config;
|
|
1043
|
+
private mapper;
|
|
1044
|
+
constructor(config: JwtConfig, mapper: Mapper);
|
|
1045
|
+
signAccessToken<D extends IStorableData>(info: D | JwtRefreshToken<any>): Promise<JwtTokenDto>;
|
|
1046
|
+
signRefreshToken(refreshToken: JwtRefreshToken<any>): Promise<JwtTokenDto>;
|
|
1047
|
+
signAccessAndRefreshToken(refreshToken: JwtRefreshToken<any>): Promise<JwtAccessAndRefreshTokenDto>;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
declare class JwtRefreshTokenRepository<D extends IStorableData> extends PgCrudRepository<JwtRefreshToken<D>> {
|
|
1051
|
+
constructor(pool: Pool);
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
declare class Jwt {
|
|
1055
|
+
private auth;
|
|
1056
|
+
private jwtSigner;
|
|
1057
|
+
private jwtRefreshTokenRepository;
|
|
1058
|
+
constructor(auth: Auth<any>, jwtSigner: JwtSigner, jwtRefreshTokenRepository: JwtRefreshTokenRepository<any>);
|
|
1059
|
+
createToken(): Promise<JwtAccessAndRefreshTokenDto>;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
interface IGetConfig {
|
|
1063
|
+
path?: string;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
declare function get(config?: string | IGetConfig): (target: object, propertyKey: string | symbol) => void;
|
|
1067
|
+
|
|
1068
|
+
interface IMiddleware {
|
|
1069
|
+
handle(req: Request, res: Response, container: DependencyContainer$1): Promise<void>;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
declare function middleware(middlewareConstructor: IConstructor<IMiddleware>): (target: object, propertyKey: string | symbol) => void;
|
|
1073
|
+
|
|
1074
|
+
interface IPostConfig {
|
|
1075
|
+
path?: string;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
declare function post(config?: string | IPostConfig): (target: object, propertyKey: string | symbol) => void;
|
|
1079
|
+
|
|
1080
|
+
interface IRestControllerConfig {
|
|
1081
|
+
path: string;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
declare function restController(config: string | IRestControllerConfig): (target: IConstructor<any>) => void;
|
|
1085
|
+
|
|
1086
|
+
interface IEndPointMetadata {
|
|
1087
|
+
method: 'get' | 'post';
|
|
1088
|
+
path?: string;
|
|
1089
|
+
controllerConstructor: IConstructor<any>;
|
|
1090
|
+
functionName: string;
|
|
1091
|
+
paramsTypes: any[];
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
interface IMiddlewareMetadata {
|
|
1095
|
+
controllerConstructor: IConstructor<any>;
|
|
1096
|
+
functionName: string;
|
|
1097
|
+
middlewareConstructor: IConstructor<IMiddleware>;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
interface IRestControllerMetadata {
|
|
1101
|
+
controllerConstructor: IConstructor<any>;
|
|
1102
|
+
path: string;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
declare class RestControllerMetadataStore {
|
|
1106
|
+
private endPoints;
|
|
1107
|
+
private middlewares;
|
|
1108
|
+
private restControllers;
|
|
1109
|
+
saveControllerMetadata(controllerMetadata: IRestControllerMetadata): void;
|
|
1110
|
+
saveEndPointMetadata(endPointMetadata: IEndPointMetadata): void;
|
|
1111
|
+
saveMiddlewareMetadata(middlewareMetadata: IMiddlewareMetadata): void;
|
|
1112
|
+
getControllerEndPointsInfo(controllerConstructor: IConstructor<any>): {
|
|
1113
|
+
middlewares: IMiddlewareMetadata[];
|
|
1114
|
+
controller: IRestControllerMetadata;
|
|
1115
|
+
method: "get" | "post";
|
|
1116
|
+
path?: string;
|
|
1117
|
+
controllerConstructor: IConstructor<any>;
|
|
1118
|
+
functionName: string;
|
|
1119
|
+
paramsTypes: any[];
|
|
1120
|
+
}[];
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
declare function runRestControllers(controllers: IConstructor<any>[]): void;
|
|
1124
|
+
|
|
1125
|
+
declare class JwtGuardMiddleware implements IMiddleware {
|
|
1126
|
+
private config;
|
|
1127
|
+
private auth;
|
|
1128
|
+
constructor(config: JwtConfig, auth: Auth<any>);
|
|
1129
|
+
handle(req: Request, res: Response, container: DependencyContainer$1): Promise<void>;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1012
1132
|
declare class SendOneTimePasswordRequest {
|
|
1013
1133
|
fromEmail: string;
|
|
1014
1134
|
toEmail: string;
|
|
@@ -1119,69 +1239,6 @@ declare class Random {
|
|
|
1119
1239
|
static numberCode(length: number): string;
|
|
1120
1240
|
}
|
|
1121
1241
|
|
|
1122
|
-
interface IGetConfig {
|
|
1123
|
-
path?: string;
|
|
1124
|
-
}
|
|
1125
|
-
|
|
1126
|
-
declare function get(config?: string | IGetConfig): (target: object, propertyKey: string | symbol) => void;
|
|
1127
|
-
|
|
1128
|
-
interface IMiddleware {
|
|
1129
|
-
handle(req: Request, res: Response, container: DependencyContainer$1): Promise<void>;
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
declare function middleware(middlewareConstructor: IConstructor<IMiddleware>): (target: object, propertyKey: string | symbol) => void;
|
|
1133
|
-
|
|
1134
|
-
interface IPostConfig {
|
|
1135
|
-
path?: string;
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
declare function post(config?: string | IPostConfig): (target: object, propertyKey: string | symbol) => void;
|
|
1139
|
-
|
|
1140
|
-
interface IRestControllerConfig {
|
|
1141
|
-
path: string;
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
declare function restController(config: string | IRestControllerConfig): (target: IConstructor<any>) => void;
|
|
1145
|
-
|
|
1146
|
-
interface IEndPointMetadata {
|
|
1147
|
-
method: 'get' | 'post';
|
|
1148
|
-
path?: string;
|
|
1149
|
-
controllerConstructor: IConstructor<any>;
|
|
1150
|
-
functionName: string;
|
|
1151
|
-
paramsTypes: any[];
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
interface IMiddlewareMetadata {
|
|
1155
|
-
controllerConstructor: IConstructor<any>;
|
|
1156
|
-
functionName: string;
|
|
1157
|
-
middlewareConstructor: IConstructor<IMiddleware>;
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
interface IRestControllerMetadata {
|
|
1161
|
-
controllerConstructor: IConstructor<any>;
|
|
1162
|
-
path: string;
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
declare class RestControllerMetadataStore {
|
|
1166
|
-
private endPoints;
|
|
1167
|
-
private middlewares;
|
|
1168
|
-
private restControllers;
|
|
1169
|
-
saveControllerMetadata(controllerMetadata: IRestControllerMetadata): void;
|
|
1170
|
-
saveEndPointMetadata(endPointMetadata: IEndPointMetadata): void;
|
|
1171
|
-
saveMiddlewareMetadata(middlewareMetadata: IMiddlewareMetadata): void;
|
|
1172
|
-
getControllerEndPointsInfo(controllerConstructor: IConstructor<any>): {
|
|
1173
|
-
middlewares: IMiddlewareMetadata[];
|
|
1174
|
-
controller: IRestControllerMetadata;
|
|
1175
|
-
method: "get" | "post";
|
|
1176
|
-
path?: string;
|
|
1177
|
-
controllerConstructor: IConstructor<any>;
|
|
1178
|
-
functionName: string;
|
|
1179
|
-
paramsTypes: any[];
|
|
1180
|
-
}[];
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1183
|
-
declare function runRestControllers(controllers: IConstructor<any>[]): void;
|
|
1184
|
-
|
|
1185
1242
|
declare function prepareChatContainer(container: DependencyContainer$1, context: IMessageContext, mindsetCtor?: IConstructor<IMindset>): Promise<DependencyContainer$1>;
|
|
1186
1243
|
|
|
1187
1244
|
interface IrunChannelProps {
|
|
@@ -1302,4 +1359,4 @@ declare function validateModel<V>(value: any, info: IModelValidatorsInfo<V>): IM
|
|
|
1302
1359
|
|
|
1303
1360
|
declare function validate<V>(value: any, modelConstructor: IConstructor<V>): IModelValidationResult<V>;
|
|
1304
1361
|
|
|
1305
|
-
export { Async, Auth, AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, ClaudeChatBotAdapter, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatBotAdapter, EmailService, Entity, Env, EnvWhatsAppRepository, ExpressProvider, HtmlModule, HttpServerProvider, type IChannelMetadata, type IChatBot, type IChatBotAdapter, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatFunctionCall, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConnectionChatMessage, type IConstructor, type ICrudRepository, type ICustomErrorData, type IEmailService, type IEndPointMetadata, type IEntityData, type IEnvType, type IGetConfig, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IJobData, type IJobEvent, type IJobEventListener, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMiddleware, type IMiddlewareMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IOtpService, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, type IPostConfig, type IPrimitive, type IPropertyValidatorInfo, type IReceivedMessage, type IReceivedMessageItem, type IRestControllerConfig, type IRestControllerMetadata, type ISendEmailRequest, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type IServerConfig, type IServerProvider, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type IStorableData, type ISystemFunctionCallItem, type ISystemMessageItem, type ITelegramChannelConfig, type IUserConnection, type IUserData, type IUserRepository, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppContact, type IWhatsAppData, type IWhatsAppMessage, type IWhatsAppMessageListener, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsAppTemplate, type IWhatsAppTemplateComponent, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppTemplateResponse, type IWhatsAppWebhookPayload, type IWhatsappChannelConfig, type IchatControllerConfig, type IrunChannelProps, Job, JobRepository, JobRunner, JobsEventsHub, Lifecycle, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, Mapper, MessageContext, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatBotAdapter, OtpService, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgRepositoryBase, PgUserRepository, PgWhatsAppRepository, RamChatMemory, RamChatRepository, RamUserRepository, Random, RegisterUserModule, RegisterUserWithEmailRequest, RestControllerMetadataStore, SendOneTimePasswordRequest, SocketChannel, SocketChannelConfig, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, ValidationMetadataStore, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, cmd, command, commandHandler, container, get, inject, injectable, isBoolean, isDate, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, max, middleware, min, mindset, mindsetFunction, mindsetModule, param, post, prepareChatContainer, restController, runAsyncCommandHandlers, runChannel, runRestControllers, runServer, scoped, singleton, socket, telegram, validate, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsapp };
|
|
1362
|
+
export { Async, Auth, AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, ClaudeChatBotAdapter, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatBotAdapter, EmailService, Entity, Env, EnvWhatsAppRepository, ExpressProvider, HtmlModule, HttpServerProvider, type IChannelMetadata, type IChatBot, type IChatBotAdapter, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatFunctionCall, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConnectionChatMessage, type IConstructor, type ICrudRepository, type ICustomErrorData, type IEmailService, type IEndPointMetadata, type IEntityData, type IEnvType, type IGetConfig, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IJobData, type IJobEvent, type IJobEventListener, type IJwtRefreshTokenData, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMiddleware, type IMiddlewareMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IOtpService, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, type IPostConfig, type IPrimitive, type IPropertyValidatorInfo, type IReceivedMessage, type IReceivedMessageItem, type IRestControllerConfig, type IRestControllerMetadata, type ISendEmailRequest, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type IServerConfig, type IServerProvider, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type IStorableData, type ISystemFunctionCallItem, type ISystemMessageItem, type ITelegramChannelConfig, type IUserConnection, type IUserData, type IUserRepository, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppContact, type IWhatsAppData, type IWhatsAppMessage, type IWhatsAppMessageListener, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsAppTemplate, type IWhatsAppTemplateComponent, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppTemplateResponse, type IWhatsAppWebhookPayload, type IWhatsappChannelConfig, type IchatControllerConfig, type IrunChannelProps, Job, JobRepository, JobRunner, JobsEventsHub, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, Mapper, MessageContext, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatBotAdapter, OtpService, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgRepositoryBase, PgUserRepository, PgWhatsAppRepository, RamChatMemory, RamChatRepository, RamUserRepository, Random, RegisterUserModule, RegisterUserWithEmailRequest, RestControllerMetadataStore, SendOneTimePasswordRequest, SocketChannel, SocketChannelConfig, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, ValidationMetadataStore, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, cmd, command, commandHandler, container, get, inject, injectable, isBoolean, isDate, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, jwtGuard, max, middleware, min, mindset, mindsetFunction, mindsetModule, param, post, prepareChatContainer, restController, runAsyncCommandHandlers, runChannel, runRestControllers, runServer, scoped, singleton, socket, telegram, validate, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsapp };
|
package/dist/src/index.js
CHANGED
|
@@ -56,6 +56,15 @@ export { Storable } from './core/Storable.js';
|
|
|
56
56
|
export { Env } from './env/Env.js';
|
|
57
57
|
export { CustomError } from './error/CustomError.js';
|
|
58
58
|
export { Lifecycle, container, inject, injectable, scoped, singleton } from './injection/index.js';
|
|
59
|
+
export { jwtGuard } from './jwt/@jwtGuard.js';
|
|
60
|
+
export { JwtAccessAndRefreshTokenDto } from './jwt/JwtAccessAndRefreshTokenDto.js';
|
|
61
|
+
export { JwtConfig } from './jwt/JwtConfig.js';
|
|
62
|
+
export { Jwt } from './jwt/Jwt.js';
|
|
63
|
+
export { JwtGuardMiddleware } from './jwt/JwtGuardMiddleware.js';
|
|
64
|
+
export { JwtRefreshToken } from './jwt/JwtRefreshToken.js';
|
|
65
|
+
export { JwtSigner } from './jwt/JwtSigner.js';
|
|
66
|
+
export { JwtTokenDto } from './jwt/JwtTokenDto.js';
|
|
67
|
+
export { JwtRefreshTokenRepository } from './jwt/JwtRefreshTokenRepository.js';
|
|
59
68
|
export { Logger } from './logger/Logger.js';
|
|
60
69
|
export { Mapper } from './mapper/Mapper.js';
|
|
61
70
|
export { mindsetFunction } from './mindset/metadata/functions/@mindsetFunction.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import '../injection/index.js';
|
|
2
|
+
import '../rest-controller/metadata/RestControllerMetadataStore.js';
|
|
3
|
+
import { middleware } from '../rest-controller/metadata/@middleware.js';
|
|
4
|
+
import '../controller/channel/ChatResolver.js';
|
|
5
|
+
import '../controller/channel/UserResolver.js';
|
|
6
|
+
import '../controller/metadata/ControllerMetadataStore.js';
|
|
7
|
+
import '../channels/cmd/CmdChannel.js';
|
|
8
|
+
import '../channels/express/ExpressProvider.js';
|
|
9
|
+
import '../channels/http/HttpServerProvider.js';
|
|
10
|
+
import '../channels/socket/SocketChannel.js';
|
|
11
|
+
import '../channels/socket/SocketChannelConfig.js';
|
|
12
|
+
import '../channels/socket/SocketServerProvider.js';
|
|
13
|
+
import '../channels/telegram/TelegramChannel.js';
|
|
14
|
+
import '../channels/whatsapp/WhatsAppChannel.js';
|
|
15
|
+
import '../channels/whatsapp/EnvWhatsAppRepository.js';
|
|
16
|
+
import '../channels/whatsapp/PgWhatsAppRepository.js';
|
|
17
|
+
import '../core/chat/repository/IChatRepository.js';
|
|
18
|
+
import '../core/user/IUserRepository.js';
|
|
19
|
+
import '../channels/whatsapp/WhatsAppReceiverByDevConnection.js';
|
|
20
|
+
import '../channels/whatsapp/WhatsAppReceiverByWebHook.js';
|
|
21
|
+
import '../channels/whatsapp/WhatsAppSenderByCloudApi.js';
|
|
22
|
+
import '../channels/whatsapp/WhatsAppSenderByDevConnection.js';
|
|
23
|
+
import 'debug';
|
|
24
|
+
import '../validation/metadata/ValidationMetadataStore.js';
|
|
25
|
+
import 'path';
|
|
26
|
+
import { JwtGuardMiddleware } from './JwtGuardMiddleware.js';
|
|
27
|
+
|
|
28
|
+
function jwtGuard() {
|
|
29
|
+
return function (target, propertyKey) {
|
|
30
|
+
middleware(JwtGuardMiddleware)(target, propertyKey);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { jwtGuard };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { Auth } from '../auth/Auth.js';
|
|
3
|
+
import { JwtSigner } from './JwtSigner.js';
|
|
4
|
+
import { JwtRefreshTokenRepository } from './JwtRefreshTokenRepository.js';
|
|
5
|
+
import { JwtRefreshToken } from './JwtRefreshToken.js';
|
|
6
|
+
import { injectable } from '../injection/index.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 '../injection/index.js';
|
|
3
|
+
import '../validation/metadata/ValidationMetadataStore.js';
|
|
4
|
+
import { isModel } from '../validation/metadata/@isModel.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 '../env/Env.js';
|
|
3
|
+
import { singleton } from '../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 { Auth } from '../auth/Auth.js';
|
|
3
|
+
import jwt from 'jsonwebtoken';
|
|
4
|
+
import { JwtConfig } from './JwtConfig.js';
|
|
5
|
+
import { injectable } from '../injection/index.js';
|
|
6
|
+
import { CustomError } from '../error/CustomError.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,11 @@
|
|
|
1
|
+
import '../core/chat/repository/IChatRepository.js';
|
|
2
|
+
import { Entity } from '../core/Entity.js';
|
|
3
|
+
import '../core/user/IUserRepository.js';
|
|
4
|
+
|
|
5
|
+
class JwtRefreshToken extends Entity {
|
|
6
|
+
get authInfo() {
|
|
7
|
+
return this.data.authInfo;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { JwtRefreshToken };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { singleton } from '../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 '../injection/index.js';
|
|
8
|
+
import { Mapper } from '../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 '../injection/index.js';
|
|
3
|
+
import '../validation/metadata/ValidationMetadataStore.js';
|
|
4
|
+
import { isDate } from '../validation/metadata/@isDate.js';
|
|
5
|
+
import { isNotEmpty } from '../validation/metadata/@isNotEmpty.js';
|
|
6
|
+
import { isString } from '../validation/metadata/@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 };
|