@wabot-dev/framework 0.1.0-beta.36 → 0.1.0-beta.38

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.
@@ -2,6 +2,7 @@ import { __decorate, __metadata } from 'tslib';
2
2
  import { Logger } from '../../../core/logger/Logger.js';
3
3
  import { WhatsAppReceiver } from './WhatsAppReceiver.js';
4
4
  import { ExpressProvider } from '../../../feature/express/ExpressProvider.js';
5
+ import { json } from 'express';
5
6
  import { WhatsAppRepository } from './WhatsAppRepository.js';
6
7
  import { singleton } from '../../../core/injection/index.js';
7
8
 
@@ -17,7 +18,7 @@ let WhatsAppReceiverByWebHook = class WhatsAppReceiverByWebHook extends WhatsApp
17
18
  this.expressApp = this.expressProvider.getExpress();
18
19
  }
19
20
  async connect() {
20
- this.expressApp.get(this.webhookPath, async (req, res) => {
21
+ this.expressApp.get(this.webhookPath, json(), async (req, res) => {
21
22
  try {
22
23
  let mode = req.query['hub.mode'];
23
24
  let token = req.query['hub.verify_token'];
@@ -39,7 +40,7 @@ let WhatsAppReceiverByWebHook = class WhatsAppReceiverByWebHook extends WhatsApp
39
40
  return;
40
41
  }
41
42
  });
42
- this.expressApp.post(this.webhookPath, (req, res) => {
43
+ this.expressApp.post(this.webhookPath, json(), (req, res) => {
43
44
  const payload = req.body;
44
45
  this.handlePayload(payload);
45
46
  res.sendStatus(200);
@@ -1,10 +1,11 @@
1
1
  import '../../../core/injection/index.js';
2
2
  import '../../../feature/rest-controller/metadata/RestControllerMetadataStore.js';
3
3
  import { middleware } from '../../../feature/rest-controller/metadata/@middleware.js';
4
- import 'path';
5
4
  import 'debug';
6
- import '../../../feature/express/ExpressProvider.js';
7
5
  import '../../../core/validation/metadata/ValidationMetadataStore.js';
6
+ import '../../../feature/express/ExpressProvider.js';
7
+ import 'express';
8
+ import 'path';
8
9
  import '../../../feature/rest-controller/auth/Auth.js';
9
10
  import { JwtGuardMiddleware } from './JwtGuardMiddleware.js';
10
11
 
@@ -4,10 +4,11 @@ import { JwtRefreshTokenRepository } from './JwtRefreshTokenRepository.js';
4
4
  import { JwtRefreshToken } from './JwtRefreshToken.js';
5
5
  import { injectable } from '../../../core/injection/index.js';
6
6
  import '../../../feature/rest-controller/metadata/RestControllerMetadataStore.js';
7
- import 'path';
8
7
  import 'debug';
9
- import '../../../feature/express/ExpressProvider.js';
10
8
  import '../../../core/validation/metadata/ValidationMetadataStore.js';
9
+ import '../../../feature/express/ExpressProvider.js';
10
+ import 'express';
11
+ import 'path';
11
12
  import { Auth } from '../../../feature/rest-controller/auth/Auth.js';
12
13
 
13
14
  let Jwt = class Jwt {
@@ -2,10 +2,11 @@ import { __decorate, __metadata } from 'tslib';
2
2
  import { CustomError } from '../../../core/error/CustomError.js';
3
3
  import { injectable } from '../../../core/injection/index.js';
4
4
  import '../../../feature/rest-controller/metadata/RestControllerMetadataStore.js';
5
- import 'path';
6
5
  import 'debug';
7
- import '../../../feature/express/ExpressProvider.js';
8
6
  import '../../../core/validation/metadata/ValidationMetadataStore.js';
7
+ import '../../../feature/express/ExpressProvider.js';
8
+ import 'express';
9
+ import 'path';
9
10
  import { Auth } from '../../../feature/rest-controller/auth/Auth.js';
10
11
  import jwt from 'jsonwebtoken';
11
12
  import { JwtConfig } from './JwtConfig.js';
@@ -1,7 +1,6 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
2
  import { HttpServerProvider } from '../http/HttpServerProvider.js';
3
3
  import express from 'express';
4
- import bodyParser from 'body-parser';
5
4
  import { Logger } from '../../core/logger/Logger.js';
6
5
  import { singleton } from '../../core/injection/index.js';
7
6
 
@@ -23,7 +22,6 @@ let ExpressProvider = class ExpressProvider {
23
22
  }
24
23
  createExpress() {
25
24
  const expressApp = express();
26
- expressApp.use(bodyParser.json());
27
25
  expressApp.use((req, res, next) => {
28
26
  const start = process.hrtime();
29
27
  res.on('finish', () => {
@@ -0,0 +1,4 @@
1
+ const EXPRESS_REQ = 'EXPRESS_REQ';
2
+ const EXPRESS_RES = 'EXPRESS_RES';
3
+
4
+ export { EXPRESS_REQ, EXPRESS_RES };
@@ -8,9 +8,9 @@ function get(config) {
8
8
  const store = container.resolve(RestControllerMetadataStore);
9
9
  store.saveEndPointMetadata({
10
10
  controllerConstructor: target.constructor,
11
- functionName,
12
11
  method: 'get',
13
- path: typeof config === 'string' ? config : config?.path,
12
+ config: typeof config === 'string' ? { path: config } : config,
13
+ functionName,
14
14
  paramsTypes,
15
15
  });
16
16
  };
@@ -8,9 +8,9 @@ function post(config) {
8
8
  const store = container.resolve(RestControllerMetadataStore);
9
9
  store.saveEndPointMetadata({
10
10
  controllerConstructor: target.constructor,
11
- functionName,
12
11
  method: 'post',
13
- path: typeof config === 'string' ? config : config?.path,
12
+ config: typeof config === 'string' ? { path: config } : config,
13
+ functionName,
14
14
  paramsTypes,
15
15
  });
16
16
  };
@@ -1,11 +1,13 @@
1
- import path from 'path';
1
+ import { CustomError } from '../../core/error/CustomError.js';
2
2
  import { container } from '../../core/injection/index.js';
3
- import { RestControllerMetadataStore } from './metadata/RestControllerMetadataStore.js';
4
3
  import { Logger } from '../../core/logger/Logger.js';
5
- import { ExpressProvider } from '../express/ExpressProvider.js';
6
4
  import '../../core/validation/metadata/ValidationMetadataStore.js';
7
5
  import { validate } from '../../core/validation/validate.js';
8
- import { CustomError } from '../../core/error/CustomError.js';
6
+ import { ExpressProvider } from '../express/ExpressProvider.js';
7
+ import { json, urlencoded } from 'express';
8
+ import path from 'path';
9
+ import { EXPRESS_REQ, EXPRESS_RES } from './injection-tokens.js';
10
+ import { RestControllerMetadataStore } from './metadata/RestControllerMetadataStore.js';
9
11
 
10
12
  function buildRequest(req) {
11
13
  return Object.assign({}, req.body, req.query, req.params);
@@ -19,10 +21,21 @@ function runRestControllers(controllers) {
19
21
  const endPoints = metadataStore.getControllerEndPointsInfo(controller);
20
22
  endPoints.forEach((endPoint) => {
21
23
  const method = endPoint.method;
22
- const route = path.join(endPoint.controller.path, endPoint.path ?? '').replaceAll('\\', '/');
24
+ const route = path
25
+ .join(endPoint.controller.path, endPoint.config?.path ?? '')
26
+ .replaceAll('\\', '/');
23
27
  logger.info(`config ${endPoint.method.toUpperCase()} ${route}`);
24
- expressApp[method](route, async (req, res) => {
28
+ const rawMiddlewares = [];
29
+ if (!endPoint.config?.disableJsonParser) {
30
+ rawMiddlewares.push(json());
31
+ }
32
+ if (!endPoint.config?.disableUrlEncodedParser) {
33
+ rawMiddlewares.push(urlencoded({ extended: true }));
34
+ }
35
+ expressApp[method](route, ...rawMiddlewares, async (req, res) => {
25
36
  const requestContainer = container.createChildContainer();
37
+ requestContainer.register(EXPRESS_REQ, { useValue: req });
38
+ requestContainer.register(EXPRESS_RES, { useValue: req });
26
39
  try {
27
40
  const middlewares = endPoint.middlewares.map((x) => requestContainer.resolve(x.middlewareConstructor));
28
41
  for (const middleware of middlewares) {
@@ -670,11 +670,13 @@ declare class ExpressProvider {
670
670
  private createExpress;
671
671
  }
672
672
 
673
- interface IGetConfig {
673
+ interface IEndPointConfig {
674
674
  path?: string;
675
+ disableJsonParser?: boolean;
676
+ disableUrlEncodedParser?: boolean;
675
677
  }
676
678
 
677
- declare function get(config?: string | IGetConfig): (target: object, propertyKey: string | symbol) => void;
679
+ declare function get(config?: string | IEndPointConfig): (target: object, propertyKey: string | symbol) => void;
678
680
 
679
681
  interface IMiddleware {
680
682
  handle(req: Request, res: Response, container: DependencyContainer$1): Promise<void>;
@@ -682,11 +684,7 @@ interface IMiddleware {
682
684
 
683
685
  declare function middleware(middlewareConstructor: IConstructor<IMiddleware>): (target: object, propertyKey: string | symbol) => void;
684
686
 
685
- interface IPostConfig {
686
- path?: string;
687
- }
688
-
689
- declare function post(config?: string | IPostConfig): (target: object, propertyKey: string | symbol) => void;
687
+ declare function post(config?: string | IEndPointConfig): (target: object, propertyKey: string | symbol) => void;
690
688
 
691
689
  interface IRestControllerConfig {
692
690
  path: string;
@@ -696,7 +694,7 @@ declare function restController(config: string | IRestControllerConfig): (target
696
694
 
697
695
  interface IEndPointMetadata {
698
696
  method: 'get' | 'post';
699
- path?: string;
697
+ config?: IEndPointConfig;
700
698
  controllerConstructor: IConstructor<any>;
701
699
  functionName: string;
702
700
  paramsTypes: any[];
@@ -724,7 +722,7 @@ declare class RestControllerMetadataStore {
724
722
  middlewares: IMiddlewareMetadata[];
725
723
  controller: IRestControllerMetadata;
726
724
  method: "get" | "post";
727
- path?: string;
725
+ config?: IEndPointConfig;
728
726
  controllerConstructor: IConstructor<any>;
729
727
  functionName: string;
730
728
  paramsTypes: any[];
@@ -739,6 +737,9 @@ declare class Auth<D extends IStorableData> {
739
737
  assign(authInfo: D): void;
740
738
  }
741
739
 
740
+ declare const EXPRESS_REQ = "EXPRESS_REQ";
741
+ declare const EXPRESS_RES = "EXPRESS_RES";
742
+
742
743
  declare class SocketServerProvider {
743
744
  private httpServerProvider;
744
745
  private socketServer;
@@ -1305,4 +1306,4 @@ interface IValidateMaxOptions {
1305
1306
  }
1306
1307
  declare function validateMax(value: any, options: IValidateMaxOptions): IValidationResult<any>;
1307
1308
 
1308
- export { Async, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, ClaudeChatAdapter, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatAdapter, Entity, Env, EnvWhatsAppRepository, ExpressProvider, GeminiChatAdapter, HtmlModule, HttpServerProvider, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMessage, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemReq, type IChatAdapterNextItemRes, type IChatBot, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatItem, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConstructor, type ICrudRepository, type ICustomErrorData, type IEndPointMetadata, type IEntityData, type IEnvType, type IFunctionCall, type IFunctionCallItem, type IGetConfig, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IHumanMessageItem, type IJobData, type IJobEvent, type IJobEventListener, type IJobRepository, type IJwtRefreshTokenData, type ILanguageModelUsage, 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 IMindsetTool, type IMindsetToolParameter, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, type IPostConfig, type IPrimitive, type IPropertyValidatorInfo, type IReceivedMessage, type IRestControllerConfig, type IRestControllerMetadata, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type IStorableData, type ITelegramChannelConfig, type IValidateArrayOptions, type IValidateArrayOptionsWithItemsValidators, 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, 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, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatAdapter, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgJobRepository, PgRepositoryBase, PgWhatsAppRepository, RamChatMemory, RamChatRepository, Random, RestControllerMetadataStore, SocketChannel, SocketChannelConfig, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, ValidationMetadataStore, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, chatItemTypeOptions, cmd, command, commandHandler, container, get, inject, injectable, isArray, isBoolean, isDate, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, jwtGuard, max, middleware, min, mindset, mindsetFunction, mindsetModule, modelInfo, param, post, restController, runAsyncCommandHandlers, runChatControllers, runRestControllers, scoped, singleton, socket, telegram, validate, validateArray, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsapp };
1309
+ export { Async, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, ClaudeChatAdapter, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatAdapter, EXPRESS_REQ, EXPRESS_RES, Entity, Env, EnvWhatsAppRepository, ExpressProvider, GeminiChatAdapter, HtmlModule, HttpServerProvider, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMessage, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemReq, type IChatAdapterNextItemRes, type IChatBot, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatItem, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConstructor, type ICrudRepository, type ICustomErrorData, type IEndPointConfig, type IEndPointMetadata, type IEntityData, type IEnvType, type IFunctionCall, type IFunctionCallItem, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IHumanMessageItem, type IJobData, type IJobEvent, type IJobEventListener, type IJobRepository, type IJwtRefreshTokenData, type ILanguageModelUsage, 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 IMindsetTool, type IMindsetToolParameter, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, type IPrimitive, type IPropertyValidatorInfo, type IReceivedMessage, type IRestControllerConfig, type IRestControllerMetadata, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type IStorableData, type ITelegramChannelConfig, type IValidateArrayOptions, type IValidateArrayOptionsWithItemsValidators, 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, 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, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatAdapter, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgJobRepository, PgRepositoryBase, PgWhatsAppRepository, RamChatMemory, RamChatRepository, Random, RestControllerMetadataStore, SocketChannel, SocketChannelConfig, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, ValidationMetadataStore, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, chatItemTypeOptions, cmd, command, commandHandler, container, get, inject, injectable, isArray, isBoolean, isDate, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, jwtGuard, max, middleware, min, mindset, mindsetFunction, mindsetModule, modelInfo, param, post, restController, runAsyncCommandHandlers, runChatControllers, runRestControllers, scoped, singleton, socket, telegram, validate, validateArray, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsapp };
package/dist/src/index.js CHANGED
@@ -57,6 +57,7 @@ export { restController } from './feature/rest-controller/metadata/@restControll
57
57
  export { RestControllerMetadataStore } from './feature/rest-controller/metadata/RestControllerMetadataStore.js';
58
58
  export { runRestControllers } from './feature/rest-controller/runRestControllers.js';
59
59
  export { Auth } from './feature/rest-controller/auth/Auth.js';
60
+ export { EXPRESS_REQ, EXPRESS_RES } from './feature/rest-controller/injection-tokens.js';
60
61
  export { SocketServerProvider } from './feature/socket/SocketServerProvider.js';
61
62
  export { PgJobRepository } from './addon/async/pg/PgJobRepository.js';
62
63
  export { ClaudeChatAdapter } from './addon/chat-bot/claude/ClaudeChatAdapter.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wabot-dev/framework",
3
- "version": "0.1.0-beta.36",
3
+ "version": "0.1.0-beta.38",
4
4
  "description": "Framework for IA Chat Bots",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",