@wabot-dev/framework 0.2.6 → 0.4.0-beta.1

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.
Files changed (36) hide show
  1. package/README.md +9 -12
  2. package/dist/src/addon/async/pg/PgJobRepository.js +50 -2
  3. package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +5 -0
  4. package/dist/src/addon/auth/jwt/PgJwtRefreshTokenRepository.js +7 -2
  5. package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +15 -3
  6. package/dist/src/addon/chat-bot/pg/PgChatMemory.js +5 -0
  7. package/dist/src/addon/chat-bot/pg/PgChatRepository.js +5 -0
  8. package/dist/src/addon/chat-bot/wabot/WabotChatAdapter.js +1 -1
  9. package/dist/src/addon/chat-controller/whatsapp/PgWhatsAppRepository.js +5 -0
  10. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppReceiverByWabotProxy.js +1 -0
  11. package/dist/src/core/lock/Locker.js +7 -0
  12. package/dist/src/feature/async/@command.js +3 -3
  13. package/dist/src/feature/async/@commandHandler.js +3 -3
  14. package/dist/src/feature/async/Async.js +21 -14
  15. package/dist/src/feature/async/{CommandMetadataStore.js → AsyncMetadataStore.js} +27 -5
  16. package/dist/src/feature/async/Job.js +92 -2
  17. package/dist/src/feature/async/JobExecutor.js +62 -0
  18. package/dist/src/feature/async/JobRepository.js +9 -0
  19. package/dist/src/feature/async/JobRunner.js +17 -6
  20. package/dist/src/feature/async/JobScheduler.js +80 -0
  21. package/dist/src/feature/async/JobWatchdog.js +74 -0
  22. package/dist/src/feature/async/runCommandHandlers.js +19 -25
  23. package/dist/src/feature/chat-bot/Chat.js +3 -0
  24. package/dist/src/feature/chat-controller/runChatControllers.js +1 -1
  25. package/dist/src/feature/pg/PgCrudRepository.js +7 -1
  26. package/dist/src/feature/pg/PgLock.js +20 -0
  27. package/dist/src/feature/pg/PgLockKey.js +68 -0
  28. package/dist/src/feature/pg/PgRepositoryBase.js +40 -27
  29. package/dist/src/feature/pg/pgStorage.js +16 -0
  30. package/dist/src/feature/pg/withPgClient.js +45 -0
  31. package/dist/src/feature/pg/withPgTransaction.js +45 -0
  32. package/dist/src/index.d.ts +252 -96
  33. package/dist/src/index.js +8 -4
  34. package/package.json +8 -6
  35. package/dist/src/feature/async/Command.js +0 -9
  36. package/dist/src/feature/async/JobsEventsHub.js +0 -36
@@ -7,48 +7,55 @@ import InterceptionOptions from 'tsyringe/dist/typings/types/interceptor-options
7
7
  import { Server } from 'http';
8
8
  import { Express, Request, Response } from 'express';
9
9
  import * as big_js from 'big.js';
10
- import { Pool } from 'pg';
10
+ import { Pool, PoolClient } from 'pg';
11
+ import { AsyncLocalStorage } from 'async_hooks';
11
12
  import { Server as Server$1, Socket } from 'socket.io';
12
13
  import { Algorithm } from 'jsonwebtoken';
13
14
  import { Socket as Socket$1 } from 'socket.io-client';
14
15
 
15
- type IPrimitive = null | number | string | boolean | undefined;
16
- type IStorableData = {
17
- [key: string]: IPrimitive | IPrimitive[] | IStorableData | IStorableData[];
18
- };
19
- declare class Storable<D extends IStorableData> {
20
- protected data: D;
21
- constructor(data: D);
22
- }
16
+ type IStorablePrimitive = null | number | string | boolean | undefined;
17
+
18
+ type IStorableType<T> = T extends IStorablePrimitive ? T : T extends (...args: any[]) => any ? never : T extends Array<infer U> ? Array<IStorableType<U>> : T extends object ? {
19
+ [K in keyof T]: IStorableType<T[K]>;
20
+ } : never;
23
21
 
