@wabot-dev/framework 0.1.0-beta.11 → 0.1.0-beta.13

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 (61) hide show
  1. package/dist/src/ai/claude/ClaudeChatBotAdapter.js +115 -0
  2. package/dist/src/channels/whatsapp/WhatsApp.js +2 -2
  3. package/dist/src/channels/whatsapp/WhatsAppSender.js +10 -1
  4. package/dist/src/channels/whatsapp/WhatsAppSenderByCloudApi.js +3 -9
  5. package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +6 -11
  6. package/dist/src/core/{Persistent.js → Entity.js} +24 -9
  7. package/dist/src/core/Storable.js +8 -0
  8. package/dist/src/core/chat/Chat.js +2 -2
  9. package/dist/src/core/chat/ChatItem.js +2 -2
  10. package/dist/src/core/user/User.js +2 -2
  11. package/dist/src/error/CustomError.js +1 -0
  12. package/dist/src/index.d.ts +250 -181
  13. package/dist/src/index.js +13 -9
  14. package/dist/src/node_modules/@anthropic-ai/sdk/_vendor/partial-json-parser/parser.js +221 -0
  15. package/dist/src/node_modules/@anthropic-ai/sdk/client.js +540 -0
  16. package/dist/src/node_modules/@anthropic-ai/sdk/core/api-promise.js +74 -0
  17. package/dist/src/node_modules/@anthropic-ai/sdk/core/error.js +100 -0
  18. package/dist/src/node_modules/@anthropic-ai/sdk/core/pagination.js +119 -0
  19. package/dist/src/node_modules/@anthropic-ai/sdk/core/resource.js +8 -0
  20. package/dist/src/node_modules/@anthropic-ai/sdk/core/streaming.js +283 -0
  21. package/dist/src/node_modules/@anthropic-ai/sdk/internal/constants.js +16 -0
  22. package/dist/src/node_modules/@anthropic-ai/sdk/internal/decoders/jsonl.js +37 -0
  23. package/dist/src/node_modules/@anthropic-ai/sdk/internal/decoders/line.js +110 -0
  24. package/dist/src/node_modules/@anthropic-ai/sdk/internal/detect-platform.js +159 -0
  25. package/dist/src/node_modules/@anthropic-ai/sdk/internal/errors.js +37 -0
  26. package/dist/src/node_modules/@anthropic-ai/sdk/internal/headers.js +71 -0
  27. package/dist/src/node_modules/@anthropic-ai/sdk/internal/parse.js +53 -0
  28. package/dist/src/node_modules/@anthropic-ai/sdk/internal/request-options.js +11 -0
  29. package/dist/src/node_modules/@anthropic-ai/sdk/internal/shims.js +86 -0
  30. package/dist/src/node_modules/@anthropic-ai/sdk/internal/to-file.js +94 -0
  31. package/dist/src/node_modules/@anthropic-ai/sdk/internal/tslib.js +14 -0
  32. package/dist/src/node_modules/@anthropic-ai/sdk/internal/uploads.js +113 -0
  33. package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/bytes.js +27 -0
  34. package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/env.js +19 -0
  35. package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/log.js +82 -0
  36. package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/path.js +76 -0
  37. package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/sleep.js +4 -0
  38. package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/uuid.js +16 -0
  39. package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/values.js +48 -0
  40. package/dist/src/node_modules/@anthropic-ai/sdk/lib/BetaMessageStream.js +588 -0
  41. package/dist/src/node_modules/@anthropic-ai/sdk/lib/MessageStream.js +582 -0
  42. package/dist/src/node_modules/@anthropic-ai/sdk/resources/beta/beta.js +19 -0
  43. package/dist/src/node_modules/@anthropic-ai/sdk/resources/beta/files.js +120 -0
  44. package/dist/src/node_modules/@anthropic-ai/sdk/resources/beta/messages/batches.js +202 -0
  45. package/dist/src/node_modules/@anthropic-ai/sdk/resources/beta/messages/messages.js +85 -0
  46. package/dist/src/node_modules/@anthropic-ai/sdk/resources/beta/models.js +58 -0
  47. package/dist/src/node_modules/@anthropic-ai/sdk/resources/completions.js +21 -0
  48. package/dist/src/node_modules/@anthropic-ai/sdk/resources/messages/batches.js +151 -0
  49. package/dist/src/node_modules/@anthropic-ai/sdk/resources/messages/messages.js +71 -0
  50. package/dist/src/node_modules/@anthropic-ai/sdk/resources/models.js +43 -0
  51. package/dist/src/node_modules/@anthropic-ai/sdk/version.js +3 -0
  52. package/dist/src/pre-made/repository/chat/ram/RamChatRepository.js +1 -1
  53. package/dist/src/repository/pg/PgCrudRepository.js +2 -2
  54. package/dist/src/repository/pg/PgRepositoryBase.js +2 -2
  55. package/dist/src/rest-controller/metadata/@middleware.js +16 -0
  56. package/dist/src/rest-controller/metadata/RestControllerMetadataStore.js +13 -0
  57. package/dist/src/rest-controller/runRestControllers.js +30 -22
  58. package/dist/src/server/prepareChatContainer.js +2 -2
  59. package/dist/src/validation/metadata/@isModel.js +18 -0
  60. package/dist/src/validation/validators/validateModel.js +2 -6
  61. package/package.json +2 -1
