@wabot-dev/framework 0.1.0-beta.1 → 0.1.0-beta.10
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.
- package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +12 -13
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +9 -7
- package/dist/src/channels/cmd/@cmd.js +0 -4
- package/dist/src/channels/cmd/CmdChannel.js +0 -4
- package/dist/src/channels/express/ExpressProvider.js +46 -0
- package/dist/src/channels/http/HttpServerProvider.js +31 -0
- package/dist/src/channels/{socket-io → socket}/@socket.js +0 -4
- package/dist/src/channels/{socket-io → socket}/SocketChannel.js +12 -11
- package/dist/src/channels/socket/SocketServerProvider.js +50 -0
- package/dist/src/channels/telegram/@telegram.js +0 -4
- package/dist/src/channels/telegram/TelegramChannel.js +0 -4
- package/dist/src/channels/wabot/WabotDevConnection.js +57 -0
- package/dist/src/channels/{whatsapp/WhatsAppDevSocketContracts.js → wabot/WabotDevSocketContracts.js} +3 -3
- package/dist/src/channels/whatsapp/@whatsapp.js +0 -4
- package/dist/src/channels/whatsapp/EnvWhatsAppRepository.js +49 -0
- package/dist/src/channels/whatsapp/PgWhatsAppRepository.js +41 -0
- package/dist/src/channels/whatsapp/WhatsApp.js +32 -0
- package/dist/src/channels/whatsapp/WhatsAppChannel.js +33 -32
- package/dist/src/channels/whatsapp/{WhatsAppConnection.js → WhatsAppReceiver.js} +4 -6
- package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +32 -0
- package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +63 -0
- package/dist/src/channels/whatsapp/WhatsAppRepository.js +10 -0
- package/dist/src/channels/whatsapp/WhatsAppSender.js +93 -17
- package/dist/src/channels/whatsapp/WhatsAppSenderByCloudApi.js +124 -0
- package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +61 -0
- package/dist/src/chatbot/ChatBotAdapter.js +1 -5
- package/dist/src/chatbot/metadata/@chatBot.js +0 -5
- package/dist/src/chatbot/metadata/ChatBotMetadataStore.js +0 -5
- package/dist/src/controller/metadata/ControllerMetadataStore.js +0 -2
- package/dist/src/controller/metadata/controller/@chatController.js +0 -2
- package/dist/src/core/IMessageContext.js +0 -2
- package/dist/src/env/WabotEnv.js +6 -0
- package/dist/src/index.d.ts +421 -201
- package/dist/src/index.js +55 -28
- package/dist/src/mindset/MindsetOperator.js +1 -3
- package/dist/src/mindset/metadata/MindsetMetadataStore.js +0 -2
- package/dist/src/mindset/metadata/mindsets/@mindset.js +0 -2
- package/dist/src/mindset/metadata/modules/@mindsetModule.js +0 -2
- package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -2
- package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -2
- package/dist/src/pre-made/module/html/HtmlModule.js +70 -0
- package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -2
- package/dist/src/pre-made/repository/chat/pg/PgChatMemory.js +1 -7
- package/dist/src/pre-made/repository/chat/pg/PgChatRepository.js +0 -5
- package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -5
- package/dist/src/repository/pg/PgCrudRepository.js +7 -1
- package/dist/src/rest-controller/metadata/@get.js +19 -0
- package/dist/src/rest-controller/metadata/@post.js +19 -0
- package/dist/src/rest-controller/metadata/@restController.js +15 -0
- package/dist/src/rest-controller/metadata/RestControllerMetadataStore.js +37 -0
- package/dist/src/rest-controller/runRestControllers.js +74 -0
- package/dist/src/server/prepareChatContainer.js +4 -4
- package/dist/src/server/runChannel.js +2 -10
- package/dist/src/server/runServer.js +0 -43
- package/dist/src/validation/metadata/@isBoolean.js +17 -0
- package/dist/src/validation/metadata/@isDate.js +17 -0
- package/dist/src/validation/metadata/@isNotEmpty.js +17 -0
- package/dist/src/validation/metadata/@isNumber.js +17 -0
- package/dist/src/validation/metadata/@isOptional.js +17 -0
- package/dist/src/validation/metadata/@isPresent.js +17 -0
- package/dist/src/validation/metadata/@isString.js +17 -0
- package/dist/src/validation/metadata/@max.js +18 -0
- package/dist/src/validation/metadata/@min.js +18 -0
- package/dist/src/validation/metadata/@validable.js +14 -0
- package/dist/src/validation/metadata/ValidationMetadataStore.js +55 -0
- package/dist/src/validation/validateModel2.js +11 -0
- package/dist/src/validation/validators/validateIsBoolean.js +12 -0
- package/dist/src/validation/validators/validateIsDate.js +16 -0
- package/dist/src/validation/validators/validateIsNotEmpty.js +12 -0
- package/dist/src/validation/validators/validateIsNumber.js +12 -0
- package/dist/src/validation/validators/validateIsOptional.js +5 -0
- package/dist/src/validation/validators/validateIsPresent.js +12 -0
- package/dist/src/validation/validators/validateIsString.js +12 -0
- package/dist/src/validation/validators/validateMax.js +17 -0
- package/dist/src/validation/validators/validateMin.js +17 -0
- package/dist/src/validation/validators/validateModel.js +47 -0
- package/package.json +4 -6
- package/dist/src/channels/whatsapp/WhatsAppDevConnection.js +0 -69
- package/dist/src/channels/whatsapp/WhatsAppProdConnection.js +0 -39
- package/dist/src/controller/express/Express.js +0 -5
- package/dist/src/controller/socket.io/SocketIO.js +0 -5
- package/dist/src/mindset/metadata/params/@isOptional.js +0 -21
- package/dist/src/pre-made/repository/chat/sqlite/SqliteChatMemory.js +0 -23
- package/dist/src/pre-made/repository/chat/sqlite/SqliteChatRepository.js +0 -30
- package/dist/src/pre-made/repository/user/sqlite/SqliteUserRepository.js +0 -23
- package/dist/src/repository/sqlite/SqliteCrudRepository.js +0 -85
- package/dist/src/repository/sqlite/SqlitePersistentMapper.js +0 -17
- /package/dist/src/channels/{socket-io → socket}/SocketChannelConfig.js +0 -0
|
@@ -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 };
|
|
File without changes
|