@wabot-dev/framework 0.1.0-beta.10 → 0.1.0-beta.11
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/channels/whatsapp/WhatsAppSender.js +2 -0
- package/dist/src/error/CustomError.js +13 -0
- package/dist/src/index.d.ts +2 -4
- package/dist/src/index.js +1 -2
- package/dist/src/repository/pg/PgCrudRepository.js +5 -1
- package/dist/src/rest-controller/runRestControllers.js +18 -7
- package/dist/src/validation/{validateModel2.js → validate.js} +2 -2
- package/package.json +1 -1
- package/dist/src/validation/metadata/@validable.js +0 -14
|
@@ -22,6 +22,7 @@ class WhatsAppSender {
|
|
|
22
22
|
}
|
|
23
23
|
catch (error) {
|
|
24
24
|
this.logger.error(`Error sending WhatsApp message: ${error}`);
|
|
25
|
+
throw new Error(`Error sending WhatsApp message: ${error}`, { cause: error });
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
async sendWhatsAppTemplate(request, options) {
|
|
@@ -34,6 +35,7 @@ class WhatsAppSender {
|
|
|
34
35
|
}
|
|
35
36
|
catch (error) {
|
|
36
37
|
this.logger.error(`Error sending WhatsApp message: ${error}`);
|
|
38
|
+
throw new Error(`Error sending WhatsApp message: ${error}`, { cause: error });
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
async getWhatsAppTemplate(request) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class CustomError extends Error {
|
|
2
|
+
humanMessage;
|
|
3
|
+
code;
|
|
4
|
+
httpCode;
|
|
5
|
+
constructor(data) {
|
|
6
|
+
super(data.message, { cause: data.cause });
|
|
7
|
+
this.humanMessage = data.humanMessage;
|
|
8
|
+
this.code = data.code;
|
|
9
|
+
this.httpCode = data.httpCode;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { CustomError };
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1046,8 +1046,6 @@ declare function max(limit: any): (target: object, propertyKey: string | symbol)
|
|
|
1046
1046
|
|
|
1047
1047
|
declare function min(limit: any): (target: object, propertyKey: string | symbol) => void;
|
|
1048
1048
|
|
|
1049
|
-
declare function validable<A>(): (target: IConstructor<A>) => void;
|
|
1050
|
-
|
|
1051
1049
|
interface IValidationError {
|
|
1052
1050
|
description: string;
|
|
1053
1051
|
}
|
|
@@ -1119,6 +1117,6 @@ declare function validateIsPresent(value: any): IValidationResult<any>;
|
|
|
1119
1117
|
|
|
1120
1118
|
declare function validateModel<V>(value: any, info: IModelValidatorsInfo<V>): IModelValidationResult<V>;
|
|
1121
1119
|
|
|
1122
|
-
declare function
|
|
1120
|
+
declare function validate<V>(value: any, modelConstructor: IConstructor<V>): IModelValidationResult<V>;
|
|
1123
1121
|
|
|
1124
|
-
export { AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Container, ControllerMetadataStore, DeepSeekChatBotAdapter, EmailService, 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 IConnectionChatMessage, type IConstructor, type ICrudRepository, type IEmailService, type IEndPointMetadata, type IGetConfig, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, 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 IPropertyValidatorInfo, type IReceivedMessage, type IReceivedMessageItem, type IRestControllerConfig, type IRestControllerMetadata, type IReversibleMapper, type ISendEmailRequest, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type IServerConfig, type IServerProvider, type ISocketChannelConfig, type ISocketChannelReceivedMessage, 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 IWabotEnvType, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppContact, type IWhatsAppData, type IWhatsAppMessage, type IWhatsAppMessageListener, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppWebhookPayload, type IWhatsappChannelConfig, type IchatControllerConfig, type IrunChannelProps, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, MessageContext, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatBotAdapter, OtpService, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgRepositoryBase, PgUserRepository, PgWhatsAppRepository, RamChatMemory, RamChatRepository, RamUserRepository, RegisterUserModule, RegisterUserWithEmailRequest, RestControllerMetadataStore, SendOneTimePasswordRequest, SocketChannel, SocketChannelConfig, SocketServerProvider, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, ValidationMetadataStore, WabotEnv, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, cmd, container, get, inject, injectable, isBoolean, isDate, isNotEmpty, isNumber, isOptional, isPresent, isString, max, min, mindset, mindsetFunction, mindsetModule, param, post, prepareChatContainer, restController, runChannel, runRestControllers, runServer, singleton, socket, telegram,
|
|
1122
|
+
export { AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Container, ControllerMetadataStore, DeepSeekChatBotAdapter, EmailService, 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 IConnectionChatMessage, type IConstructor, type ICrudRepository, type IEmailService, type IEndPointMetadata, type IGetConfig, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, 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 IPropertyValidatorInfo, type IReceivedMessage, type IReceivedMessageItem, type IRestControllerConfig, type IRestControllerMetadata, type IReversibleMapper, type ISendEmailRequest, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type IServerConfig, type IServerProvider, type ISocketChannelConfig, type ISocketChannelReceivedMessage, 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 IWabotEnvType, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppContact, type IWhatsAppData, type IWhatsAppMessage, type IWhatsAppMessageListener, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppWebhookPayload, type IWhatsappChannelConfig, type IchatControllerConfig, type IrunChannelProps, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, MessageContext, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatBotAdapter, OtpService, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgRepositoryBase, PgUserRepository, PgWhatsAppRepository, RamChatMemory, RamChatRepository, RamUserRepository, RegisterUserModule, RegisterUserWithEmailRequest, RestControllerMetadataStore, SendOneTimePasswordRequest, SocketChannel, SocketChannelConfig, SocketServerProvider, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, ValidationMetadataStore, WabotEnv, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, cmd, container, get, inject, injectable, isBoolean, isDate, isNotEmpty, isNumber, isOptional, isPresent, isString, max, min, mindset, mindsetFunction, mindsetModule, param, post, prepareChatContainer, restController, runChannel, runRestControllers, runServer, singleton, socket, telegram, validate, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsapp };
|
package/dist/src/index.js
CHANGED
|
@@ -87,7 +87,6 @@ export { isPresent } from './validation/metadata/@isPresent.js';
|
|
|
87
87
|
export { isString } from './validation/metadata/@isString.js';
|
|
88
88
|
export { max } from './validation/metadata/@max.js';
|
|
89
89
|
export { min } from './validation/metadata/@min.js';
|
|
90
|
-
export { validable } from './validation/metadata/@validable.js';
|
|
91
90
|
export { ValidationMetadataStore } from './validation/metadata/ValidationMetadataStore.js';
|
|
92
91
|
export { validateIsBoolean } from './validation/validators/validateIsBoolean.js';
|
|
93
92
|
export { validateIsDate } from './validation/validators/validateIsDate.js';
|
|
@@ -98,5 +97,5 @@ export { validateMax } from './validation/validators/validateMax.js';
|
|
|
98
97
|
export { validateMin } from './validation/validators/validateMin.js';
|
|
99
98
|
export { validateIsPresent } from './validation/validators/validateIsPresent.js';
|
|
100
99
|
export { validateModel } from './validation/validators/validateModel.js';
|
|
101
|
-
export {
|
|
100
|
+
export { validate } from './validation/validate.js';
|
|
102
101
|
export { Container } from './injection/Container.js';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as shortUUID from 'short-uuid';
|
|
2
2
|
import { PgRepositoryBase } from './PgRepositoryBase.js';
|
|
3
|
+
import { CustomError } from '../../error/CustomError.js';
|
|
3
4
|
|
|
4
5
|
class PgCrudRepository extends PgRepositoryBase {
|
|
5
6
|
config;
|
|
@@ -20,7 +21,10 @@ class PgCrudRepository extends PgRepositoryBase {
|
|
|
20
21
|
async findOrThrow(id) {
|
|
21
22
|
const item = await this.find(id);
|
|
22
23
|
if (!item) {
|
|
23
|
-
throw new
|
|
24
|
+
throw new CustomError({
|
|
25
|
+
message: `Not found ${this.config.constructor.name} with id = '${id}'}`,
|
|
26
|
+
httpCode: 404,
|
|
27
|
+
});
|
|
24
28
|
}
|
|
25
29
|
return item;
|
|
26
30
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import '../injection/index.js';
|
|
2
|
-
import { RestControllerMetadataStore } from './metadata/RestControllerMetadataStore.js';
|
|
3
1
|
import '../controller/channel/ChatResolver.js';
|
|
4
2
|
import '../controller/channel/UserResolver.js';
|
|
3
|
+
import '../injection/index.js';
|
|
5
4
|
import '../controller/metadata/ControllerMetadataStore.js';
|
|
6
5
|
import '../channels/cmd/CmdChannel.js';
|
|
7
6
|
import { ExpressProvider } from '../channels/express/ExpressProvider.js';
|
|
@@ -19,8 +18,11 @@ import '../channels/whatsapp/WhatsAppSenderByDevConnection.js';
|
|
|
19
18
|
import '../channels/whatsapp/WhatsAppSenderByCloudApi.js';
|
|
20
19
|
import '../channels/whatsapp/PgWhatsAppRepository.js';
|
|
21
20
|
import '../channels/whatsapp/EnvWhatsAppRepository.js';
|
|
22
|
-
import path from 'path';
|
|
23
21
|
import { Logger } from '../logger/Logger.js';
|
|
22
|
+
import '../validation/metadata/ValidationMetadataStore.js';
|
|
23
|
+
import { validate } from '../validation/validate.js';
|
|
24
|
+
import path from 'path';
|
|
25
|
+
import { RestControllerMetadataStore } from './metadata/RestControllerMetadataStore.js';
|
|
24
26
|
|
|
25
27
|
function buildRequest(req) {
|
|
26
28
|
return Object.assign({}, req.body, req.query, req.params);
|
|
@@ -47,9 +49,8 @@ function runRestControllers(controllers, container) {
|
|
|
47
49
|
throw new Error(`Cant determine de parameter ${paramIndex} value`);
|
|
48
50
|
}
|
|
49
51
|
defaultArgFound = true;
|
|
50
|
-
if (typeof paramType === 'function'
|
|
51
|
-
const { value, error } =
|
|
52
|
-
debugger;
|
|
52
|
+
if (typeof paramType === 'function') {
|
|
53
|
+
const { value, error } = validate(buildRequest(req), paramType);
|
|
53
54
|
if (error) {
|
|
54
55
|
res.status(400).json({ error });
|
|
55
56
|
return;
|
|
@@ -62,7 +63,17 @@ function runRestControllers(controllers, container) {
|
|
|
62
63
|
res.status(200).json(response);
|
|
63
64
|
}
|
|
64
65
|
catch (err) {
|
|
65
|
-
|
|
66
|
+
if (err instanceof Error) {
|
|
67
|
+
const keys = Object.keys(err).filter((key) => !['message', 'stack'].includes(key));
|
|
68
|
+
const info = keys.reduce((acc, key) => {
|
|
69
|
+
acc[key] = err[key];
|
|
70
|
+
return acc;
|
|
71
|
+
}, {});
|
|
72
|
+
res.status(500).json({ error: { message: err.message, stack: err.stack, ...info } });
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
res.status(500).json({ error: { message: 'Unknown error' } });
|
|
76
|
+
}
|
|
66
77
|
}
|
|
67
78
|
requestContainer.dispose();
|
|
68
79
|
});
|
|
@@ -2,10 +2,10 @@ import { container } from '../injection/index.js';
|
|
|
2
2
|
import { ValidationMetadataStore } from './metadata/ValidationMetadataStore.js';
|
|
3
3
|
import { validateModel } from './validators/validateModel.js';
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function validate(value, modelConstructor) {
|
|
6
6
|
const metadataStore = container.resolve(ValidationMetadataStore);
|
|
7
7
|
const info = metadataStore.getModelValidatorsInfo(modelConstructor);
|
|
8
8
|
return validateModel(value, info);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export {
|
|
11
|
+
export { validate };
|
package/package.json
CHANGED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { container } from 'tsyringe';
|
|
2
|
-
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
3
|
-
import { validateModel } from '../validators/validateModel.js';
|
|
4
|
-
|
|
5
|
-
function validable() {
|
|
6
|
-
return function (target) {
|
|
7
|
-
target.__validate__ = function (value) {
|
|
8
|
-
const info = container.resolve(ValidationMetadataStore).getModelValidatorsInfo(target);
|
|
9
|
-
return validateModel(value, info);
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { validable };
|