24
- declare class Auth<D extends IStorableData> {
22
+ declare class Auth<D> {
25
23
  private authInfo;
26
24
  private overrided;
27
- require(): D;
28
- assign(authInfo: D): void;
29
- override(authInfo: D): void;
25
+ require(): IStorableType<D>;
26
+ assign(authInfo: IStorableType<D>): void;
27
+ override(authInfo: IStorableType<D>): void;
30
28
  clear(): void;
31
29
  isAssigned(): boolean;
32
30
  wasOverrided(): boolean;
33
31
  }
34
32
 
35
- interface IEntityData extends IStorableData {
33
+ type IStorableData<O extends object> = {
34
+ [K in keyof O]: IStorableType<O[K]>;
35
+ };
36
+
37
+ declare class Storable<D extends object> {
38
+ protected data: IStorableData<D>;
39
+ constructor(data: IStorableData<D>);
40
+ }
41
+
42
+ interface IEntityData {
36
43
  id?: string;
37
44
  createdAt?: number | null;
38
45
  discardedAt?: number | null;
39
46
  }
40
47
  declare class Entity<D extends IEntityData> extends Storable<D> {
41
- get id(): string;
48
+ get id(): NonNullable<IStorableType<D["id"]>>;
42
49
  /**
43
50
  * @deprecated use id
44
51
  */
45
- getId(): string;
52
+ getId(): NonNullable<IStorableType<D["id"]>>;
46
53
  get createdAt(): Date;
47
54
  /**
48
55
  * @deprecated use createdAt
49
56
  */
50
57
  getCreatedAt(): Date;
51
- update(newData: Omit<D, 'id' | 'createdAt' | 'discardedAt'>): void;
58
+ update(newData: Partial<Omit<D, 'id' | 'createdAt' | 'discardedAt'>>): void;
52
59
  wasCreated(): boolean;
53
60
  validate(): void;
54
61
  }
@@ -334,62 +341,117 @@ declare class DescriptionMetadataStore {
334
341
  getModelDescriptions(model: IConstructor<any>): IDescriptionMetadata[];
335
342
  }
336
343
 
337
- interface ICommandConfig {
338
- name?: string;
344
+ interface ILockKey {
345
+ run<T>(fn: () => Promise<T>): Promise<T>;
346
+ tryRun<T>(fn: () => Promise<T>): Promise<T | undefined>;
339
347
  }
340
- declare function command(config?: ICommandConfig): (target: IConstructor<any>) => void;
341
348
 
342
- declare class Command<T extends IStorableData> extends Storable<T> {
343
- getData(): T;
349
+ interface ILocker {
350
+ withKey(key: string | number): ILockKey;
344
351
  }
352
+ declare class Locker implements ILocker {
353
+ withKey(key: string | number): ILockKey;
354
+ }
355
+
356
+ interface ICommandConfig {
357
+ name: string;
358
+ }
359
+ declare function command<O extends object>(config: ICommandConfig | string): (target: IConstructor<IStorableData<O>>) => void;
345
360
 
346
- interface ICommandHandler<C extends Command<any>> {
361
+ interface ICommandHandler<C extends object> {
347
362
  handle(command: C): void | Promise<void>;
348
363
  }
349
364
 
350
- interface ICommandHandlerConfig<C extends Command<any>> {
351
- command: IConstructor<C>;
365
+ interface ICommandHandlerConfig<C extends object> {
366
+ command: IConstructor<IStorableData<C>>;
367
+ }
368
+ declare function commandHandler<C extends object>(config: ICommandHandlerConfig<C> | IConstructor<IStorableData<C>>): (target: IConstructor<ICommandHandler<C>>) => void;
369
+
370
+ interface ICronHandler {
371
+ handle(): void | Promise<void>;
372
+ handleError?(e: any): void | Promise<void>;
373
+ }
374
+
375
+ interface ICronJobScheduleConfig {
376
+ name: string;
377
+ commandName: string;
378
+ cron: string;
379
+ enabled: boolean;
380
+ }
381
+
382
+ interface ICronMetadata {
383
+ handlerConstructor: IConstructor<ICronHandler>;
384
+ config: ICronJobScheduleConfig;
352
385
  }
353
- declare function commandHandler<C extends Command<any>>(config: ICommandHandlerConfig<C>): (target: IConstructor<ICommandHandler<C>>) => void;
354
386
 
355
- declare class CommandMetadataStore {
387
+ declare class AsyncMetadataStore {
356
388
  private handlersMap;
357
389
  private handlersInverseMap;
358
390
  private commandsMap;
359
391
  private commandsInverseMap;
360
- registerCommand(command: IConstructor<Command<any>>, commandName: string): void;
361
- registerHandler(command: IConstructor<Command<any>>, handlerConstructor: IConstructor<ICommandHandler<any>>): void;
392
+ private cronsMap;
393
+ registerCron(cron: IConstructor<ICronHandler>, config: ICronJobScheduleConfig): void;
394
+ requireCronMetadata(cron: IConstructor<ICronHandler>): ICronMetadata[];
395
+ registerCommand(command: IConstructor<any>, commandName: string): void;
396
+ registerCommandHandler<C extends object>(command: IConstructor<IStorableData<C>>, handlerConstructor: IConstructor<ICommandHandler<C>>): void;
362
397
  getHandlerForCommandName(commandName: string): IConstructor<ICommandHandler<any>> | null;
363
398
  getCommandNameForHandler(handlerConstructor: IConstructor<ICommandHandler<any>>): string | null;
364
- getCommandName(command: IConstructor<Command<any>>): string | null;
365
- getCommandForCommandName(commandName: string): IConstructor<Command<any>> | null;
399
+ requireCommandNameForHandler(handlerConstructor: IConstructor<ICommandHandler<any>>): string;
400
+ getCommandName(command: IConstructor<any>): string | null;
401
+ getCommandForCommandName(commandName: string): IConstructor<any> | null;
366
402
  }
367
403
 
368
404
  interface IJobData extends IEntityData {
369
405
  commandName: string;
370
406
  commandData: any;
407
+ scheduledAt?: number;
371
408
  startedAt?: number;
372
409
  successAt?: number;
373
410
  failedAt?: number;
374
411
  retryAt?: number;
412
+ reintentsDelaysInSeconds?: number[];
413
+ intentNumber?: number;
375
414
  error?: {
415
+ time: number;
376
416
  message: string;
377
417
  stack?: string;
378
418
  info?: any;
379
419
  };
420
+ aceptableRunningTimeSeconds?: number;
421
+ stuckRetryAttempts?: number;
380
422
  }
381
423
  declare class Job extends Entity<IJobData> {
382
424
  get commandName(): string;
425
+ get commandData(): any;
426
+ get reintentsDelaysInSeconds(): number[] | undefined;
427
+ get aceptableRunningTimeSeconds(): number | undefined;
428
+ get stuckRetryAttempts(): number | undefined;
429
+ get runningSeconds(): number;
430
+ get successAt(): Date | null;
431
+ get failedAt(): Date | null;
432
+ get scheduledAt(): Date | null;
433
+ get intentNumber(): number;
434
+ wasSuccess(): boolean;
435
+ wasFailed(): boolean;
383
436
  hasFinished(): boolean;
437
+ isRunning(): boolean;
438
+ isScheduleReady(): boolean;
439
+ isStuck(): boolean;
384
440
  setAsStarted(): void;
385
441
  setAsSuccess(): void;
386
442
  setAsFailed(error: Error): void;
443
+ recover(): void;
387
444
  }
388
445
 
389
446
  interface IJobRepository extends ICrudRepository<Job> {
447
+ findPendingForRunFrom(date: Date, limit: number): Promise<Job[]>;
448
+ findRunningJobs(): Promise<Job[]>;
449
+ countRunningByCommand(commandName: string): Promise<number>;
390
450
  }
391
451
 
392
452
  declare class JobRepository implements IJobRepository {
453
+ findRunningJobs(): Promise<Job[]>;
454
+ findPendingForRunFrom(date: Date, limit: number): Promise<Job[]>;
393
455
  find(id: string): Promise<Job | null>;
394
456
  findOrThrow(id: string): Promise<Job>;
395
457
  findByIds(ids: string[]): Promise<Job[]>;
@@ -397,39 +459,60 @@ declare class JobRepository implements IJobRepository {
397
459
  create(item: Job): Promise<void>;
398
460
  update(item: Job): Promise<void>;
399
461
  delete(item: Job): Promise<void>;
462
+ countRunningByCommand(commandName: string): Promise<number>;
400
463
  }
401
464
 
402
- interface IJobEvent extends IStorableData {
403
- jobId: string;
404
- type: 'created';
465
+ declare class JobRunner {
466
+ private jobRepository;
467
+ private handlerContainer;
468
+ private logger;
469
+ constructor(jobRepository: JobRepository, handlerContainer: AsyncMetadataStore);
470
+ run(job: Job): Promise<void>;
405
471
  }
406
- type IJobEventListener = (event: IJobEvent) => void | Promise<void>;
407
- declare class JobsEventsHub {
472
+
473
+ declare class JobExecutor {
474
+ private locker;
475
+ private runner;
476
+ private repo;
477
+ private env;
478
+ private activeJobs;
408
479
  private logger;
409
- private jobsEventsListener;
410
- notifyJobCreated(job: Job): void;
411
- listenJobsEvents(listener: IJobEventListener): void;
480
+ constructor(locker: Locker, runner: JobRunner, repo: JobRepository, env: Env);
481
+ remainingSlots(): number;
482
+ execute(job: Job): Promise<void>;
483
+ private tryAcquire;
484
+ private release;
412
485
  }
413
486
 
414
- declare class Async {
415
- private jobRepository;
416
- private handlerContainer;
417
- private jobsEventsHub;
418
- constructor(jobRepository: JobRepository, handlerContainer: CommandMetadataStore, jobsEventsHub: JobsEventsHub);
419
- run<T extends IStorableData>(command: Command<T>): Promise<Job>;
487
+ declare class JobScheduler {
488
+ private locker;
489
+ private repo;
490
+ private executor;
491
+ private env;
492
+ private timeout?;
493
+ private logger;
494
+ private commands;
495
+ private running;
496
+ constructor(locker: Locker, repo: JobRepository, executor: JobExecutor, env: Env);
497
+ start(commands: string[]): void;
498
+ stop(commands: string[]): void;
499
+ tryExecuteNow(job: Job): void;
500
+ private tick;
420
501
  }
421
502
 
422
- declare class JobRunner {
503
+ declare class Async {
423
504
  private jobRepository;
424
- private handlerContainer;
425
- private logger;
426
- constructor(jobRepository: JobRepository, handlerContainer: CommandMetadataStore);
427
- run(job: Job): Promise<void>;
505
+ private metadataStore;
506
+ private jobScheduler;
507
+ constructor(jobRepository: JobRepository, metadataStore: AsyncMetadataStore, jobScheduler: JobScheduler);
508
+ runCommand<T>(ctor: IConstructor<T>, data: IValidateInputShape<T>): Promise<Job>;
428
509
  }
429
510
 
430
- declare function runAsyncCommandHandlers(handlers: IConstructor<ICommandHandler<any>>[]): void;
511
+ declare function runCommandHandlers(handlers: IConstructor<ICommandHandler<any>>[]): void;
512
+ declare function stopCommandHandlers(handlers: IConstructor<ICommandHandler<any>>[]): void;
431
513
 
432
- interface IChatConnection extends IStorableData {
514
+ interface IChatConnection {
515
+ chatType: 'GROUP' | 'PRIVATE';
433
516
  channelName: string;
434
517
  id: string;
435
518
  }
@@ -444,6 +527,11 @@ declare class Chat extends Entity<IChatData> {
444
527
  constructor(data: IChatData);
445
528
  isPrivate(): boolean;
446
529
  isGroup(): boolean;
530
+ get connections(): {
531
+ chatType: "GROUP" | "PRIVATE";
532
+ channelName: string;
533
+ id: string;
534
+ }[];
447
535
  hasConnection(connection: IChatConnection): boolean;
448
536
  private validatePrivateChat;
449
537
  private validateGroupChat;
@@ -581,13 +669,28 @@ declare class MindsetOperator implements IMindset {
581
669
  functionErrorToString(error: any): Promise<string>;
582
670
  }
583
671
 
584
- interface IChatMessage extends IStorableData {
672
+ interface IChatMessagesPublicImage {
673
+ name?: string;
674
+ publicUrl: string;
675
+ base64Url?: undefined;
676
+ mimeType: string;
677
+ }
678
+ interface IChatMessagesPrivateImage {
679
+ name?: string;
680
+ publicUrl?: undefined;
681
+ base64Url: string;
682
+ mimeType: string;
683
+ }
684
+ type IChatMessageImage = IChatMessagesPrivateImage | IChatMessagesPublicImage;
685
+
686
+ interface IChatMessage {
585
687
  senderId?: string;
586
688
  senderName?: string;
587
689
  text?: string;
690
+ images?: IChatMessageImage[];
588
691
  }
589
692
 
590
- interface IFunctionCall extends IStorableData {
693
+ interface IFunctionCall {
591
694
  id: string;
592
695
  name: string;
593
696
  arguments?: string;
@@ -598,13 +701,19 @@ declare const chatItemTypeOptions: readonly ["botMessage", "humanMessage", "func
598
701
  type IBotMessageItem = {
599
702
  type: 'botMessage';
600
703
  botMessage: IChatMessage;
704
+ humanMessage?: undefined;
705
+ functionCall?: undefined;
601
706
  };
602
707
  type IHumanMessageItem = {
603
708
  type: 'humanMessage';
709
+ botMessage?: undefined;
604
710
  humanMessage: IChatMessage;
711
+ functionCall?: undefined;
605
712
  };
606
713
  type IFunctionCallItem = {
607
714
  type: 'functionCall';
715
+ botMessage?: undefined;
716
+ humanMessage?: undefined;
608
717
  functionCall: IFunctionCall;
609
718
  };
610
719
  type IChatItem = IBotMessageItem | IHumanMessageItem | IFunctionCallItem;
@@ -641,7 +750,7 @@ declare class ChatItem extends Entity<IChatItemData> {
641
750
  get botMessage(): IChatMessage;
642
751
  get functionCall(): IFunctionCall;
643
752
  setFunctionResult(result: string): void;
644
- getData(): IChatItemData;
753
+ getData(): IStorableData<IChatItemData>;
645
754
  }
646
755
 
647
756
  interface IChatMemory {
@@ -745,7 +854,7 @@ declare class ChatResolver {
745
854
 
746
855
  interface IMessageContext extends IReceivedMessage {
747
856
  chat: Chat;
748
- authInfo?: IStorableData;
857
+ authInfo?: object;
749
858
  }
750
859
 
751
860
  declare function runChatControllers(controllers: IConstructor<any>[]): void;
@@ -768,13 +877,12 @@ declare class ExpressProvider {
768
877
  private createExpress;
769
878
  }
770
879
 
771
- interface IMoneyData extends IStorableData {
880
+ interface IMoneyData {
772
881
  amount: string;
773
882
  currency: string;
774
883
  }
775
884
  declare class Money extends Storable<IMoneyData> {
776
885
  getData(): {
777
- [key: string]: IPrimitive | IStorableData | IPrimitive[] | IStorableData[];
778
886
  amount: string;
779
887
  currency: string;
780
888
  };
@@ -812,14 +920,15 @@ type IPgRepositoryConfig<P extends Entity<IEntityData>> = {
812
920
  declare class PgRepositoryBase<P extends Entity<IEntityData>> {
813
921
  protected pool: Pool;
814
922
  protected config: IPgRepositoryConfig<any>;
815
- private tableIsCreated;
923
+ private tableIsReady;
816
924
  protected schema: string;
817
925
  protected table: string;
818
926
  protected columnsList: string[];
819
- protected columnsAndTypes: string;
927
+ protected columnsAndTypes: string[];
820
928
  protected columns: string;
821
929
  protected vars: string;
822
930
  protected updates: string;
931
+ private logger;
823
932
  addColumns: {
824
933
  [columns: string]: {
825
934
  type: string;
@@ -830,9 +939,8 @@ declare class PgRepositoryBase<P extends Entity<IEntityData>> {
830
939
  protected values(item: P): (string | number | boolean | Date | null)[];
831
940
  protected exec(sql: string, values: any[]): Promise<void>;
832
941
  protected query(sql: string, values: any[]): Promise<P[]>;
833
- protected connect(): Promise<Pool>;
834
- protected ensureTable(): Promise<void>;
835
- protected ensureColumns(): Promise<void>;
942
+ protected ensureTable(client: PoolClient): Promise<void>;
943
+ protected ensureColumns(client: PoolClient): Promise<void>;
836
944
  }
837
945
 
838
946
  declare class PgCrudRepository<P extends Entity<IEntityData>> extends PgRepositoryBase<P> implements ICrudRepository<P> {
@@ -847,6 +955,44 @@ declare class PgCrudRepository<P extends Entity<IEntityData>> extends PgReposito
847
955
  delete(item: P): Promise<void>;
848
956
  }
849
957
 
958
+ declare class PgLocker implements ILocker {
959
+ private readonly pool;
960
+ constructor(pool: Pool);
961
+ withKey(key: string | number): ILockKey;
962
+ }
963
+
964
+ declare class PgLockKey implements ILockKey {
965
+ private readonly key;
966
+ private pool;
967
+ readonly value: bigint;
968
+ private logger;
969
+ constructor(key: string | number, pool: Pool);
970
+ run<T>(fn: () => Promise<T>): Promise<T>;
971
+ tryRun<T>(fn: () => Promise<T>): Promise<T | undefined>;
972
+ toString(): string;
973
+ private static hashString;
974
+ }
975
+
976
+ type ClientMap = Map<Pool, PoolClient>;
977
+ declare const pgStorage: AsyncLocalStorage<ClientMap>;
978
+ /**
979
+ * Get or initialize the client map for the current async context
980
+ */
981
+ declare function getClientMap(): ClientMap;
982
+
983
+ /**
984
+ * Runs a function with a shared Postgres client for the given pool.
985
+ * Reuses the client if already present in the async context.
986
+ */
987
+ declare function withPgClient<T>(pool: Pool, fn: (client: PoolClient) => Promise<T>): Promise<T>;
988
+ /**
989
+ * Get the current shared client for a pool.
990
+ * Falls back to the pool itself if no shared client exists.
991
+ */
992
+ declare function getPgClient(pool: Pool): PoolClient | Pool;
993
+
994
+ declare function withPgTransaction<T>(pool: Pool, fn: (client: PoolClient) => Promise<T>): Promise<T>;
995
+
850
996
  interface IEndPointConfig {
851
997
  path?: string;
852
998
  disableJsonParser?: boolean;
@@ -982,57 +1128,62 @@ declare function runSocketControllers(controllers: IConstructor<any>[]): void;
982
1128
 
983
1129
  declare class PgJobRepository extends PgCrudRepository<Job> implements IJobRepository {
984
1130
  constructor(pool: Pool);
1131
+ findPendingForRunFrom(date: Date, limit: number): Promise<Job[]>;
1132
+ findRunningJobs(): Promise<Job[]>;
1133
+ countRunningByCommand(commandName: string): Promise<number>;
985
1134
  }
986
1135
 
987
1136
  declare function apiKeyHandshakeGuard(): (target: IConstructor<any>) => void;
988
1137
 
989
1138
  declare function apiKeyGuard(): (target: object, propertyKey: string | symbol) => void;
990
1139
 
991
- interface IApiKeyData<A extends IStorableData> extends IEntityData {
1140
+ interface IApiKeyData<A extends object> extends IEntityData {
992
1141
  secretHash?: string;
993
1142
  metadata?: Record<string, string>;
994
1143
  authInfo: A;
995
1144
  name: string;
996
1145
  }
997
- declare class ApiKey<A extends IStorableData> extends Entity<IApiKeyData<A>> {
1146
+ declare class ApiKey<A extends object> extends Entity<IApiKeyData<A>> {
998
1147
  static PREFIX: string;
999
1148
  static hashSecret(secret: string): string;
1000
- get authInfo(): A;
1001
- get metadata(): Record<string, string>;
1149
+ get authInfo(): IStorableType<A>;
1150
+ get metadata(): {
1151
+ [x: string]: string;
1152
+ };
1002
1153
  get name(): string;
1003
- setAuthInfo(authInfo: A): void;
1154
+ setAuthInfo(authInfo: IStorableType<A>): void;
1004
1155
  generateSecret(): string;
1005
1156
  isValidSecret(secret: string): boolean;
1006
1157
  validateSecret(secret: string): void;
1007
1158
  }
1008
1159
 
1009
- interface IApiKeyRepository<A extends IStorableData> {
1160
+ interface IApiKeyRepository<A extends object> {
1010
1161
  find(id: string): Promise<ApiKey<A> | null>;
1011
1162
  findOrThrow(id: string): Promise<ApiKey<A>>;
1012
1163
  findByMetadata(metadata: Record<string, string>): Promise<ApiKey<A>[]>;
1013
1164
  create(item: ApiKey<A>): Promise<void>;
1014
1165
  generate(req: IGenerateApiKeyReq<A>): Promise<IGenerateApiKeyRes<A>>;
1015
1166
  findBySecret(secret: string): Promise<ApiKey<A> | null>;
1016
- findAndValidate(secret: string): Promise<A>;
1167
+ findAndValidate(secret: string): Promise<IStorableType<A>>;
1017
1168
  }
1018
- interface IGenerateApiKeyReq<A extends IStorableData> extends IStorableData {
1169
+ interface IGenerateApiKeyReq<A extends object> {
1019
1170
  name: string;
1020
1171
  metadata?: Record<string, string>;
1021
- authInfo: A;
1172
+ authInfo: IStorableType<A>;
1022
1173
  }
1023
- interface IGenerateApiKeyRes<A extends IStorableData> {
1174
+ interface IGenerateApiKeyRes<A extends object> {
1024
1175
  apiKey: ApiKey<A>;
1025
1176
  secret: string;
1026
1177
  }
1027
1178
 
1028
- declare class ApiKeyRepository<A extends IStorableData> implements IApiKeyRepository<A> {
1179
+ declare class ApiKeyRepository<A extends object> implements IApiKeyRepository<A> {
1029
1180
  find(id: string): Promise<ApiKey<A> | null>;
1030
1181
  findOrThrow(id: string): Promise<ApiKey<A>>;
1031
1182
  findByMetadata(metadata: Record<string, string>): Promise<ApiKey<A>[]>;
1032
1183
  create(item: ApiKey<A>): Promise<void>;
1033
1184
  generate(req: IGenerateApiKeyReq<A>): Promise<IGenerateApiKeyRes<A>>;
1034
1185
  findBySecret(secret: string): Promise<ApiKey<A> | null>;
1035
- findAndValidate(secret: string): Promise<A>;
1186
+ findAndValidate(secret: string): Promise<IStorableType<A>>;
1036
1187
  }
1037
1188
 
1038
1189
  declare class ApiKeyHandshakeGuardMiddleware implements IHandshakeMiddleware {
@@ -1049,23 +1200,23 @@ declare class ApiKeyGuardMiddleware implements IMiddleware {
1049
1200
  handle(req: Request, res: Response, container: DependencyContainer$1): Promise<void>;
1050
1201
  }
1051
1202
 
1052
- declare class PgApiKeyRepository<A extends IStorableData> extends PgCrudRepository<ApiKey<A>> implements IApiKeyRepository<A> {
1203
+ declare class PgApiKeyRepository<A extends object> extends PgCrudRepository<ApiKey<A>> implements IApiKeyRepository<A> {
1053
1204
  constructor(pool: Pool);
1054
- findAndValidate(secret: string): Promise<A>;
1205
+ findAndValidate(secret: string): Promise<IStorableType<A>>;
1055
1206
  findBySecret(secret: string): Promise<ApiKey<A> | null>;
1056
1207
  findByMetadata(metadata: Record<string, string>): Promise<ApiKey<A>[]>;
1057
1208
  generate(req: IGenerateApiKeyReq<A>): Promise<IGenerateApiKeyRes<A>>;
1058
1209
  }
1059
1210
 
1060
- interface IRemoteApiKeyFetcher<A extends IStorableData> {
1061
- fetchAuthInfoBySecret: (secret: string) => Promise<A | null>;
1211
+ interface IRemoteApiKeyFetcher<A extends object> {
1212
+ fetchAuthInfoBySecret: (secret: string) => Promise<IStorableType<A> | null>;
1062
1213
  }
1063
- declare class RemoteApiKeyRepository<A extends IStorableData> implements IApiKeyRepository<A> {
1214
+ declare class RemoteApiKeyRepository<A extends object> implements IApiKeyRepository<A> {
1064
1215
  private fetcher;
1065
1216
  private cacheSeconds;
1066
1217
  private cacheBySecret;
1067
1218
  constructor(fetcher: IRemoteApiKeyFetcher<A>, cacheSeconds: number);
1068
- findAndValidate(secret: string): Promise<A>;
1219
+ findAndValidate(secret: string): Promise<IStorableType<A>>;
1069
1220
  find(id: string): Promise<ApiKey<A> | null>;
1070
1221
  findOrThrow(id: string): Promise<ApiKey<A>>;
1071
1222
  findBySecret(secret: string): Promise<ApiKey<A> | null>;
@@ -1078,18 +1229,20 @@ declare function jwtHandshakeGuard(): (target: IConstructor<any>) => void;
1078
1229
 
1079
1230
  declare function jwtGuard(): (target: object, propertyKey: string | symbol) => void;
1080
1231
 
1081
- interface IJwtRefreshTokenData<A extends IStorableData> extends IEntityData {
1232
+ interface IJwtRefreshTokenData<A extends object> extends IEntityData {
1082
1233
  secretHash?: string;
1083
1234
  metadata?: Record<string, string>;
1084
1235
  authInfo: A;
1085
1236
  expirationTime: number;
1086
1237
  revokedAt?: number;
1087
1238
  }
1088
- declare class JwtRefreshToken<A extends IStorableData> extends Entity<IJwtRefreshTokenData<A>> {
1239
+ declare class JwtRefreshToken<A extends object> extends Entity<IJwtRefreshTokenData<A>> {
1089
1240
  static PREFIX: string;
1090
1241
  static hashSecret(secret: string): string;
1091
- get authInfo(): A;
1092
- get metadata(): Record<string, string>;
1242
+ get authInfo(): IStorableType<A>;
1243
+ get metadata(): {
1244
+ [x: string]: string;
1245
+ };
1093
1246
  get expirationTime(): Date;
1094
1247
  isExpired(): boolean;
1095
1248
  revoke(): void;
@@ -1100,8 +1253,8 @@ declare class JwtRefreshToken<A extends IStorableData> extends Entity<IJwtRefres
1100
1253
  validateToken(secret: string): void;
1101
1254
  }
1102
1255
 
1103
- interface IJwtRefreshTokenRepository<D extends IStorableData> extends ICrudRepository<JwtRefreshToken<D>> {
1104
- findAndValidate(secret: string): Promise<D>;
1256
+ interface IJwtRefreshTokenRepository<D extends object> extends ICrudRepository<JwtRefreshToken<D>> {
1257
+ findAndValidate(secret: string): Promise<IStorableType<D>>;
1105
1258
  findByMetadata(metadata: Record<string, string>): Promise<JwtRefreshToken<D>[]>;
1106
1259
  }
1107
1260
 
@@ -1128,12 +1281,12 @@ declare class JwtSigner {
1128
1281
  private config;
1129
1282
  private mapper;
1130
1283
  constructor(config: JwtConfig, mapper: Mapper);
1131
- signAccessToken<D extends IStorableData>(info: D | JwtRefreshToken<any>): Promise<JwtTokenDto>;
1284
+ signAccessToken<D extends object>(info: IStorableType<D> | JwtRefreshToken<any>): Promise<JwtTokenDto>;
1132
1285
  }
1133
1286
 
1134
- declare class JwtRefreshTokenRepository<D extends IStorableData> implements IJwtRefreshTokenRepository<D> {
1287
+ declare class JwtRefreshTokenRepository<D extends object> implements IJwtRefreshTokenRepository<D> {
1135
1288
  findByMetadata(metadata: Record<string, string>): Promise<JwtRefreshToken<D>[]>;
1136
- findAndValidate(secret: string): Promise<D>;
1289
+ findAndValidate(secret: string): Promise<IStorableType<D>>;
1137
1290
  find(id: string): Promise<JwtRefreshToken<D> | null>;
1138
1291
  findOrThrow(id: string): Promise<JwtRefreshToken<D>>;
1139
1292
  findByIds(ids: string[]): Promise<JwtRefreshToken<D>[]>;
@@ -1167,9 +1320,9 @@ declare class JwtGuardMiddleware implements IMiddleware {
1167
1320
  handle(req: Request, res: Response, container: DependencyContainer$1): Promise<void>;
1168
1321
  }
1169
1322
 
1170
- declare class PgJwtRefreshTokenRepository<D extends IStorableData> extends PgCrudRepository<JwtRefreshToken<D>> implements IJwtRefreshTokenRepository<D> {
1323
+ declare class PgJwtRefreshTokenRepository<D extends object> extends PgCrudRepository<JwtRefreshToken<D>> implements IJwtRefreshTokenRepository<D> {
1171
1324
  constructor(pool: Pool);
1172
- findAndValidate(secret: string): Promise<D>;
1325
+ findAndValidate(secret: string): Promise<IStorableType<D>>;
1173
1326
  findBySecret(secret: string): Promise<JwtRefreshToken<D> | null>;
1174
1327
  findByMetadata(metadata: Record<string, string>): Promise<JwtRefreshToken<D>[]>;
1175
1328
  }
@@ -1341,11 +1494,11 @@ declare class WhatsappChannelConfig implements IWhatsappChannelConfig {
1341
1494
 
1342
1495
  declare function whatsApp(config: string | IWhatsappChannelConfig): (target: object, propertyKey: string | symbol) => void;
1343
1496
 
1344
- interface IWhatsAppBusinessNumber extends IStorableData {
1497
+ interface IWhatsAppBusinessNumber {
1345
1498
  id: string;
1346
1499
  number: string;
1347
1500
  }
1348
- interface IWhatsAppBusinessAccount extends IStorableData {
1501
+ interface IWhatsAppBusinessAccount {
1349
1502
  id: string;
1350
1503
  }
1351
1504
  interface IWhatsAppData extends IEntityData {
@@ -1361,7 +1514,10 @@ declare class WhatsApp extends Entity<IWhatsAppData> {
1361
1514
  getSlug(): string;
1362
1515
  getBusinessAccount(): IWhatsAppBusinessAccount;
1363
1516
  getAppSecret(): string;
1364
- getBusinessNumbers(): IWhatsAppBusinessNumber[];
1517
+ getBusinessNumbers(): {
1518
+ id: string;
1519
+ number: string;
1520
+ }[];
1365
1521
  getAccessToken(): string;
1366
1522
  hasBusinessNumber(number: string): boolean;
1367
1523
  getBussinessNumber(number: string): IWhatsAppBusinessNumber | null;
@@ -1629,4 +1785,4 @@ declare function HtmlModule(options: IHtmlModuleOptions): {
1629
1785
  new (): {};
1630
1786
  };
1631
1787
 
1632
- export { AnthropicChatAdapter, ApiKey, ApiKeyGuardMiddleware, ApiKeyHandshakeGuardMiddleware, ApiKeyRepository, Async, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatAdapter, DescriptionMetadataStore, EXPRESS_REQ, EXPRESS_RES, Entity, Env, EnvWhatsAppRepository, ExpressProvider, GoogleChatAdapter, type GoogleChatAdapterV2Options, HtmlModule, HttpServerProvider, type IApiKeyData, type IApiKeyRepository, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMessage, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemsReq, type IChatAdapterNextItemsRes, 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 IDescriptionMetadata, type IEndPointConfig, type IEndPointMetadata, type IEntityData, type IEnvType, type IFunctionCall, type IFunctionCallItem, type IGenerateApiKeyReq, type IGenerateApiKeyRes, type IGetWhatsAppTemplateRequest, type IHandshakeMiddleware, type IHandshakeMiddlewareMetadata, 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 IMindsetConfig, type IMindsetIdentity, type IMindsetLlm, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleMetadata, type IMindsetTool, type IMindsetToolParameter, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IMoneyData, type IPersistentData, type IPgRepositoryConfig, type IPrimitive, type IPropertyValidatorInfo, type IReceivedMessage, type IRemoteApiKeyFetcher, type IRestControllerConfig, type IRestControllerMetadata, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type ISocketControllerConfig, type ISocketControllerMetadata, type ISocketEventConfig, type ISocketEventMetadata, type IStorableData, type ITelegramChannelConfig, type IValidateArrayOptions, type IValidateArrayOptionsWithItemsValidators, type IValidateInputShape, type IValidateIsInOptions, type IValidateIsRecordOptions, 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, JwtGuardMiddleware, JwtHandshakeGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Logger, Mapper, Mindset, MindsetMetadataStore, MindsetOperator, Money, MoneyDto, OpenaiChatAdapter, Password, type PasswordHashOptions, Persistent, PgApiKeyRepository, PgChatMemory, PgChatRepository, PgCrudRepository, PgJobRepository, PgJwtRefreshTokenRepository, PgRepositoryBase, PgWhatsAppRepository, RamChatMemory, RamChatRepository, Random, RemoteApiKeyRepository, RestControllerMetadataStore, RestRequest, SocketChannel, SocketChannelConfig, SocketChannelReceivedMessage, 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, apiKeyHandshakeGuard, chatBot, chatController, chatItemTypeOptions, cmd, command, commandHandler, container, description, handshakeMiddlewares, inject, injectable, isArray, isBoolean, isDate, isIn, isModel, isNotEmpty, isNumber, isOptional, isPresent, isRecord, isString, jwtGuard, jwtHandshakeGuard, max, middleware, min, mindset, mindsetModule, modelInfo, onDelete, onGet, onPost, onPut, onSocketEvent, readJsonFromFile, restController, runAsyncCommandHandlers, runChatControllers, runRestControllers, runSocketControllers, scoped, singleton, socket, socketController, telegram, validateAndTransform, validateArray, validateIsBoolean, validateIsDate, validateIsIn, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsRecord, validateIsString, validateMax, validateMin, validateModel, whatsApp, writeJsonToFile };
1788
+ export { AnthropicChatAdapter, ApiKey, ApiKeyGuardMiddleware, ApiKeyHandshakeGuardMiddleware, ApiKeyRepository, Async, AsyncMetadataStore, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, type ClientMap, CmdChannel, Container, ControllerMetadataStore, CustomError, DeepSeekChatAdapter, DescriptionMetadataStore, EXPRESS_REQ, EXPRESS_RES, Entity, Env, EnvWhatsAppRepository, ExpressProvider, GoogleChatAdapter, type GoogleChatAdapterV2Options, HtmlModule, HttpServerProvider, type IApiKeyData, type IApiKeyRepository, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMessage, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemsReq, type IChatAdapterNextItemsRes, 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 IDescriptionMetadata, type IEndPointConfig, type IEndPointMetadata, type IEntityData, type IEnvType, type IFunctionCall, type IFunctionCallItem, type IGenerateApiKeyReq, type IGenerateApiKeyRes, type IGetWhatsAppTemplateRequest, type IHandshakeMiddleware, type IHandshakeMiddlewareMetadata, type IHtmlModuleOptions, type IHumanMessageItem, type IJobData, type IJobRepository, type IJwtRefreshTokenData, type IJwtRefreshTokenRepository, type ILanguageModelUsage, type IListenWhatsAppMessageRequest, type ILockKey, type ILocker, type IMessageContext, type IMiddleware, type IMiddlewareMetadata, type IMindset, type IMindsetConfig, type IMindsetIdentity, type IMindsetLlm, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleMetadata, type IMindsetTool, type IMindsetToolParameter, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IMoneyData, type IPersistentData, type IPgRepositoryConfig, type IPropertyValidatorInfo, type IReceivedMessage, type IRemoteApiKeyFetcher, type IRestControllerConfig, type IRestControllerMetadata, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type ISocketControllerConfig, type ISocketControllerMetadata, type ISocketEventConfig, type ISocketEventMetadata, type IStorableData, type ITelegramChannelConfig, type IValidateArrayOptions, type IValidateArrayOptionsWithItemsValidators, type IValidateInputShape, type IValidateIsInOptions, type IValidateIsRecordOptions, 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, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtGuardMiddleware, JwtHandshakeGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Locker, Logger, Mapper, Mindset, MindsetMetadataStore, MindsetOperator, Money, MoneyDto, OpenaiChatAdapter, Password, type PasswordHashOptions, Persistent, PgApiKeyRepository, PgChatMemory, PgChatRepository, PgCrudRepository, PgJobRepository, PgJwtRefreshTokenRepository, PgLockKey, PgLocker, PgRepositoryBase, PgWhatsAppRepository, RamChatMemory, RamChatRepository, Random, RemoteApiKeyRepository, RestControllerMetadataStore, RestRequest, SocketChannel, SocketChannelConfig, SocketChannelReceivedMessage, 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, apiKeyHandshakeGuard, chatBot, chatController, chatItemTypeOptions, cmd, command, commandHandler, container, description, getClientMap, getPgClient, handshakeMiddlewares, inject, injectable, isArray, isBoolean, isDate, isIn, isModel, isNotEmpty, isNumber, isOptional, isPresent, isRecord, isString, jwtGuard, jwtHandshakeGuard, max, middleware, min, mindset, mindsetModule, modelInfo, onDelete, onGet, onPost, onPut, onSocketEvent, pgStorage, readJsonFromFile, restController, runChatControllers, runCommandHandlers, runRestControllers, runSocketControllers, scoped, singleton, socket, socketController, stopCommandHandlers, telegram, validateAndTransform, validateArray, validateIsBoolean, validateIsDate, validateIsIn, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsRecord, validateIsString, validateMax, validateMin, validateModel, whatsApp, withPgClient, withPgTransaction, writeJsonToFile };