@wabot-dev/framework 0.9.1 → 0.9.5
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/addon/async/in-memory/InMemoryCronJobRepository.js +45 -0
- package/dist/src/addon/async/in-memory/InMemoryJobRepository.js +75 -0
- package/dist/src/addon/async/in-memory/index.js +2 -0
- package/dist/src/addon/async/pg/PgCronJobRepository.js +7 -5
- package/dist/src/addon/async/pg/PgJobRepository.js +8 -5
- package/dist/src/addon/async/pg/PgTransactionAdapter.js +25 -0
- package/dist/src/addon/async/pg/index.js +3 -0
- package/dist/src/addon/auth/api-key/ApiKey.js +4 -4
- package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +9 -8
- package/dist/src/addon/auth/jwt/JwtRefreshToken.js +4 -4
- package/dist/src/addon/auth/jwt/PgJwtRefreshTokenRepository.js +6 -5
- package/dist/src/addon/chat-bot/{ram/RamChatMemory.js → in-memory/InMemoryChatMemory.js} +2 -2
- package/dist/src/addon/chat-bot/{ram/RamChatRepository.js → in-memory/InMemoryChatRepository.js} +6 -6
- package/dist/src/addon/chat-bot/in-memory/index.js +2 -0
- package/dist/src/addon/chat-bot/pg/PgChatMemory.js +8 -7
- package/dist/src/addon/chat-bot/pg/PgChatRepository.js +7 -6
- package/dist/src/addon/chat-bot/pg/index.js +2 -0
- package/dist/src/addon/chat-controller/cmd/@cmd.js +7 -2
- package/dist/src/addon/chat-controller/cmd/CmdChannel.js +85 -61
- package/dist/src/addon/chat-controller/cmd/CmdChannelConfig.js +8 -0
- package/dist/src/addon/chat-controller/cmd/CmdChannelServer.js +169 -0
- package/dist/src/addon/chat-controller/cmd/cmdChannelSocketPath.js +16 -0
- package/dist/src/addon/chat-controller/cmd/runCmdClient.js +226 -0
- package/dist/src/addon/chat-controller/socket/@socket.js +3 -1
- package/dist/src/addon/chat-controller/socket/SocketChannelConfig.js +4 -4
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppSender.js +2 -72
- package/dist/src/addon/chat-controller/whatsapp/{WhatsAppReceiver.js → cloud-api/WhatsAppApiReceiver.js} +2 -2
- package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppApiSender.js +67 -0
- package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppReceiverByCloudApi.js +5 -7
- package/dist/src/addon/chat-controller/whatsapp/wasender/@wasender.js +23 -0
- package/dist/src/addon/chat-controller/{wasender/WhatsAppByWasenderChannel.js → whatsapp/wasender/WasenderChannel.js} +20 -20
- package/dist/src/addon/chat-controller/{wasender/WhatsAppByWasenderChannelConfig.js → whatsapp/wasender/WasenderChannelConfig.js} +3 -3
- package/dist/src/addon/chat-controller/whatsapp/wasender/WasenderChannelName.js +3 -0
- package/dist/src/addon/chat-controller/{wasender/WhatsAppReceiverByWasender.js → whatsapp/wasender/WasenderReceiver.js} +7 -7
- package/dist/src/addon/chat-controller/{wasender/WhatsAppSenderByWasender.js → whatsapp/wasender/WasenderSender.js} +8 -5
- package/dist/src/addon/chat-controller/{wasender → whatsapp/wasender}/WasenderWebhookController.js +4 -4
- package/dist/src/addon/lock/InMemoryLockKey.js +45 -0
- package/dist/src/addon/lock/InMemoryLocker.js +15 -0
- package/dist/src/addon/lock/index.js +2 -0
- package/dist/src/core/repository/CrudRepository.js +25 -0
- package/dist/src/feature/async/{@cron.js → @cronHandler.js} +2 -2
- package/dist/src/feature/async/@transaction.js +22 -0
- package/dist/src/feature/async/AsyncMetadataStore.js +6 -0
- package/dist/src/feature/async/TransactionMetadataStore.js +28 -0
- package/dist/src/feature/chat-controller/metadata/ControllerMetadataStore.js +3 -0
- package/dist/src/feature/pg/@pgExtension.js +33 -0
- package/dist/src/feature/pg/PgJsonRepositoryAdapter.js +50 -0
- package/dist/src/feature/pg/index.js +10 -0
- package/dist/src/feature/project-runner/ProjectRunner.js +276 -0
- package/dist/src/feature/repository/@memoryExtension.js +29 -0
- package/dist/src/feature/repository/@query.js +22 -0
- package/dist/src/feature/repository/@queryExtension.js +21 -0
- package/dist/src/feature/repository/@repository.js +170 -0
- package/dist/src/feature/repository/MemoryRepositoryAdapter.js +110 -0
- package/dist/src/feature/repository/RepositoryAdapterRegistry.js +27 -0
- package/dist/src/feature/repository/RepositoryMetadataStore.js +102 -0
- package/dist/src/feature/repository/evaluateQueryAst.js +134 -0
- package/dist/src/feature/rest-controller/metadata/RestControllerMetadataStore.js +3 -0
- package/dist/src/feature/socket-controller/metadata/SocketControllerMetadataStore.js +3 -0
- package/dist/src/index.d.ts +377 -298
- package/dist/src/index.js +40 -34
- package/package.json +9 -7
- package/dist/src/addon/chat-controller/wasender/@whatsAppByWasender.js +0 -20
- package/dist/src/addon/chat-controller/wasender/whatsAppByWasenderChannelName.js +0 -3
- package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +0 -20
- package/dist/src/addon/chat-controller/whatsapp/EnvWhatsAppRepository.js +0 -49
- package/dist/src/addon/chat-controller/whatsapp/PgWhatsAppRepository.js +0 -48
- package/dist/src/addon/chat-controller/whatsapp/WhatsApp.js +0 -30
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppChannel.js +0 -58
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppChannelConfig.js +0 -8
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppRepository.js +0 -10
- package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppSenderByCloudApi.js +0 -133
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppProxyContracts.js +0 -5
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppReceiverByWabotProxy.js +0 -67
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppSenderByWabotProxy.js +0 -63
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppWabotProxyConnection.js +0 -45
- package/dist/src/feature/pg/query/@pgJsonRepository.js +0 -73
- package/dist/src/feature/pg/query/@query.js +0 -14
- package/dist/src/feature/pg/query/PgJsonRepository.js +0 -23
- package/dist/src/feature/pg/query/PgRepositoryMetadataStore.js +0 -44
- /package/dist/src/addon/chat-controller/whatsapp/{whatsAppChannelName.js → cloud-api/whatsAppChannelName.js} +0 -0
- /package/dist/src/addon/chat-controller/{wasender → whatsapp/wasender}/extractNumberFromWasenderKey.js +0 -0
- /package/dist/src/feature/pg/{query/buildQuerySql.js → buildQuerySql.js} +0 -0
- /package/dist/src/feature/{pg/query → repository}/parseQueryMethodName.js +0 -0
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import { WhatsAppSender } from '../WhatsAppSender.js';
|
|
3
|
-
import { singleton } from '../../../../core/injection/index.js';
|
|
4
|
-
import { Logger } from '../../../../core/logger/Logger.js';
|
|
5
|
-
import '../../../../feature/chat-bot/ChatAdapterRegistry.js';
|
|
6
|
-
import '../../../../feature/chat-bot/ChatBot.js';
|
|
7
|
-
import '../../../../feature/chat-bot/ChatOperator.js';
|
|
8
|
-
import { ChatRepository } from '../../../../feature/chat-bot/ChatRepository.js';
|
|
9
|
-
import '../../../../feature/chat-bot/UnionChatAdapter.js';
|
|
10
|
-
import '../../../../feature/chat-bot/metadata/ChatAdapterMetadataStore.js';
|
|
11
|
-
import 'uuid';
|
|
12
|
-
import '../../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
13
|
-
import '../../../../core/error/setupErrorHandlers.js';
|
|
14
|
-
import '../../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
|
|
15
|
-
import { ChatResolver } from '../../../../feature/chat-controller/ChatResolver.js';
|
|
16
|
-
import '../../../../feature/chat-controller/runChatControllers.js';
|
|
17
|
-
import { WhatsAppRepository } from '../WhatsAppRepository.js';
|
|
18
|
-
import { WhatsAppWabotProxyConnection } from './WhatsAppWabotProxyConnection.js';
|
|
19
|
-
|
|
20
|
-
let WhatsAppSenderByWabotProxy = class WhatsAppSenderByWabotProxy extends WhatsAppSender {
|
|
21
|
-
wabotDevConnection;
|
|
22
|
-
logger = new Logger('wabot:whatsapp-sender-by-wabot-proxy');
|
|
23
|
-
constructor(wabotDevConnection, chatRepository, chatResolver, whatsAppRepository) {
|
|
24
|
-
super(chatRepository, chatResolver, whatsAppRepository);
|
|
25
|
-
this.wabotDevConnection = wabotDevConnection;
|
|
26
|
-
}
|
|
27
|
-
async sendWhatsApp(request, options) {
|
|
28
|
-
try {
|
|
29
|
-
const socket = await this.wabotDevConnection.getSocket();
|
|
30
|
-
const req = {
|
|
31
|
-
event: 'sendMessage',
|
|
32
|
-
data: {
|
|
33
|
-
from: request.from,
|
|
34
|
-
to: request.to,
|
|
35
|
-
content: {
|
|
36
|
-
text: request.message.text ?? 'No Text',
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
const ack = await socket.timeout(5000).emitWithAck(req.event, req.data);
|
|
41
|
-
if (!ack || !ack.success) {
|
|
42
|
-
throw new Error(`not success ack, when send whatsapp from '${request.from}' to '${request.to}'`);
|
|
43
|
-
}
|
|
44
|
-
this.logger.trace(`success send whatsapp from '${request.from}' to '${request.to}'`);
|
|
45
|
-
if (options?.writeChatMemory) {
|
|
46
|
-
await this.writePrivateChatMemory(request.message, request.to);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
catch (err) {
|
|
50
|
-
this.logger.error(`Failed to send WhatsApp from '${request.from}' to '${request.to}'`, err);
|
|
51
|
-
throw new Error(undefined, { cause: err });
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
WhatsAppSenderByWabotProxy = __decorate([
|
|
56
|
-
singleton(),
|
|
57
|
-
__metadata("design:paramtypes", [WhatsAppWabotProxyConnection,
|
|
58
|
-
ChatRepository,
|
|
59
|
-
ChatResolver,
|
|
60
|
-
WhatsAppRepository])
|
|
61
|
-
], WhatsAppSenderByWabotProxy);
|
|
62
|
-
|
|
63
|
-
export { WhatsAppSenderByWabotProxy };
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import { Env } from '../../../../core/env/Env.js';
|
|
3
|
-
import { injectable } from '../../../../core/injection/index.js';
|
|
4
|
-
import { Logger } from '../../../../core/logger/Logger.js';
|
|
5
|
-
import { io } from 'socket.io-client';
|
|
6
|
-
|
|
7
|
-
let WhatsAppWabotProxyConnection = class WhatsAppWabotProxyConnection {
|
|
8
|
-
baseUrl;
|
|
9
|
-
socket = null;
|
|
10
|
-
apiKey;
|
|
11
|
-
logger = new Logger('wabot:whats-app-wabot-proxy-connection');
|
|
12
|
-
constructor(env) {
|
|
13
|
-
this.apiKey = env.requireString('WABOT_API_KEY');
|
|
14
|
-
this.baseUrl = env.requireString('WABOT_PROXY_URL');
|
|
15
|
-
while (this.baseUrl.endsWith('/')) {
|
|
16
|
-
this.baseUrl = this.baseUrl.substring(0, this.baseUrl.length - 1);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
async getSocket() {
|
|
20
|
-
if (this.socket) {
|
|
21
|
-
return this.socket;
|
|
22
|
-
}
|
|
23
|
-
return new Promise((resolve, reject) => {
|
|
24
|
-
const socket = io(`${this.baseUrl}/whats-app`, {
|
|
25
|
-
autoConnect: false,
|
|
26
|
-
auth: { token: this.apiKey },
|
|
27
|
-
reconnection: true,
|
|
28
|
-
});
|
|
29
|
-
socket.on('connect', async () => {
|
|
30
|
-
this.socket = socket;
|
|
31
|
-
resolve(socket);
|
|
32
|
-
});
|
|
33
|
-
socket.on('connect_error', (err) => {
|
|
34
|
-
reject(new Error(err && err.message ? err.message : 'connection error', { cause: err }));
|
|
35
|
-
});
|
|
36
|
-
socket.connect();
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
WhatsAppWabotProxyConnection = __decorate([
|
|
41
|
-
injectable(),
|
|
42
|
-
__metadata("design:paramtypes", [Env])
|
|
43
|
-
], WhatsAppWabotProxyConnection);
|
|
44
|
-
|
|
45
|
-
export { WhatsAppWabotProxyConnection };
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { container, singleton } from '../../../core/injection/index.js';
|
|
2
|
-
import { withPgClient } from '../withPgClient.js';
|
|
3
|
-
import { buildQuerySql } from './buildQuerySql.js';
|
|
4
|
-
import { parseQueryMethodName } from './parseQueryMethodName.js';
|
|
5
|
-
import { PgJsonRepository } from './PgJsonRepository.js';
|
|
6
|
-
import { PgRepositoryMetadataStore } from './PgRepositoryMetadataStore.js';
|
|
7
|
-
|
|
8
|
-
const QUERY_CACHE_KEY = Symbol('wabot:pgQueryCache');
|
|
9
|
-
function makeQueryImpl(methodName, ast) {
|
|
10
|
-
return async function (...args) {
|
|
11
|
-
let cache = this[QUERY_CACHE_KEY];
|
|
12
|
-
if (!cache) {
|
|
13
|
-
cache = new Map();
|
|
14
|
-
Object.defineProperty(this, QUERY_CACHE_KEY, { value: cache, enumerable: false });
|
|
15
|
-
}
|
|
16
|
-
let built = cache.get(methodName);
|
|
17
|
-
if (!built) {
|
|
18
|
-
built = buildQuerySql(ast, this.table, this.columns);
|
|
19
|
-
cache.set(methodName, built);
|
|
20
|
-
}
|
|
21
|
-
const params = built.buildParams(args);
|
|
22
|
-
switch (ast.prefix) {
|
|
23
|
-
case 'find': {
|
|
24
|
-
return await this.query(built.sql, params);
|
|
25
|
-
}
|
|
26
|
-
case 'findOne': {
|
|
27
|
-
const items = await this.query(built.sql, params);
|
|
28
|
-
return items[0] ?? null;
|
|
29
|
-
}
|
|
30
|
-
case 'count': {
|
|
31
|
-
return await withPgClient(this.pool, async (client) => {
|
|
32
|
-
await this.ensureTable(client);
|
|
33
|
-
const result = await client.query(built.sql, params);
|
|
34
|
-
return result.rows[0]?.count ?? 0;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
case 'exists': {
|
|
38
|
-
return await withPgClient(this.pool, async (client) => {
|
|
39
|
-
await this.ensureTable(client);
|
|
40
|
-
const result = await client.query(built.sql, params);
|
|
41
|
-
return Boolean(result.rows[0]?.exists);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
case 'delete': {
|
|
45
|
-
await this.exec(built.sql, params);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function pgJsonRepository(config) {
|
|
52
|
-
return function (target) {
|
|
53
|
-
if (target !== PgJsonRepository && !(target.prototype instanceof PgJsonRepository)) {
|
|
54
|
-
throw new Error(`@pgJsonRepository: ${target.name} must extend PgJsonRepository`);
|
|
55
|
-
}
|
|
56
|
-
const store = container.resolve(PgRepositoryMetadataStore);
|
|
57
|
-
store.saveRepositoryConfig(target, config);
|
|
58
|
-
const queryMethods = store.getQueryMethods(target);
|
|
59
|
-
for (const meta of queryMethods) {
|
|
60
|
-
if (Object.prototype.hasOwnProperty.call(target.prototype, meta.functionName)) {
|
|
61
|
-
const existing = target.prototype[meta.functionName];
|
|
62
|
-
if (typeof existing === 'function') {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const ast = parseQueryMethodName(meta.functionName);
|
|
67
|
-
target.prototype[meta.functionName] = makeQueryImpl(meta.functionName, ast);
|
|
68
|
-
}
|
|
69
|
-
singleton()(target);
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export { pgJsonRepository };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { container } from '../../../core/injection/index.js';
|
|
2
|
-
import { PgRepositoryMetadataStore } from './PgRepositoryMetadataStore.js';
|
|
3
|
-
|
|
4
|
-
function query() {
|
|
5
|
-
return function (target, propertyKey) {
|
|
6
|
-
const store = container.resolve(PgRepositoryMetadataStore);
|
|
7
|
-
store.saveQueryMethodMetadata({
|
|
8
|
-
repositoryConstructor: target.constructor,
|
|
9
|
-
functionName: propertyKey.toString(),
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { query };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import { Pool } from 'pg';
|
|
3
|
-
import { injectable, container } from '../../../core/injection/index.js';
|
|
4
|
-
import { PgCrudRepository } from '../PgCrudRepository.js';
|
|
5
|
-
import { PgRepositoryMetadataStore } from './PgRepositoryMetadataStore.js';
|
|
6
|
-
|
|
7
|
-
let PgJsonRepository = class PgJsonRepository extends PgCrudRepository {
|
|
8
|
-
constructor(pool) {
|
|
9
|
-
const ctor = new.target;
|
|
10
|
-
const store = container.resolve(PgRepositoryMetadataStore);
|
|
11
|
-
const config = store.getRepositoryConfig(ctor);
|
|
12
|
-
if (!config) {
|
|
13
|
-
throw new Error(`${ctor.name} must be decorated with @pgJsonRepository`);
|
|
14
|
-
}
|
|
15
|
-
super(pool, config);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
PgJsonRepository = __decorate([
|
|
19
|
-
injectable(),
|
|
20
|
-
__metadata("design:paramtypes", [Pool])
|
|
21
|
-
], PgJsonRepository);
|
|
22
|
-
|
|
23
|
-
export { PgJsonRepository };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { __decorate } from 'tslib';
|
|
2
|
-
import { singleton } from '../../../core/injection/index.js';
|
|
3
|
-
|
|
4
|
-
let PgRepositoryMetadataStore = class PgRepositoryMetadataStore {
|
|
5
|
-
queryMethods = new Map();
|
|
6
|
-
repositoryConfigs = new Map();
|
|
7
|
-
saveQueryMethodMetadata(metadata) {
|
|
8
|
-
let perClass = this.queryMethods.get(metadata.repositoryConstructor);
|
|
9
|
-
if (!perClass) {
|
|
10
|
-
perClass = new Map();
|
|
11
|
-
this.queryMethods.set(metadata.repositoryConstructor, perClass);
|
|
12
|
-
}
|
|
13
|
-
perClass.set(metadata.functionName, metadata);
|
|
14
|
-
}
|
|
15
|
-
saveRepositoryConfig(ctor, config) {
|
|
16
|
-
this.repositoryConfigs.set(ctor, config);
|
|
17
|
-
}
|
|
18
|
-
getRepositoryConfig(ctor) {
|
|
19
|
-
return this.repositoryConfigs.get(ctor);
|
|
20
|
-
}
|
|
21
|
-
getQueryMethods(ctor) {
|
|
22
|
-
const collected = new Map();
|
|
23
|
-
const hierarchy = [];
|
|
24
|
-
let proto = ctor.prototype;
|
|
25
|
-
while (proto && proto.constructor !== Object) {
|
|
26
|
-
hierarchy.unshift(proto.constructor);
|
|
27
|
-
proto = Object.getPrototypeOf(proto);
|
|
28
|
-
}
|
|
29
|
-
for (const cls of hierarchy) {
|
|
30
|
-
const perClass = this.queryMethods.get(cls);
|
|
31
|
-
if (perClass) {
|
|
32
|
-
for (const [name, meta] of perClass) {
|
|
33
|
-
collected.set(name, meta);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return [...collected.values()];
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
PgRepositoryMetadataStore = __decorate([
|
|
41
|
-
singleton()
|
|
42
|
-
], PgRepositoryMetadataStore);
|
|
43
|
-
|
|
44
|
-
export { PgRepositoryMetadataStore };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|