@@ -2,10 +2,10 @@ import InjectionToken from 'tsyringe/dist/typings/providers/injection-token';
2
2
  import DependencyContainer, { PreResolutionInterceptorCallback, PostResolutionInterceptorCallback } from 'tsyringe/dist/typings/types/dependency-container';
3
3
  import InterceptionOptions from 'tsyringe/dist/typings/types/interceptor-options';
4
4
  import { Server } from 'http';
5
- import { Express } from 'express';
5
+ import { Express, Request, Response } from 'express';
6
6
  import { Server as Server$1 } from 'socket.io';
7
- import { Socket } from 'socket.io-client';
8
7
  import { Pool } from 'pg';
8
+ import { Socket } from 'socket.io-client';
9
9
  import * as tsyringe from 'tsyringe';
10
10
  import { DependencyContainer as DependencyContainer$1 } from 'tsyringe';
11
11
  export { DependencyContainer } from 'tsyringe';
@@ -26,33 +26,58 @@ interface IMindsetFunctionDecoration {
26
26
  decorationConfig: any;
27
27
  }
28
28
 
29
- interface IPersistentData {
29
+ type IPrimitive = null | number | string | boolean | undefined;
30
+ type IStorableData = {
31
+ [key: string]: IPrimitive | IPrimitive[] | IStorableData | IStorableData[];
32
+ };
33
+ declare class Storable<D extends IStorableData> {
34
+ protected data: D;
35
+ constructor(data: D);
36
+ }
37
+
38
+ interface IEntityData extends IStorableData {
30
39
  id?: string;
31
40
  createdAt?: number | null;
32
41
  discardedAt?: number | null;
33
42
  }
34
- declare class Persistent<D extends IPersistentData = IPersistentData> {
35
- protected data: D;
36
- constructor(data: D);
43
+ declare class Entity<D extends IEntityData> extends Storable<D> {
44
+ get id(): string;
45
+ /**
46
+ * @deprecated use id
47
+ */
37
48
  getId(): string;
49
+ get createdAt(): Date;
50
+ /**
51
+ * @deprecated use createdAt
52
+ */
38
53
  getCreatedAt(): Date;
39
- update(newData: D): void;
54
+ update(newData: Omit<D, 'id' | 'createdAt' | 'discardedAt'>): void;
40
55
  wasCreated(): boolean;
41
56
  validate(): void;
42
57
  discard(): void;
43
58
  }
59
+ /**
60
+ * @deprecated Should use IEntityData
61
+ */
62
+ interface IPersistentData extends IEntityData {
63
+ }
64
+ /**
65
+ * @deprecated Should use Entity
66
+ */
67
+ declare class Persistent<D extends IPersistentData> extends Entity<D> {
68
+ }
44
69
 
45
70
  type IChatType = 'PRIVATE' | 'GROUP';
46
- interface IChatConnection {
71
+ interface IChatConnection extends IStorableData {
47
72
  chatType: IChatType;
48
73
  channelName: string;
49
74
  id: string;
50
75
  }
51
- interface IChatData extends IPersistentData {
76
+ interface IChatData extends IEntityData {
52
77
  type: IChatType;
53
78
  connections: IChatConnection[];
54
79
  }
55
- declare class Chat extends Persistent<IChatData> {
80
+ declare class Chat extends Entity<IChatData> {
56
81
  constructor(data: IChatData);
57
82
  isPrivate(): boolean;
58
83
  isGroup(): boolean;
@@ -62,24 +87,24 @@ declare class Chat extends Persistent<IChatData> {
62
87
  validate(): void;
63
88
  }
64
89
 
65
- interface IChatDocument {
90
+ interface IChatDocument extends IStorableData {
66
91
  }
67
92
 
68
- interface IChatImage {
93
+ interface IChatImage extends IStorableData {
69
94
  }
70
95
 
71
- interface IUserConnection {
96
+ interface IUserConnection extends IStorableData {
72
97
  channelName: string;
73
98
  id: string;
74
99
  }
75
- interface IUserData extends IPersistentData {
100
+ interface IUserData extends IEntityData {
76
101
  shortName: string;
77
102
  connections: IUserConnection[];
78
103
  keyValueData: {
79
104
  [key: string]: string;
80
105
  };
81
106
  }
82
- declare class User extends Persistent<IUserData> {
107
+ declare class User extends Entity<IUserData> {
83
108
  constructor(data: IUserData);
84
109
  hasConnection(connection: IUserConnection): boolean;
85
110
  getValue(key: string): string;
@@ -87,7 +112,7 @@ declare class User extends Persistent<IUserData> {
87
112
  addConnection(connection: IUserConnection): void;
88
113
  }
89
114
 
90
- interface IChatMessage {
115
+ interface IChatMessage extends IStorableData {
91
116
  text?: string;
92
117
  documents?: IChatDocument[];
93
118
  images?: IChatImage[];
@@ -118,12 +143,9 @@ type ISystemFunctionCallItem = {
118
143
  type: 'FUNCTION_CALL';
119
144
  content: IChatFunctionCall;
120
145
  };
121
- type IChatItemData = {
122
- id?: string;
123
- createdAt?: number;
124
- } & (ISystemMessageItem | IReceivedMessageItem | ISystemFunctionCallItem);
146
+ type IChatItemData = IEntityData & (ISystemMessageItem | IReceivedMessageItem | ISystemFunctionCallItem);
125
147
  type IChatItemType = IChatItemData['type'];
126
- declare class ChatItem extends Persistent<IChatItemData> {
148
+ declare class ChatItem extends Entity<IChatItemData> {
127
149
  getType(): "BOT_MESSAGE" | "CONNECTION_MESSAGE" | "FUNCTION_CALL";
128
150
  getContent(): IChatMessage | IConnectionChatMessage | IChatFunctionCall;
129
151
  getData(): IChatItemData;
@@ -172,11 +194,6 @@ declare class MessageContext implements IMessageContext {
172
194
  constructor(message: IConnectionChatMessage, chat: Chat, user: User | null);
173
195
  }
174
196
 
175
- interface IReversibleMapper<T1, T2> {
176
- map(input: T1): T2;
177
- rev(input: T2): T1;
178
- }
179
-
180
197
  type IConstructor<T> = new (...args: any[]) => T;
181
198
 
182
199
  interface IMindsetIdentity {
@@ -383,6 +400,15 @@ declare class OpenaiChatBotAdapter extends ChatBotAdapter {
383
400
  private mapChatItems;
384
401
  }
385
402
 
403
+ declare class ClaudeChatBotAdapter extends ChatBotAdapter {
404
+ private anthropic;
405
+ private model;
406
+ private logger;
407
+ constructor(mindset: MindsetOperator);
408
+ generateNextChatItem(chatItems: ChatItem[]): Promise<ChatItem>;
409
+ private mapChatItems;
410
+ }
411
+
386
412
  declare function cmd(): (target: object, propertyKey: string | symbol) => void;
387
413
 
388
414
  declare class ChatResolver {
@@ -532,6 +558,54 @@ declare class WhatsappChannelConfig implements IWhatsappChannelConfig {
532
558
 
533
559
  declare function whatsapp(config: IWhatsappChannelConfig): (target: object, propertyKey: string | symbol) => void;
534
560
 
561
+ interface IWhatsAppBusinessNumber extends IStorableData {
562
+ id: string;
563
+ number: string;
564
+ }
565
+ interface IWhatsAppBusinessAccount extends IStorableData {
566
+ id: string;
567
+ }
568
+ interface IWhatsAppData extends IEntityData {
569
+ slug: string;
570
+ verifyToken: string;
571
+ appSecret: string;
572
+ accessToken: string;
573
+ businessAccount: IWhatsAppBusinessAccount;
574
+ businessNumbers: IWhatsAppBusinessNumber[];
575
+ }
576
+ declare class WhatsApp extends Entity<IWhatsAppData> {
577
+ getVerifyToken(): string;
578
+ getSlug(): string;
579
+ getBusinessAccount(): IWhatsAppBusinessAccount;
580
+ getAppSecret(): string;
581
+ getBusinessNumbers(): IWhatsAppBusinessNumber[];
582
+ getAccessToken(): string;
583
+ hasBusinessNumber(number: string): boolean;
584
+ getBussinessNumber(number: string): IWhatsAppBusinessNumber | null;
585
+ }
586
+
587
+ interface IWhatsAppRepository {
588
+ findBySlug(slug: string): Promise<WhatsApp | null>;
589
+ findByBusinessNumber(number: string): Promise<WhatsApp | null>;
590
+ }
591
+
592
+ type IWabotEnvType = 'development' | 'staging' | 'testing' | 'production';
593
+ declare class WabotEnv {
594
+ private envType;
595
+ constructor();
596
+ isDevelopment(): boolean;
597
+ isProduction(): boolean;
598
+ requireString(varName: string): string;
599
+ }
600
+
601
+ declare class EnvWhatsAppRepository implements IWhatsAppRepository {
602
+ private env;
603
+ constructor(env: WabotEnv);
604
+ findBySlug(slug: string): Promise<WhatsApp | null>;
605
+ findByBusinessNumber(number: string): Promise<WhatsApp | null>;
606
+ private getFromEnvVars;
607
+ }
608
+
535
609
  type IWhatsAppTemplateParameter = {
536
610
  type: 'text';
537
611
  text: string;
@@ -555,6 +629,32 @@ interface IWhatsAppTemplateMessage {
555
629
  parameters: IWhatsAppTemplateParameter[];
556
630
  }
557
631
 
632
+ interface IWhatsAppTemplateResponse {
633
+ data: IWhatsAppTemplate[];
634
+ paging: IWhatsAppApiPaging;
635
+ }
636
+ interface IWhatsAppTemplate {
637
+ name: string;
638
+ parameter_format: 'POSITIONAL' | 'OTHER';
639
+ components: IWhatsAppTemplateComponent[];
640
+ language: string;
641
+ status: string;
642
+ category: string;
643
+ id: string;
644
+ }
645
+ interface IWhatsAppTemplateComponent {
646
+ type: 'HEADER' | 'BODY' | 'FOOTER';
647
+ format?: 'TEXT';
648
+ text?: string;
649
+ }
650
+ interface IWhatsAppApiPaging {
651
+ cursors: IWhatsAppApiCursors;
652
+ }
653
+ interface IWhatsAppApiCursors {
654
+ before: string;
655
+ after: string;
656
+ }
657
+
558
658
  interface IWhatsAppWebhookPayload {
559
659
  object: 'whatsapp_business_account';
560
660
  entry: IEntry[];
@@ -607,30 +707,70 @@ interface IAudioMessage extends IBaseMessage {
607
707
  };
608
708
  }
609
709
 
610
- interface IWhatsAppBusinessNumber {
611
- id: string;
612
- number: string;
710
+ interface ICrudRepository<T> {
711
+ find(id: string): Promise<T | null>;
712
+ findOrThrow(id: string): Promise<T>;
713
+ findAll(id: string): Promise<T[]>;
714
+ create(item: T): Promise<void>;
715
+ update(item: T): Promise<void>;
716
+ discard(item: T): Promise<void>;
613
717
  }
614
- interface IWhatsAppBusinessAccount {
615
- id: string;
718
+
719
+ type IPgRepositoryConfig<P extends Entity<IEntityData>> = {
720
+ schema?: string;
721
+ table: string;
722
+ constructor: IConstructor<P>;
723
+ add?: {
724
+ columns: {
725
+ [column: string]: {
726
+ type: string;
727
+ value: (item: P) => boolean | number | string | null | Date;
728
+ };
729
+ };
730
+ };
731
+ };
732
+
733
+ declare class PgRepositoryBase<P extends Entity<IEntityData>> {
734
+ protected pool: Pool;
735
+ protected config: IPgRepositoryConfig<any>;
736
+ private tableIsCreated;
737
+ protected schema: string;
738
+ protected table: string;
739
+ protected columnsList: string[];
740
+ protected columnsAndTypes: string;
741
+ protected columns: string;
742
+ protected vars: string;
743
+ protected updates: string;
744
+ addColumns: {
745
+ [columns: string]: {
746
+ type: string;
747
+ value: (item: P) => number | boolean | string | null | Date;
748
+ };
749
+ };
750
+ constructor(pool: Pool, config: IPgRepositoryConfig<any>);
751
+ protected values(item: P): (string | number | boolean | Date | null)[];
752
+ protected exec(sql: string, values: any[]): Promise<void>;
753
+ protected query(sql: string, values: any[]): Promise<any[]>;
754
+ protected connect(): Promise<Pool>;
755
+ protected ensureTable(): Promise<void>;
756
+ protected ensureColumns(): Promise<void>;
616
757
  }
617
- interface IWhatsAppData extends IPersistentData {
618
- slug: string;
619
- verifyToken: string;
620
- appSecret: string;
621
- accessToken: string;
622
- businessAccount: IWhatsAppBusinessAccount;
623
- businessNumbers: IWhatsAppBusinessNumber[];
758
+
759
+ declare class PgCrudRepository<P extends Entity<IEntityData>> extends PgRepositoryBase<P> implements ICrudRepository<P> {
760
+ protected readonly config: IPgRepositoryConfig<P>;
761
+ constructor(pool: Pool, config: IPgRepositoryConfig<P>);
762
+ find(id: string): Promise<P | null>;
763
+ findOrThrow(id: string): Promise<P>;
764
+ findAll(): Promise<P[]>;
765
+ create(item: P): Promise<void>;
766
+ update(item: P): Promise<void>;
767
+ discard(item: P): Promise<void>;
624
768
  }
625
- declare class WhatsApp extends Persistent<IWhatsAppData> {
626
- getVerifyToken(): string;
627
- getSlug(): string;
628
- getBusinessAccount(): IWhatsAppBusinessAccount;
629
- getAppSecret(): string;
630
- getBusinessNumbers(): IWhatsAppBusinessNumber[];
631
- getAccessToken(): string;
632
- hasBusinessNumber(number: string): boolean;
633
- getBussinessNumber(number: string): IWhatsAppBusinessNumber | null;
769
+
770
+ declare class PgWhatsAppRepository extends PgCrudRepository<WhatsApp> implements IWhatsAppRepository {
771
+ constructor(pool: Pool);
772
+ findBySlug(slug: string): Promise<WhatsApp | null>;
773
+ findByBusinessNumber(number: string): Promise<WhatsApp | null>;
634
774
  }
635
775
 
636
776
  declare class Logger {
@@ -660,31 +800,11 @@ declare abstract class WhatsAppReceiver {
660
800
  private emmitMessage;
661
801
  }
662
802
 
663
- interface IWhatsAppRepository {
664
- findBySlug(slug: string): Promise<WhatsApp | null>;
665
- findByBusinessNumber(number: string): Promise<WhatsApp | null>;
666
- }
667
-
668
803
  declare class WhatsAppRepository implements IWhatsAppRepository {
669
804
  findBySlug(slug: string): Promise<WhatsApp | null>;
670
805
  findByBusinessNumber(number: string): Promise<WhatsApp | null>;
671
806
  }
672
807
 
673
- interface IWhatsAppTemplate {
674
- name: string;
675
- parameter_format: 'POSITIONAL' | 'OTHER';
676
- components: IWhatsAppTemplateComponent[];
677
- language: string;
678
- status: string;
679
- category: string;
680
- id: string;
681
- }
682
- interface IWhatsAppTemplateComponent {
683
- type: 'HEADER' | 'BODY' | 'FOOTER';
684
- format?: 'TEXT';
685
- text?: string;
686
- }
687
-
688
808
  interface ISendWhatsAppRequest {
689
809
  from: string;
690
810
  to: string;
@@ -704,15 +824,15 @@ interface IGetWhatsAppTemplateRequest {
704
824
  interface IWhatsAppSenderOptions {
705
825
  writeChatMemory?: boolean;
706
826
  }
707
- declare abstract class WhatsAppSender {
827
+ declare class WhatsAppSender {
708
828
  protected logger: Logger;
709
829
  protected chatRepository: ChatRepository;
710
830
  protected chatResolver: ChatResolver;
711
831
  protected whatsAppRepository: WhatsAppRepository;
712
832
  constructor(logger: Logger, chatRepository: ChatRepository, chatResolver: ChatResolver, whatsAppRepository: WhatsAppRepository);
713
- protected abstract handleSendRequest(request: ISendWhatsAppRequest): Promise<void>;
714
- protected abstract handleSendTemplateRequest(request: ISendWhatsAppTemplateRequest): Promise<void>;
715
- protected abstract handleGetWhatsAppTemplate(request: IGetWhatsAppTemplateRequest): Promise<IWhatsAppTemplate | null>;
833
+ protected handleSendRequest(request: ISendWhatsAppRequest): Promise<void>;
834
+ protected handleSendTemplateRequest(request: ISendWhatsAppTemplateRequest): Promise<void>;
835
+ protected handleGetWhatsAppTemplate(request: IGetWhatsAppTemplateRequest): Promise<IWhatsAppTemplate | null>;
716
836
  sendWhatsApp(request: ISendWhatsAppRequest, options?: IWhatsAppSenderOptions): Promise<void>;
717
837
  sendWhatsAppTemplate(request: ISendWhatsAppTemplateRequest, options?: IWhatsAppSenderOptions): Promise<void>;
718
838
  getWhatsAppTemplate(request: IGetWhatsAppTemplateRequest): Promise<IWhatsAppTemplate | null>;
@@ -758,126 +878,37 @@ declare class WhatsAppReceiverByWebHook extends WhatsAppReceiver {
758
878
  connect(): Promise<void>;
759
879
  }
760
880
 
761
- declare class WhatsAppSenderByDevConnection extends WhatsAppSender {
762
- private wabotDevConnection;
763
- constructor(wabotDevConnection: WabotDevConnection, chatRepository: ChatRepository, chatResolver: ChatResolver, whatsAppRepository: WhatsAppRepository);
881
+ declare class WhatsAppSenderByCloudApi extends WhatsAppSender {
882
+ constructor(chatRepository: ChatRepository, chatResolver: ChatResolver, whatsAppRepository: WhatsAppRepository);
764
883
  handleSendRequest(request: ISendWhatsAppRequest): Promise<void>;
765
884
  handleSendTemplateRequest(request: ISendWhatsAppTemplateRequest): Promise<void>;
766
885
  handleGetWhatsAppTemplate(request: IGetWhatsAppTemplateRequest): Promise<IWhatsAppTemplate | null>;
767
886
  }
768
887
 
769
- declare class WhatsAppSenderByCloudApi extends WhatsAppSender {
770
- constructor(chatRepository: ChatRepository, chatResolver: ChatResolver, whatsAppRepository: WhatsAppRepository);
888
+ declare class WhatsAppSenderByDevConnection extends WhatsAppSender {
889
+ private wabotDevConnection;
890
+ constructor(wabotDevConnection: WabotDevConnection, chatRepository: ChatRepository, chatResolver: ChatResolver, whatsAppRepository: WhatsAppRepository);
771
891
  handleSendRequest(request: ISendWhatsAppRequest): Promise<void>;
772
892
  handleSendTemplateRequest(request: ISendWhatsAppTemplateRequest): Promise<void>;
773
893
  handleGetWhatsAppTemplate(request: IGetWhatsAppTemplateRequest): Promise<IWhatsAppTemplate | null>;
774
894
  }
775
895
 
776
- interface ICrudRepository<T> {
777
- find(id: string): Promise<T | null>;
778
- findOrThrow(id: string): Promise<T>;
779
- findAll(id: string): Promise<T[]>;
780
- create(item: T): Promise<void>;
781
- update(item: T): Promise<void>;
782
- discard(item: T): Promise<void>;
783
- }
784
-
785
- type IPgRepositoryConfig<P extends Persistent> = {
786
- schema?: string;
787
- table: string;
788
- constructor: IConstructor<P>;
789
- add?: {
790
- columns: {
791
- [column: string]: {
792
- type: string;
793
- value: (item: P) => boolean | number | string | null | Date;
794
- };
795
- };
796
- };
797
- };
798
-
799
- declare class PgRepositoryBase<P extends Persistent> {
800
- protected pool: Pool;
801
- protected config: IPgRepositoryConfig<any>;
802
- private tableIsCreated;
803
- schema: string;
804
- table: string;
805
- columnsList: string[];
806
- columnsAndTypes: string;
807
- columns: string;
808
- vars: string;
809
- updates: string;
810
- addColumns: {
811
- [columns: string]: {
812
- type: string;
813
- value: (item: P) => number | boolean | string | null | Date;
814
- };
815
- };
816
- constructor(pool: Pool, config: IPgRepositoryConfig<any>);
817
- values(item: P): (string | number | boolean | Date | null)[];
818
- protected exec(sql: string, values: any[]): Promise<void>;
819
- protected query(sql: string, values: any[]): Promise<any[]>;
820
- protected connect(): Promise<Pool>;
821
- protected ensureTable(): Promise<void>;
822
- protected ensureColumns(): Promise<void>;
896
+ interface ICustomErrorData {
897
+ message: string;
898
+ humanMessage?: string;
899
+ code?: string;
900
+ httpCode?: number;
901
+ cause?: Error;
902
+ info?: any;
823
903
  }
824
-
825
- declare class PgCrudRepository<P extends Persistent> extends PgRepositoryBase<P> implements ICrudRepository<P> {
826
- protected readonly config: IPgRepositoryConfig<P>;
827
- constructor(pool: Pool, config: IPgRepositoryConfig<P>);
828
- find(id: string): Promise<P | null>;
829
- findOrThrow(id: string): Promise<P>;
830
- findAll(): Promise<P[]>;
831
- create(item: P): Promise<void>;
832
- update(item: P): Promise<void>;
833
- discard(item: P): Promise<void>;
904
+ declare class CustomError extends Error {
905
+ humanMessage?: string;
906
+ code?: string;
907
+ httpCode?: number;
908
+ info?: any;
909
+ constructor(data: ICustomErrorData);
834
910
  }
835
911
 
836
- declare class PgWhatsAppRepository extends PgCrudRepository<WhatsApp> implements IWhatsAppRepository {
837
- constructor(pool: Pool);
838
- findBySlug(slug: string): Promise<WhatsApp | null>;
839
- findByBusinessNumber(number: string): Promise<WhatsApp | null>;
840
- }
841
-
842
- type IWabotEnvType = 'development' | 'staging' | 'testing' | 'production';
843
- declare class WabotEnv {
844
- private envType;
845
- constructor();
846
- isDevelopment(): boolean;
847
- isProduction(): boolean;
848
- requireString(varName: string): string;
849
- }
850
-
851
- declare class EnvWhatsAppRepository implements IWhatsAppRepository {
852
- private env;
853
- constructor(env: WabotEnv);
854
- findBySlug(slug: string): Promise<WhatsApp | null>;
855
- findByBusinessNumber(number: string): Promise<WhatsApp | null>;
856
- private getFromEnvVars;
857
- }
858
-
859
- declare function prepareChatContainer(container: DependencyContainer$1, context: IMessageContext, mindsetCtor?: IConstructor<IMindset>): Promise<DependencyContainer$1>;
860
-
861
- interface IrunChannelProps {
862
- channel: IConstructor<IChatChannel>;
863
- channelConfig?: object;
864
- mindset: IConstructor<IMindset>;
865
- chatRepository: IConstructor<IChatRepository>;
866
- chatBotAdapter: IConstructor<IChatBotAdapter>;
867
- }
868
- declare function runChannel(props: IrunChannelProps): void;
869
-
870
- interface IServerProvider<T, ST extends T> {
871
- replace: IConstructor<T>;
872
- with: IConstructor<ST>;
873
- singleton?: true;
874
- }
875
- interface IServerConfig {
876
- controllers: IConstructor<any>[];
877
- providers?: IServerProvider<unknown, unknown>[];
878
- }
879
- declare function runServer(config: IServerConfig): void;
880
-
881
912
  declare class SendOneTimePasswordRequest {
882
913
  fromEmail: string;
883
914
  toEmail: string;
@@ -986,6 +1017,12 @@ interface IGetConfig {
986
1017
 
987
1018
  declare function get(config?: IGetConfig): (target: object, propertyKey: string | symbol) => void;
988
1019
 
1020
+ interface IMiddleware {
1021
+ handle(req: Request, res: Response, container: DependencyContainer$1): Promise<void>;
1022
+ }
1023
+
1024
+ declare function middleware(middlewareConstructor: IConstructor<IMiddleware>): (target: object, propertyKey: string | symbol) => void;
1025
+
989
1026
  interface IPostConfig {
990
1027
  path?: string;
991
1028
  }
@@ -1006,6 +1043,12 @@ interface IEndPointMetadata {
1006
1043
  paramsTypes: any[];
1007
1044
  }
1008
1045
 
1046
+ interface IMiddlewareMetadata {
1047
+ controllerConstructor: IConstructor<any>;
1048
+ functionName: string;
1049
+ middlewareConstructor: IConstructor<IMiddleware>;
1050
+ }
1051
+
1009
1052
  interface IRestControllerMetadata {
1010
1053
  controllerConstructor: IConstructor<any>;
1011
1054
  path: string;
@@ -1013,10 +1056,13 @@ interface IRestControllerMetadata {
1013
1056
 
1014
1057
  declare class RestControllerMetadataStore {
1015
1058
  private endPoints;
1059
+ private middlewares;
1016
1060
  private restControllers;
1017
1061
  saveControllerMetadata(controllerMetadata: IRestControllerMetadata): void;
1018
1062
  saveEndPointMetadata(endPointMetadata: IEndPointMetadata): void;
1063
+ saveMiddlewareMetadata(middlewareMetadata: IMiddlewareMetadata): void;
1019
1064
  getControllerEndPointsInfo(controllerConstructor: IConstructor<any>): {
1065
+ middlewares: IMiddlewareMetadata[];
1020
1066
  controller: IRestControllerMetadata;
1021
1067
  method: "get" | "post";
1022
1068
  path?: string;
@@ -1028,10 +1074,34 @@ declare class RestControllerMetadataStore {
1028
1074
 
1029
1075
  declare function runRestControllers(controllers: IConstructor<any>[], container: DependencyContainer$1): void;
1030
1076
 
1077
+ declare function prepareChatContainer(container: DependencyContainer$1, context: IMessageContext, mindsetCtor?: IConstructor<IMindset>): Promise<DependencyContainer$1>;
1078
+
1079
+ interface IrunChannelProps {
1080
+ channel: IConstructor<IChatChannel>;
1081
+ channelConfig?: object;
1082
+ mindset: IConstructor<IMindset>;
1083
+ chatRepository: IConstructor<IChatRepository>;
1084
+ chatBotAdapter: IConstructor<IChatBotAdapter>;
1085
+ }
1086
+ declare function runChannel(props: IrunChannelProps): void;
1087
+
1088
+ interface IServerProvider<T, ST extends T> {
1089
+ replace: IConstructor<T>;
1090
+ with: IConstructor<ST>;
1091
+ singleton?: true;
1092
+ }
1093
+ interface IServerConfig {
1094
+ controllers: IConstructor<any>[];
1095
+ providers?: IServerProvider<unknown, unknown>[];
1096
+ }
1097
+ declare function runServer(config: IServerConfig): void;
1098
+
1031
1099
  declare function isBoolean(): (target: object, propertyKey: string | symbol) => void;
1032
1100
 
1033
1101
  declare function isDate(): (target: object, propertyKey: string | symbol) => void;
1034
1102
 
1103
+ declare function isModel(model: IConstructor<any>): (target: object, propertyKey: string | symbol) => void;
1104
+
1035
1105
  declare function isNotEmpty(): (target: object, propertyKey: string | symbol) => void;
1036
1106
 
1037
1107
  declare function isNumber(): (target: object, propertyKey: string | symbol) => void;
@@ -1049,8 +1119,7 @@ declare function min(limit: any): (target: object, propertyKey: string | symbol)
1049
1119
  interface IValidationError {
1050
1120
  description: string;
1051
1121
  }
1052
- interface IModelValidationError {
1053
- model: IValidationError[];
1122
+ interface IModelValidationError extends IValidationError {
1054
1123
  properties: {
1055
1124
  name: string;
1056
1125
  errors: IValidationError[];
@@ -1119,4 +1188,4 @@ declare function validateModel<V>(value: any, info: IModelValidatorsInfo<V>): IM
1119
1188
 
1120
1189
  declare function validate<V>(value: any, modelConstructor: IConstructor<V>): IModelValidationResult<V>;
1121
1190
 
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 };
1191
+ export { AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, ClaudeChatBotAdapter, CmdChannel, Container, ControllerMetadataStore, CustomError, DeepSeekChatBotAdapter, EmailService, Entity, 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 ICustomErrorData, type IEmailService, type IEndPointMetadata, type IEntityData, type IGetConfig, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMiddlewareMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type 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 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 IWhatsAppTemplate, type IWhatsAppTemplateComponent, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppTemplateResponse, 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, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, max, middleware, 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 };