@wabot-dev/framework 0.0.16 → 0.0.50

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 (111) hide show
  1. package/dist/src/_virtual/_commonjsHelpers.js +5 -0
  2. package/dist/src/_virtual/cjs.js +7 -0
  3. package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +107 -0
  4. package/dist/src/ai/openia/OpenaiChatBotAdapter.js +9 -7
  5. package/dist/src/channels/cmd/@cmd.js +0 -4
  6. package/dist/src/channels/cmd/CmdChannel.js +0 -4
  7. package/dist/src/channels/express/ExpressProvider.js +46 -0
  8. package/dist/src/channels/http/HttpServerProvider.js +31 -0
  9. package/dist/src/channels/socket/@socket.js +20 -0
  10. package/dist/src/channels/socket/SocketChannel.js +79 -0
  11. package/dist/src/channels/socket/SocketChannelConfig.js +15 -0
  12. package/dist/src/channels/socket/SocketServerProvider.js +50 -0
  13. package/dist/src/channels/telegram/@telegram.js +0 -4
  14. package/dist/src/channels/telegram/TelegramChannel.js +0 -4
  15. package/dist/src/channels/wabot/WabotDevConnection.js +57 -0
  16. package/dist/src/channels/wabot/WabotDevSocketContracts.js +10 -0
  17. package/dist/src/channels/whatsapp/@whatsapp.js +0 -4
  18. package/dist/src/channels/whatsapp/EnvWhatsAppRepository.js +49 -0
  19. package/dist/src/channels/whatsapp/PgWhatsAppRepository.js +41 -0
  20. package/dist/src/channels/whatsapp/WhatsApp.js +32 -0
  21. package/dist/src/channels/whatsapp/WhatsAppChannel.js +33 -32
  22. package/dist/src/channels/whatsapp/{WhatsAppConnection.js → WhatsAppReceiver.js} +4 -6
  23. package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +32 -0
  24. package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +63 -0
  25. package/dist/src/channels/whatsapp/WhatsAppRepository.js +10 -0
  26. package/dist/src/channels/whatsapp/WhatsAppSender.js +99 -0
  27. package/dist/src/channels/whatsapp/WhatsAppSenderByCloudApi.js +124 -0
  28. package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +61 -0
  29. package/dist/src/chatbot/ChatBotAdapter.js +1 -5
  30. package/dist/src/chatbot/metadata/@chatBot.js +0 -5
  31. package/dist/src/chatbot/metadata/ChatBotMetadataStore.js +0 -5
  32. package/dist/src/controller/metadata/ControllerMetadataStore.js +0 -2
  33. package/dist/src/controller/metadata/controller/@chatController.js +0 -2
  34. package/dist/src/core/IMessageContext.js +0 -2
  35. package/dist/src/env/WabotEnv.js +6 -0
  36. package/dist/src/index.d.ts +454 -163
  37. package/dist/src/index.js +56 -21
  38. package/dist/src/mindset/MindsetOperator.js +1 -3
  39. package/dist/src/mindset/metadata/MindsetMetadataStore.js +0 -2
  40. package/dist/src/mindset/metadata/mindsets/@mindset.js +0 -2
  41. package/dist/src/mindset/metadata/modules/@mindsetModule.js +0 -2
  42. package/dist/src/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js +90 -0
  43. package/dist/src/node_modules/deepmerge/dist/cjs.js +142 -0
  44. package/dist/src/node_modules/dom-serializer/lib/esm/foreignNames.js +102 -0
  45. package/dist/src/node_modules/dom-serializer/lib/esm/index.js +186 -0
  46. package/dist/src/node_modules/domelementtype/lib/esm/index.js +53 -0
  47. package/dist/src/node_modules/domhandler/lib/esm/index.js +148 -0
  48. package/dist/src/node_modules/domhandler/lib/esm/node.js +334 -0
  49. package/dist/src/node_modules/entities/lib/esm/decode.js +458 -0
  50. package/dist/src/node_modules/entities/lib/esm/decode_codepoint.js +62 -0
  51. package/dist/src/node_modules/entities/lib/esm/escape.js +99 -0
  52. package/dist/src/node_modules/entities/lib/esm/generated/decode-data-html.js +8 -0
  53. package/dist/src/node_modules/entities/lib/esm/generated/decode-data-xml.js +8 -0
  54. package/dist/src/node_modules/html-to-text/lib/html-to-text.js +2147 -0
  55. package/dist/src/node_modules/htmlparser2/lib/esm/Parser.js +491 -0
  56. package/dist/src/node_modules/htmlparser2/lib/esm/Tokenizer.js +928 -0
  57. package/dist/src/node_modules/htmlparser2/lib/esm/index.js +18 -0
  58. package/dist/src/node_modules/leac/lib/leac.js +3 -0
  59. package/dist/src/node_modules/parseley/lib/parseley.js +270 -0
  60. package/dist/src/node_modules/peberminta/lib/core.js +171 -0
  61. package/dist/src/node_modules/selderee/lib/selderee.js +380 -0
  62. package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -2
  63. package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -2
  64. package/dist/src/pre-made/module/html/HtmlModule.js +70 -0
  65. package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -2
  66. package/dist/src/pre-made/repository/chat/pg/PgChatMemory.js +1 -7
  67. package/dist/src/pre-made/repository/chat/pg/PgChatRepository.js +0 -5
  68. package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -5
  69. package/dist/src/repository/pg/PgCrudRepository.js +0 -1
  70. package/dist/src/rest-controller/metadata/@get.js +19 -0
  71. package/dist/src/rest-controller/metadata/@post.js +19 -0
  72. package/dist/src/rest-controller/metadata/@restController.js +15 -0
  73. package/dist/src/rest-controller/metadata/RestControllerMetadataStore.js +37 -0
  74. package/dist/src/rest-controller/runRestControllers.js +74 -0
  75. package/dist/src/server/prepareChatContainer.js +4 -4
  76. package/dist/src/server/runChannel.js +2 -10
  77. package/dist/src/server/runServer.js +0 -43
  78. package/dist/src/validation/metadata/@isBoolean.js +17 -0
  79. package/dist/src/validation/metadata/@isDate.js +17 -0
  80. package/dist/src/validation/metadata/@isNotEmpty.js +17 -0
  81. package/dist/src/validation/metadata/@isNumber.js +17 -0
  82. package/dist/src/validation/metadata/@isOptional.js +17 -0
  83. package/dist/src/validation/metadata/@isPresent.js +17 -0
  84. package/dist/src/validation/metadata/@isString.js +17 -0
  85. package/dist/src/validation/metadata/@max.js +18 -0
  86. package/dist/src/validation/metadata/@min.js +18 -0
  87. package/dist/src/validation/metadata/@validable.js +14 -0
  88. package/dist/src/validation/metadata/ValidationMetadataStore.js +55 -0
  89. package/dist/src/validation/validateModel2.js +11 -0
  90. package/dist/src/validation/validators/validateIsBoolean.js +12 -0
  91. package/dist/src/validation/validators/validateIsDate.js +16 -0
  92. package/dist/src/validation/validators/validateIsNotEmpty.js +12 -0
  93. package/dist/src/validation/validators/validateIsNumber.js +12 -0
  94. package/dist/src/validation/validators/validateIsOptional.js +5 -0
  95. package/dist/src/validation/validators/validateIsPresent.js +12 -0
  96. package/dist/src/validation/validators/validateIsString.js +12 -0
  97. package/dist/src/validation/validators/validateMax.js +17 -0
  98. package/dist/src/validation/validators/validateMin.js +17 -0
  99. package/dist/src/validation/validators/validateModel.js +47 -0
  100. package/package.json +4 -6
  101. package/dist/src/channels/whatsapp/WhatsAppDevConnection.js +0 -61
  102. package/dist/src/channels/whatsapp/WhatsAppProdConnection.js +0 -36
  103. package/dist/src/channels/whatsapp/whatsAppDevSocketContracts.js +0 -9
  104. package/dist/src/controller/express/Express.js +0 -5
  105. package/dist/src/controller/socket.io/SocketIO.js +0 -5
  106. package/dist/src/mindset/metadata/params/@isOptional.js +0 -21
  107. package/dist/src/pre-made/repository/chat/sqlite/SqliteChatMemory.js +0 -23
  108. package/dist/src/pre-made/repository/chat/sqlite/SqliteChatRepository.js +0 -30
  109. package/dist/src/pre-made/repository/user/sqlite/SqliteUserRepository.js +0 -23
  110. package/dist/src/repository/sqlite/SqliteCrudRepository.js +0 -85
  111. package/dist/src/repository/sqlite/SqlitePersistentMapper.js +0 -17
