@wabot-dev/framework 0.1.0-beta.52 → 0.1.0-beta.54

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.
@@ -4,6 +4,24 @@ const DIGITS = '0123456789';
4
4
  const ALPHA_NUMERIC_CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
5
5
  const ALPHA_NUMERIC_LOWER_CASE_CHARSET = 'abcdefghijklmnopqrstuvwxyz0123456789';
6
6
  class Random {
7
+ static integer(options) {
8
+ const { min, max } = options;
9
+ if (min > max) {
10
+ throw new RangeError('min must be less than or equal to max');
11
+ }
12
+ const range = max - min + 1;
13
+ if (range <= 0) {
14
+ throw new RangeError('Range must be a positive number');
15
+ }
16
+ const byteSize = 6; // gives us up to 2^48
17
+ const maxGeneratedValue = Math.pow(2, byteSize * 8) - 1;
18
+ const maxAcceptable = maxGeneratedValue - (maxGeneratedValue % range);
19
+ let randomNumber;
20
+ do {
21
+ randomNumber = parseInt(randomBytes(byteSize).toString('hex'), 16);
22
+ } while (randomNumber >= maxAcceptable);
23
+ return min + (randomNumber % range);
24
+ }
7
25
  static slug(name, options) {
8
26
  const base = name
9
27
  .toLowerCase()
@@ -0,0 +1,7 @@
1
+ import { methodDecorator } from './methodDecorator.js';
2
+
3
+ function onDelete(config) {
4
+ return methodDecorator('delete', config);
5
+ }
6
+
7
+ export { onDelete };
@@ -0,0 +1,7 @@
1
+ import { methodDecorator } from './methodDecorator.js';
2
+
3
+ function onGet(config) {
4
+ return methodDecorator('get', config);
5
+ }
6
+
7
+ export { onGet };
@@ -0,0 +1,7 @@
1
+ import { methodDecorator } from './methodDecorator.js';
2
+
3
+ function onPost(config) {
4
+ return methodDecorator('post', config);
5
+ }
6
+
7
+ export { onPost };
@@ -0,0 +1,7 @@
1
+ import { methodDecorator } from './methodDecorator.js';
2
+
3
+ function onPut(config) {
4
+ return methodDecorator('put', config);
5
+ }
6
+
7
+ export { onPut };
@@ -1,14 +1,14 @@
1
1
  import { container } from '../../../core/injection/index.js';
2
2
  import { RestControllerMetadataStore } from './RestControllerMetadataStore.js';
3
3
 
4
- function get(config) {
4
+ function methodDecorator(method, config) {
5
5
  return function (target, propertyKey) {
6
6
  const functionName = propertyKey.toString();
7
7
  const paramsTypes = Reflect.getMetadata('design:paramtypes', target, functionName);
8
8
  const store = container.resolve(RestControllerMetadataStore);
9
9
  store.saveEndPointMetadata({
10
10
  controllerConstructor: target.constructor,
11
- method: 'get',
11
+ method,
12
12
  config: typeof config === 'string' ? { path: config } : config,
13
13
  functionName,
14
14
  paramsTypes,
@@ -16,4 +16,4 @@ function get(config) {
16
16
  };
17
17
  }
18
18
 
19
- export { get };
19
+ export { methodDecorator };
@@ -146,6 +146,10 @@ declare class Password {
146
146
  }
147
147
 
148
148
  declare class Random {
149
+ static integer(options: {
150
+ min: number;
151
+ max: number;
152
+ }): number;
149
153
  static slug(name: string, options: {
150
154
  randomLength: number;
151
155
  }): string;
@@ -825,7 +829,7 @@ interface IEndPointConfig {
825
829
  disableUrlEncodedParser?: boolean;
826
830
  }
827
831
 
828
- declare function get(config?: string | IEndPointConfig): (target: object, propertyKey: string | symbol) => void;
832
+ declare function onGet(config?: string | IEndPointConfig): (target: object, propertyKey: string | symbol) => void;
829
833
 
830
834
  interface IMiddleware {
831
835
  handle(req: Request, res: Response, container: DependencyContainer$1): Promise<void>;
@@ -833,7 +837,11 @@ interface IMiddleware {
833
837
 
834
838
  declare function middleware(middlewareConstructor: IConstructor<IMiddleware>): (target: object, propertyKey: string | symbol) => void;
835
839
 
836
- declare function post(config?: string | IEndPointConfig): (target: object, propertyKey: string | symbol) => void;
840
+ declare function onPost(config?: string | IEndPointConfig): (target: object, propertyKey: string | symbol) => void;
841
+
842
+ declare function onPut(config?: string | IEndPointConfig): (target: object, propertyKey: string | symbol) => void;
843
+
844
+ declare function onDelete(config?: string | IEndPointConfig): (target: object, propertyKey: string | symbol) => void;
837
845
 
838
846
  interface IRestControllerConfig {
839
847
  path: string;
@@ -842,7 +850,7 @@ interface IRestControllerConfig {
842
850
  declare function restController(config: string | IRestControllerConfig): (target: IConstructor<any>) => void;
843
851
 
844
852
  interface IEndPointMetadata {
845
- method: 'get' | 'post';
853
+ method: 'get' | 'post' | 'put' | 'delete';
846
854
  config?: IEndPointConfig;
847
855
  controllerConstructor: IConstructor<any>;
848
856
  functionName: string;
@@ -870,7 +878,7 @@ declare class RestControllerMetadataStore {
870
878
  getControllerEndPointsInfo(controllerConstructor: IConstructor<any>): {
871
879
  middlewares: IMiddlewareMetadata[];
872
880
  controller: IRestControllerMetadata;
873
- method: "get" | "post";
881
+ method: "get" | "post" | "put" | "delete";
874
882
  config?: IEndPointConfig;
875
883
  controllerConstructor: IConstructor<any>;
876
884
  functionName: string;
@@ -1548,4 +1556,4 @@ declare function HtmlModule(options: IHtmlModuleOptions): {
1548
1556
  new (): {};
1549
1557
  };
1550
1558
 
1551
- export { AnthropicChatAdapter, ApiKey, ApiKeyGuardMiddleware, ApiKeyRepository, Async, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatAdapter, EXPRESS_REQ, EXPRESS_RES, Entity, Env, EnvWhatsAppRepository, ExpressProvider, GoogleChatAdapter, HtmlModule, HttpServerProvider, type IApiKeyData, type IApiKeyRepository, 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 IConnectionMiddleware, type IConnectionMiddlewareMetadata, 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 IJwtRefreshTokenRepository, type ILanguageModelUsage, type IListenWhatsAppMessageRequest, type IMessageContext, type IMiddleware, type IMiddlewareMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetLlm, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IMindsetTool, type IMindsetToolParameter, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IMoneyData, 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 ISocketConnectionConfig, type ISocketConnectionMetadata, type ISocketControllerConfig, type ISocketControllerMetadata, type ISocketEventConfig, type ISocketEventMetadata, 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 IWhatsAppCloudContact, type IWhatsAppCloudMessage, type IWhatsAppCloudMessageMetadata, type IWhatsAppCloudTemplate, type IWhatsAppCloudTemplateComponent, type IWhatsAppCloudTemplateMessage, type IWhatsAppCloudTemplateParameter, type IWhatsAppCloudTemplateResponse, type IWhatsAppCloudWebhookPayload, type IWhatsAppData, type IWhatsAppMessageListener, type IWhatsAppProxyListenMessageEventData, type IWhatsAppProxyListenMessageEventReq, type IWhatsAppProxyMessage, type IWhatsAppProxyMessageContent, type IWhatsAppProxyMessageEventReq, type IWhatsAppProxySendMessageEventReq, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsappChannelConfig, type IchatControllerConfig, Job, JobRepository, JobRunner, JobsEventsHub, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtConnectionGuardMiddleware, JwtGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, Mapper, Mindset, MindsetMetadataStore, MindsetOperator, Money, MoneyDto, OpenaiChatAdapter, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Password, type PasswordHashOptions, Persistent, PgApiKeyRepository, PgChatMemory, PgChatRepository, PgCrudRepository, PgJobRepository, PgJwtRefreshTokenRepository, PgRepositoryBase, PgWhatsAppRepository, RamChatMemory, RamChatRepository, Random, RestControllerMetadataStore, SocketChannel, SocketChannelConfig, SocketControllerMetadataStore, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, ValidationMetadataStore, WHATSAPP_MESSAGE_EVENT, WHATSAPP_PROXY_LISTEN_MESSAGE_EVENT, WHATSAPP_PROXY_SEND_MESSAGE_EVENT, WabotChatAdapter, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByCloudApi, WhatsAppReceiverByWabotProxy, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByWabotProxy, WhatsAppWabotProxyConnection, WhatsappChannelConfig, apiKeyGuard, chatBot, chatController, chatItemTypeOptions, cmd, command, commandHandler, connectionMiddleware, container, get, inject, injectable, isArray, isBoolean, isDate, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, jwtConnectionGuard, jwtGuard, max, middleware, min, mindset, mindsetFunction, mindsetModule, modelInfo, param, post, restController, runAsyncCommandHandlers, runChatControllers, runRestControllers, runSocketControllers, scoped, singleton, socket, socketConnection, socketController, socketEvent, telegram, validate, validateArray, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsApp };
1559
+ export { AnthropicChatAdapter, ApiKey, ApiKeyGuardMiddleware, ApiKeyRepository, Async, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatAdapter, EXPRESS_REQ, EXPRESS_RES, Entity, Env, EnvWhatsAppRepository, ExpressProvider, GoogleChatAdapter, HtmlModule, HttpServerProvider, type IApiKeyData, type IApiKeyRepository, 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 IConnectionMiddleware, type IConnectionMiddlewareMetadata, 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 IJwtRefreshTokenRepository, type ILanguageModelUsage, type IListenWhatsAppMessageRequest, type IMessageContext, type IMiddleware, type IMiddlewareMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetLlm, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IMindsetTool, type IMindsetToolParameter, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IMoneyData, 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 ISocketConnectionConfig, type ISocketConnectionMetadata, type ISocketControllerConfig, type ISocketControllerMetadata, type ISocketEventConfig, type ISocketEventMetadata, 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 IWhatsAppCloudContact, type IWhatsAppCloudMessage, type IWhatsAppCloudMessageMetadata, type IWhatsAppCloudTemplate, type IWhatsAppCloudTemplateComponent, type IWhatsAppCloudTemplateMessage, type IWhatsAppCloudTemplateParameter, type IWhatsAppCloudTemplateResponse, type IWhatsAppCloudWebhookPayload, type IWhatsAppData, type IWhatsAppMessageListener, type IWhatsAppProxyListenMessageEventData, type IWhatsAppProxyListenMessageEventReq, type IWhatsAppProxyMessage, type IWhatsAppProxyMessageContent, type IWhatsAppProxyMessageEventReq, type IWhatsAppProxySendMessageEventReq, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsappChannelConfig, type IchatControllerConfig, Job, JobRepository, JobRunner, JobsEventsHub, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtConnectionGuardMiddleware, JwtGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, Mapper, Mindset, MindsetMetadataStore, MindsetOperator, Money, MoneyDto, OpenaiChatAdapter, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Password, type PasswordHashOptions, Persistent, PgApiKeyRepository, PgChatMemory, PgChatRepository, PgCrudRepository, PgJobRepository, PgJwtRefreshTokenRepository, PgRepositoryBase, PgWhatsAppRepository, RamChatMemory, RamChatRepository, Random, RestControllerMetadataStore, SocketChannel, SocketChannelConfig, SocketControllerMetadataStore, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, ValidationMetadataStore, WHATSAPP_MESSAGE_EVENT, WHATSAPP_PROXY_LISTEN_MESSAGE_EVENT, WHATSAPP_PROXY_SEND_MESSAGE_EVENT, WabotChatAdapter, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByCloudApi, WhatsAppReceiverByWabotProxy, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByWabotProxy, WhatsAppWabotProxyConnection, WhatsappChannelConfig, apiKeyGuard, chatBot, chatController, chatItemTypeOptions, cmd, command, commandHandler, connectionMiddleware, container, inject, injectable, isArray, isBoolean, isDate, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, jwtConnectionGuard, jwtGuard, max, middleware, min, mindset, mindsetFunction, mindsetModule, modelInfo, onDelete, onGet, onPost, onPut, param, restController, runAsyncCommandHandlers, runChatControllers, runRestControllers, runSocketControllers, scoped, singleton, socket, socketConnection, socketController, socketEvent, telegram, validate, validateArray, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsApp };
package/dist/src/index.js CHANGED
@@ -72,9 +72,11 @@ export { Money } from './feature/money/Money.js';
72
72
  export { MoneyDto } from './feature/money/MoneyDto.js';
73
73
  export { PgCrudRepository } from './feature/pg/PgCrudRepository.js';
74
74
  export { PgRepositoryBase } from './feature/pg/PgRepositoryBase.js';
75
- export { get } from './feature/rest-controller/metadata/@get.js';
75
+ export { onGet } from './feature/rest-controller/metadata/@onGet.js';
76
76
  export { middleware } from './feature/rest-controller/metadata/@middleware.js';
77
- export { post } from './feature/rest-controller/metadata/@post.js';
77
+ export { onPost } from './feature/rest-controller/metadata/@onPost.js';
78
+ export { onPut } from './feature/rest-controller/metadata/@onPut.js';
79
+ export { onDelete } from './feature/rest-controller/metadata/@onDelete.js';
78
80
  export { restController } from './feature/rest-controller/metadata/@restController.js';
79
81
  export { RestControllerMetadataStore } from './feature/rest-controller/metadata/RestControllerMetadataStore.js';
80
82
  export { runRestControllers } from './feature/rest-controller/runRestControllers.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wabot-dev/framework",
3
- "version": "0.1.0-beta.52",
3
+ "version": "0.1.0-beta.54",
4
4
  "description": "Framework for IA Chat Bots",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -1,19 +0,0 @@
1
- import { container } from '../../../core/injection/index.js';
2
- import { RestControllerMetadataStore } from './RestControllerMetadataStore.js';
3
-
4
- function post(config) {
5
- return function (target, propertyKey) {
6
- const functionName = propertyKey.toString();
7
- const paramsTypes = Reflect.getMetadata('design:paramtypes', target, functionName);
8
- const store = container.resolve(RestControllerMetadataStore);
9
- store.saveEndPointMetadata({
10
- controllerConstructor: target.constructor,
11
- method: 'post',
12
- config: typeof config === 'string' ? { path: config } : config,
13
- functionName,
14
- paramsTypes,
15
- });
16
- };
17
- }
18
-
19
- export { post };