@wabot-dev/framework 0.1.0-beta.37 → 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.
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppReceiverByWebHook.js +3 -2
- package/dist/src/addon/rest-controller/jwt/@jwtGuard.js +3 -2
- package/dist/src/addon/rest-controller/jwt/Jwt.js +3 -2
- package/dist/src/addon/rest-controller/jwt/JwtGuardMiddleware.js +3 -2
- package/dist/src/feature/express/ExpressProvider.js +0 -2
- package/dist/src/feature/rest-controller/metadata/@get.js +2 -2
- package/dist/src/feature/rest-controller/metadata/@post.js +2 -2
- package/dist/src/feature/rest-controller/runRestControllers.js +16 -6
- package/dist/src/index.d.ts +8 -10
- package/package.json +1 -1
|
@@ -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', () => {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
12
|
+
config: typeof config === 'string' ? { path: config } : config,
|
|
13
|
+
functionName,
|
|
14
14
|
paramsTypes,
|
|
15
15
|
});
|
|
16
16
|
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import
|
|
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 {
|
|
6
|
+
import { ExpressProvider } from '../express/ExpressProvider.js';
|
|
7
|
+
import { json, urlencoded } from 'express';
|
|
8
|
+
import path from 'path';
|
|
9
9
|
import { EXPRESS_REQ, EXPRESS_RES } from './injection-tokens.js';
|
|
10
|
+
import { RestControllerMetadataStore } from './metadata/RestControllerMetadataStore.js';
|
|
10
11
|
|
|
11
12
|
function buildRequest(req) {
|
|
12
13
|
return Object.assign({}, req.body, req.query, req.params);
|
|
@@ -20,9 +21,18 @@ function runRestControllers(controllers) {
|
|
|
20
21
|
const endPoints = metadataStore.getControllerEndPointsInfo(controller);
|
|
21
22
|
endPoints.forEach((endPoint) => {
|
|
22
23
|
const method = endPoint.method;
|
|
23
|
-
const route = path
|
|
24
|
+
const route = path
|
|
25
|
+
.join(endPoint.controller.path, endPoint.config?.path ?? '')
|
|
26
|
+
.replaceAll('\\', '/');
|
|
24
27
|
logger.info(`config ${endPoint.method.toUpperCase()} ${route}`);
|
|
25
|
-
|
|
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) => {
|
|
26
36
|
const requestContainer = container.createChildContainer();
|
|
27
37
|
requestContainer.register(EXPRESS_REQ, { useValue: req });
|
|
28
38
|
requestContainer.register(EXPRESS_RES, { useValue: req });
|
package/dist/src/index.d.ts
CHANGED
|
@@ -670,11 +670,13 @@ declare class ExpressProvider {
|
|
|
670
670
|
private createExpress;
|
|
671
671
|
}
|
|
672
672
|
|
|
673
|
-
interface
|
|
673
|
+
interface IEndPointConfig {
|
|
674
674
|
path?: string;
|
|
675
|
+
disableJsonParser?: boolean;
|
|
676
|
+
disableUrlEncodedParser?: boolean;
|
|
675
677
|
}
|
|
676
678
|
|
|
677
|
-
declare function get(config?: string |
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
725
|
+
config?: IEndPointConfig;
|
|
728
726
|
controllerConstructor: IConstructor<any>;
|
|
729
727
|
functionName: string;
|
|
730
728
|
paramsTypes: any[];
|
|
@@ -1308,4 +1306,4 @@ interface IValidateMaxOptions {
|
|
|
1308
1306
|
}
|
|
1309
1307
|
declare function validateMax(value: any, options: IValidateMaxOptions): IValidationResult<any>;
|
|
1310
1308
|
|
|
1311
|
-
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 IEndPointMetadata, type IEntityData, type IEnvType, type IFunctionCall, type IFunctionCallItem, type
|
|
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 };
|