@@ -1,61 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { singleton } from '../../injection/index.js';
3
- import { Logger } from '../../logger/Logger.js';
4
- import { io } from 'socket.io-client';
5
- import { WhatsAppConnection } from './WhatsAppConnection.js';
6
- import { devWhatsappEmitEvent, devWhatsAppListentEvent } from './whatsAppDevSocketContracts.js';
7
-
8
- let WhatsAppDevConnection = class WhatsAppDevConnection extends WhatsAppConnection {
9
- devProxy;
10
- devProxySocket;
11
- devToken;
12
- connected = false;
13
- constructor() {
14
- super(new Logger('wabot:whatsapp-dev-connection'));
15
- this.devProxy = process.env.WABOT_DEV_PROXY ?? 'https://proxy.wabot.dev';
16
- this.devToken = process.env.WABOT_DEV_TOKEN;
17
- this.devProxySocket = io(this.devProxy, { autoConnect: false });
18
- }
19
- async sendWhatsApp(businessNumber, to, chatMessage) {
20
- const req = {
21
- from: businessNumber,
22
- to,
23
- message: chatMessage,
24
- };
25
- await this.devProxySocket.emitWithAck(devWhatsappEmitEvent.DEV_SEND_WHATSAPP, req);
26
- }
27
- connect() {
28
- if (this.connected) {
29
- return;
30
- }
31
- this.connected = true;
32
- this.devProxySocket.connect();
33
- this.devProxySocket.on('connect', async () => {
34
- if (!this.devToken) {
35
- return;
36
- }
37
- try {
38
- const req = {
39
- token: this.devToken,
40
- };
41
- const ack = await this.devProxySocket.emitWithAck(devWhatsappEmitEvent.DEV_CONNECTION, req);
42
- if (ack != 'OK') {
43
- return this.logger.debug('dev connection fails');
44
- }
45
- this.devProxySocket.on(devWhatsAppListentEvent.DEV_WATSAPP_WEBHOOK, async (payload) => {
46
- await this.handlePayload(payload);
47
- });
48
- return this.logger.debug('success dev connection');
49
- }
50
- catch (err) {
51
- this.logger.error(err);
52
- }
53
- });
54
- }
55
- };
56
- WhatsAppDevConnection = __decorate([
57
- singleton(),
58
- __metadata("design:paramtypes", [])
59
- ], WhatsAppDevConnection);
60
-
61
- export { WhatsAppDevConnection };
@@ -1,36 +0,0 @@
1
- import { __decorate, __param, __metadata } from 'tslib';
2
- import '../../controller/channel/ChatResolver.js';
3
- import '../../controller/channel/UserResolver.js';
4
- import { inject } from '../../injection/index.js';
5
- import '../../core/chat/repository/IChatRepository.js';
6
- import '../../core/user/IUserRepository.js';
7
- import '../../controller/metadata/ControllerMetadataStore.js';
8
- import { ExpressApp } from '../../controller/express/Express.js';
9
- import 'socket.io';
10
- import { singleton } from 'tsyringe';
11
-
12
- let WhatsAppProdConnection = class WhatsAppProdConnection {
13
- express;
14
- constructor(express) {
15
- this.express = express;
16
- this.express.get('/try-express', (req, res) => {
17
- res.status(200).json({ success: true });
18
- });
19
- }
20
- listenMessage(businessNumber, listener) {
21
- throw new Error('Method not implemented.');
22
- }
23
- sendWhatsApp(businessNumber, to, replyMessage) {
24
- throw new Error('Method not implemented.');
25
- }
26
- connect() {
27
- throw new Error('Method not implemented.');
28
- }
29
- };
30
- WhatsAppProdConnection = __decorate([
31
- singleton(),
32
- __param(0, inject(ExpressApp)),
33
- __metadata("design:paramtypes", [Function])
34
- ], WhatsAppProdConnection);
35
-
36
- export { WhatsAppProdConnection };
@@ -1,9 +0,0 @@
1
- const devWhatsAppListentEvent = {
2
- DEV_WATSAPP_WEBHOOK: 'dev-whatsapp-webhook',
3
- };
4
- const devWhatsappEmitEvent = {
5
- DEV_CONNECTION: 'dev-connection',
6
- DEV_SEND_WHATSAPP: 'dev-send-whatsapp',
7
- };
8
-
9
- export { devWhatsAppListentEvent, devWhatsappEmitEvent };
@@ -1,5 +0,0 @@
1
- import 'express';
2
-
3
- const ExpressApp = Symbol.for('ExpressApp');
4
-
5
- export { ExpressApp };
@@ -1,5 +0,0 @@
1
- import 'socket.io';
2
-
3
- const SocketIoApp = Symbol.for('SocketIoApp');
4
-
5
- export { SocketIoApp };
@@ -1,21 +0,0 @@
1
- import 'reflect-metadata';
2
- import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
3
- import { container } from '../../../injection/index.js';
4
- import { PARAM_DECORATION_IS_OPTIONAL } from './decoratorNames.js';
5
-
6
- function isOptional() {
7
- return (target, propertyKey) => {
8
- const paramName = propertyKey.toString();
9
- const paramType = Reflect.getMetadata('design:type', target, paramName);
10
- const store = container.resolve(MindsetMetadataStore);
11
- store.saveParamDecoration({
12
- decorationName: PARAM_DECORATION_IS_OPTIONAL,
13
- paramType: paramType,
14
- paramName: paramName,
15
- constructor: target.constructor,
16
- decorationConfig: {},
17
- });
18
- };
19
- }
20
-
21
- export { isOptional };
@@ -1,23 +0,0 @@
1
- import path from 'path';
2
- import { ChatItem } from '../../../../core/chat/ChatItem.js';
3
- import '../../../../core/chat/repository/IChatRepository.js';
4
- import '../../../../core/user/IUserRepository.js';
5
- import 'pg';
6
- import 'short-uuid';
7
- import { SqliteCrudRepository } from '../../../../repository/sqlite/SqliteCrudRepository.js';
8
- import { sqliteMapperFor } from '../../../../repository/sqlite/SqlitePersistentMapper.js';
9
-
10
- class SqliteChatMemory extends SqliteCrudRepository {
11
- constructor(chatId) {
12
- super('chat_item', SqliteChatMemory.getDbPath(chatId), sqliteMapperFor(ChatItem));
13
- }
14
- async findLastItems(count) {
15
- const allItems = await this.findAll();
16
- return allItems.slice(allItems.length - count, allItems.length);
17
- }
18
- static getDbPath(chatId) {
19
- return path.join(process.cwd(), '.sqlite', 'chat-memory', chatId + '.db');
20
- }
21
- }
22
-
23
- export { SqliteChatMemory };
@@ -1,30 +0,0 @@
1
- import '../../../../core/chat/repository/IChatRepository.js';
2
- import { Chat } from '../../../../core/chat/Chat.js';
3
- import '../../../../core/user/IUserRepository.js';
4
- import path from 'path';
5
- import { SqliteChatMemory } from './SqliteChatMemory.js';
6
- import 'pg';
7
- import 'short-uuid';
8
- import { SqliteCrudRepository } from '../../../../repository/sqlite/SqliteCrudRepository.js';
9
- import { sqliteMapperFor } from '../../../../repository/sqlite/SqlitePersistentMapper.js';
10
-
11
- class SqliteChatRepository extends SqliteCrudRepository {
12
- constructor() {
13
- super('chat', SqliteChatRepository.getDbPath(), sqliteMapperFor(Chat));
14
- }
15
- async findByConnection(query) {
16
- const allChats = await this.findAll();
17
- return allChats.find((chat) => chat.hasConnection(query)) ?? null;
18
- }
19
- async findMemory(chatId) {
20
- const chat = await this.find(chatId);
21
- if (!chat)
22
- return null;
23
- return new SqliteChatMemory(chatId);
24
- }
25
- static getDbPath() {
26
- return path.join(process.cwd(), '.sqlite', 'chat.db');
27
- }
28
- }
29
-
30
- export { SqliteChatRepository };
@@ -1,23 +0,0 @@
1
- import '../../../../core/chat/repository/IChatRepository.js';
2
- import { User } from '../../../../core/user/User.js';
3
- import '../../../../core/user/IUserRepository.js';
4
- import 'pg';
5
- import 'short-uuid';
6
- import { SqliteCrudRepository } from '../../../../repository/sqlite/SqliteCrudRepository.js';
7
- import { sqliteMapperFor } from '../../../../repository/sqlite/SqlitePersistentMapper.js';
8
- import path from 'path';
9
-
10
- class SqliteUserRepository extends SqliteCrudRepository {
11
- constructor() {
12
- super('user', SqliteUserRepository.getDbPath(), sqliteMapperFor(User));
13
- }
14
- async findByConnection(query) {
15
- const allItems = await this.findAll();
16
- return allItems.find((item) => item.hasConnection(query)) ?? null;
17
- }
18
- static getDbPath() {
19
- return path.join(process.cwd(), '.sqlite', 'user.db');
20
- }
21
- }
22
-
23
- export { SqliteUserRepository };
@@ -1,85 +0,0 @@
1
- import { promises } from 'fs';
2
- import path from 'path';
3
- import { open } from 'sqlite';
4
- import sqlite3 from 'sqlite3';
5
- import { v4 } from 'uuid';
6
-
7
- class SqliteCrudRepository {
8
- table;
9
- dbPath;
10
- mapper;
11
- tableCreated = false;
12
- constructor(table, dbPath, mapper) {
13
- this.table = table;
14
- this.dbPath = dbPath;
15
- this.mapper = mapper;
16
- }
17
- async find(id) {
18
- const db = await this.getDb();
19
- const result = await db.all(`SELECT id, data FROM ${this.table} WHERE id=?`, [
20
- id,
21
- ]);
22
- db.close();
23
- if (result.length < 1) {
24
- return null;
25
- }
26
- const item = this.mapper.rev(result[0].data);
27
- return item;
28
- }
29
- async findAll() {
30
- const db = await this.getDb();
31
- const result = await db.all(`SELECT id, data FROM ${this.table}`);
32
- db.close();
33
- const items = result.map((item) => this.mapper.rev(item.data));
34
- return items;
35
- }
36
- async create(item) {
37
- if (item.wasCreated()) {
38
- throw new Error('Item already created');
39
- }
40
- item['data'].id = v4();
41
- item['data'].createdAt = new Date().getTime();
42
- item.validate();
43
- const db = await this.getDb();
44
- await db.run(`INSERT INTO ${this.table} VALUES (?, ?, ?)`, [
45
- item.getId(),
46
- item.getCreatedAt().getTime(),
47
- this.mapper.map(item),
48
- ]);
49
- db.close();
50
- }
51
- async update(item) {
52
- if (!item.wasCreated()) {
53
- throw new Error('Item is not created');
54
- }
55
- item.validate();
56
- const db = await this.getDb();
57
- await db.run(`UPDATE ${this.table} SET data=? WHERE id=?`, [
58
- this.mapper.map(item),
59
- item.getId(),
60
- ]);
61
- db.close();
62
- }
63
- async discard(item) {
64
- item.discard();
65
- await this.update(item);
66
- }
67
- async getDb() {
68
- const dbDirPath = path.dirname(this.dbPath);
69
- await promises.mkdir(dbDirPath, { recursive: true });
70
- const db = await open({
71
- filename: this.dbPath,
72
- driver: sqlite3.Database,
73
- });
74
- if (!this.tableCreated) {
75
- this.tableCreated = true;
76
- await this.createTable(db);
77
- }
78
- return db;
79
- }
80
- async createTable(db) {
81
- await db.exec(`CREATE TABLE IF NOT EXISTS ${this.table}(id TEXT, created_at INTEGER, data TEXT)`);
82
- }
83
- }
84
-
85
- export { SqliteCrudRepository };
@@ -1,17 +0,0 @@
1
- class SqlitePersistentMapper {
2
- ctor;
3
- constructor(ctor) {
4
- this.ctor = ctor;
5
- }
6
- map(input) {
7
- return JSON.stringify(input['data']);
8
- }
9
- rev(input) {
10
- return new this.ctor(JSON.parse(input));
11
- }
12
- }
13
- function sqliteMapperFor(ctor) {
14
- return new SqlitePersistentMapper(ctor);
15
- }
16
-
17
- export { SqlitePersistentMapper, sqliteMapperFor };