@wabot-dev/framework 0.1.0-beta.56 → 0.1.0-beta.57

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.
@@ -1,4 +1,9 @@
1
+ import { ApiKey } from './ApiKey.js';
2
+
1
3
  class ApiKeyRepository {
4
+ findAuthInfo(secret) {
5
+ throw new Error('Method not implemented.');
6
+ }
2
7
  find(id) {
3
8
  throw new Error('Method not implemented.');
4
9
  }
@@ -8,6 +13,23 @@ class ApiKeyRepository {
8
13
  create(item) {
9
14
  throw new Error('Method not implemented.');
10
15
  }
16
+ generate(req) {
17
+ throw new Error('Method not implemented.');
18
+ }
19
+ static async generate(repository, req) {
20
+ const apiKey = new ApiKey(req);
21
+ const pass = apiKey.generatePassword();
22
+ await repository.create(apiKey);
23
+ const id = apiKey.id;
24
+ const secret = ApiKey.deflate({ id, pass });
25
+ return { id, secret };
26
+ }
27
+ static async findAuthInfo(repository, secret) {
28
+ const { id, pass } = ApiKey.inflate(secret);
29
+ const apiKey = await repository.findOrThrow(id);
30
+ apiKey.validatePassword(pass);
31
+ return apiKey.authInfo;
32
+ }
11
33
  }
12
34
 
13
35
  export { ApiKeyRepository };
@@ -3,6 +3,7 @@ import { ApiKey } from './ApiKey.js';
3
3
  import { Pool } from 'pg';
4
4
  import { PgCrudRepository } from '../../../feature/pg/PgCrudRepository.js';
5
5
  import { singleton } from 'tsyringe';
6
+ import { ApiKeyRepository } from './ApiKeyRepository.js';
6
7
 
7
8
  let PgApiKeyRepository = class PgApiKeyRepository extends PgCrudRepository {
8
9
  constructor(pool) {
@@ -12,6 +13,12 @@ let PgApiKeyRepository = class PgApiKeyRepository extends PgCrudRepository {
12
13
  constructor: ApiKey,
13
14
  });
14
15
  }
16
+ findAuthInfo(secret) {
17
+ return ApiKeyRepository.findAuthInfo(this, secret);
18
+ }
19
+ async generate(req) {
20
+ return ApiKeyRepository.generate(this, req);
21
+ }
15
22
  };
16
23
  PgApiKeyRepository = __decorate([
17
24
  singleton(),
@@ -0,0 +1,42 @@
1
+ import { ApiKeyRepository } from './ApiKeyRepository.js';
2
+
3
+ class RemoteApiKeyRepository {
4
+ fetcher;
5
+ cacheSeconds;
6
+ cache = new Map();
7
+ constructor(fetcher, cacheSeconds) {
8
+ this.fetcher = fetcher;
9
+ this.cacheSeconds = cacheSeconds;
10
+ }
11
+ async find(id) {
12
+ const now = Date.now();
13
+ const cached = this.cache.get(id);
14
+ if (cached && cached.expiresAt > now) {
15
+ return cached.value;
16
+ }
17
+ const result = await this.fetcher(id);
18
+ this.cache.set(id, {
19
+ value: result,
20
+ expiresAt: now + this.cacheSeconds * 1000,
21
+ });
22
+ return result;
23
+ }
24
+ async findOrThrow(id) {
25
+ const result = await this.find(id);
26
+ if (!result) {
27
+ throw new Error(`API key with ID '${id}' not found.`);
28
+ }
29
+ return result;
30
+ }
31
+ findAuthInfo(secret) {
32
+ return ApiKeyRepository.findAuthInfo(this, secret);
33
+ }
34
+ create(item) {
35
+ throw new Error('Method not implemented.');
36
+ }
37
+ async generate(req) {
38
+ throw new Error('Method not implemented.');
39
+ }
40
+ }
41
+
42
+ export { RemoteApiKeyRepository };
@@ -983,6 +983,7 @@ declare function apiKeyGuard(): (target: object, propertyKey: string | symbol) =
983
983
  interface IApiKeyData<A extends IStorableData> extends IEntityData {
984
984
  passwordHash?: string;
985
985
  authInfo: A;
986
+ name: string;
986
987
  }
987
988
  declare class ApiKey<A extends IStorableData> extends Entity<IApiKeyData<A>> {
988
989
  get authInfo(): A;
@@ -1004,12 +1005,29 @@ interface IApiKeyRepository<A extends IStorableData> {
1004
1005
  find(id: string): Promise<ApiKey<A> | null>;
1005
1006
  findOrThrow(id: string): Promise<ApiKey<A>>;
1006
1007
  create(item: ApiKey<A>): Promise<void>;
1008
+ generate(req: IGenerateApiKeyReq<A>): Promise<IGenerateApiKeyRes>;
1009
+ findAuthInfo(secret: string): Promise<A>;
1010
+ }
1011
+ interface IGenerateApiKeyReq<A extends IStorableData> extends IStorableData {
1012
+ name: string;
1013
+ authInfo: A;
1014
+ }
1015
+ interface IGenerateApiKeyRes {
1016
+ id: string;
1017
+ secret: string;
1007
1018
  }
1008
1019
 
1009
1020
  declare class ApiKeyRepository<A extends IStorableData> implements IApiKeyRepository<A> {
1021
+ findAuthInfo(secret: string): Promise<A>;
1010
1022
  find(id: string): Promise<ApiKey<A> | null>;
1011
1023
  findOrThrow(id: string): Promise<ApiKey<A>>;
1012
1024
  create(item: ApiKey<A>): Promise<void>;
1025
+ generate(req: IGenerateApiKeyReq<A>): Promise<IGenerateApiKeyRes>;
1026
+ static generate(repository: ApiKeyRepository<any>, req: IGenerateApiKeyReq<any>): Promise<{
1027
+ id: string;
1028
+ secret: string;
1029
+ }>;
1030
+ static findAuthInfo<A extends IStorableData>(repository: ApiKeyRepository<A>, secret: string): Promise<A>;
1013
1031
  }
1014
1032
 
1015
1033
  declare class ApiKeyGuardMiddleware implements IMiddleware {
@@ -1021,6 +1039,20 @@ declare class ApiKeyGuardMiddleware implements IMiddleware {
1021
1039
 
1022
1040
  declare class PgApiKeyRepository<A extends IStorableData> extends PgCrudRepository<ApiKey<A>> implements IApiKeyRepository<A> {
1023
1041
  constructor(pool: Pool);
1042
+ findAuthInfo(secret: string): Promise<A>;
1043
+ generate(req: IGenerateApiKeyReq<A>): Promise<IGenerateApiKeyRes>;
1044
+ }
1045
+
1046
+ declare class RemoteApiKeyRepository<A extends IStorableData> implements IApiKeyRepository<A> {
1047
+ private fetcher;
1048
+ private cacheSeconds;
1049
+ private cache;
1050
+ constructor(fetcher: (id: string) => Promise<ApiKey<A> | null>, cacheSeconds: number);
1051
+ find(id: string): Promise<ApiKey<A> | null>;
1052
+ findOrThrow(id: string): Promise<ApiKey<A>>;
1053
+ findAuthInfo(secret: string): Promise<A>;
1054
+ create(item: ApiKey<A>): Promise<void>;
1055
+ generate(req: IGenerateApiKeyReq<A>): Promise<IGenerateApiKeyRes>;
1024
1056
  }
1025
1057
 
1026
1058
  declare function jwtConnectionGuard(): (target: object, propertyKey: string | symbol) => void;
@@ -1557,4 +1589,4 @@ declare function HtmlModule(options: IHtmlModuleOptions): {
1557
1589
  new (): {};
1558
1590
  };
1559
1591
 
1560
- 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 };
1592
+ 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 IGenerateApiKeyReq, type IGenerateApiKeyRes, 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, RemoteApiKeyRepository, 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
@@ -94,6 +94,7 @@ export { ApiKey } from './addon/auth/api-key/ApiKey.js';
94
94
  export { ApiKeyGuardMiddleware } from './addon/auth/api-key/ApiKeyGuardMiddleware.js';
95
95
  export { ApiKeyRepository } from './addon/auth/api-key/ApiKeyRepository.js';
96
96
  export { PgApiKeyRepository } from './addon/auth/api-key/PgApiKeyRepository.js';
97
+ export { RemoteApiKeyRepository } from './addon/auth/api-key/RemoteApiKeyRepository.js';
97
98
  export { jwtConnectionGuard } from './addon/auth/jwt/@jwtConnectionGuard.js';
98
99
  export { jwtGuard } from './addon/auth/jwt/@jwtGuard.js';
99
100
  export { Jwt } from './addon/auth/jwt/Jwt.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wabot-dev/framework",
3
- "version": "0.1.0-beta.56",
3
+ "version": "0.1.0-beta.57",
4
4
  "description": "Framework for IA Chat Bots",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",