From 8ece6fb9981e403ffb1ee81a718596d1debe9ff1 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Fri, 12 Apr 2024 17:13:15 -0300 Subject: [PATCH] fix: reorganization of files and folders --- CHANGELOG.md | 1 + package.json | 2 +- .../abstract/abstract.cache.ts | 0 .../abstract/abstract.repository.ts | 0 .../abstract/abstract.router.ts | 0 .../controllers/chamaai.controller.ts | 0 .../controllers/chat.controller.ts | 0 .../controllers/group.controller.ts | 0 .../controllers/instance.controller.ts | 10 +- .../controllers/label.controller.ts | 0 .../controllers/proxy.controller.ts | 0 .../controllers/sendMessage.controller.ts | 0 .../controllers/settings.controller.ts | 0 .../controllers/webhook.controller.ts | 0 src/{whatsapp => api}/dto/chamaai.dto.ts | 0 src/{whatsapp => api}/dto/chat.dto.ts | 0 src/{whatsapp => api}/dto/group.dto.ts | 0 src/{whatsapp => api}/dto/instance.dto.ts | 0 src/{whatsapp => api}/dto/integration.dto.ts | 0 src/{whatsapp => api}/dto/label.dto.ts | 0 src/{whatsapp => api}/dto/proxy.dto.ts | 0 src/{whatsapp => api}/dto/sendMessage.dto.ts | 0 src/{whatsapp => api}/dto/settings.dto.ts | 0 src/{whatsapp => api}/dto/webhook.dto.ts | 0 src/{whatsapp => api}/guards/auth.guard.ts | 2 +- .../guards/instance.guard.ts | 2 +- .../chatwoot/cache}/cacheengine.ts | 4 +- .../chatwoot/cache}/localcache.ts | 4 +- .../chatwoot/cache}/rediscache.client.ts | 4 +- .../chatwoot/cache}/rediscache.ts | 6 +- .../controllers/chatwoot.controller.ts | 16 +- .../chatwoot}/dto/chatwoot.dto.ts | 0 .../chatwoot}/libs/postgres.client.ts | 4 +- .../chatwoot}/models/chatwoot.model.ts | 2 +- .../repository/chatwoot.repository.ts | 8 +- .../chatwoot/routes}/chatwoot.router.ts | 12 +- .../chatwoot}/services/chatwoot.service.ts | 22 +-- .../chatwoot}/utils/chatwoot-import-helper.ts | 10 +- .../chatwoot/validate/chatwoot.schema.ts | 42 +++++ .../controllers/rabbitmq.controller.ts | 4 +- .../rabbitmq}/dto/rabbitmq.dto.ts | 0 .../rabbitmq}/libs/amqp.server.ts | 4 +- .../rabbitmq}/models/rabbitmq.model.ts | 2 +- .../repository/rabbitmq.repository.ts | 8 +- .../rabbitmq/routes}/rabbitmq.router.ts | 12 +- .../rabbitmq}/services/rabbitmq.service.ts | 10 +- .../rabbitmq/validate/rabbitmq.schema.ts | 66 ++++++++ .../sqs}/controllers/sqs.controller.ts | 4 +- .../integrations/sqs}/dto/sqs.dto.ts | 0 .../integrations/sqs}/libs/sqs.server.ts | 4 +- .../integrations/sqs}/models/sqs.model.ts | 2 +- .../sqs}/repository/sqs.repository.ts | 8 +- .../integrations/sqs/routes}/sqs.router.ts | 12 +- .../integrations/sqs}/services/sqs.service.ts | 10 +- .../integrations/sqs/validate/sqs.schema.ts | 66 ++++++++ .../controllers/typebot.controller.ts | 4 +- .../integrations/typebot}/dto/typebot.dto.ts | 0 .../typebot}/models/typebot.model.ts | 2 +- .../typebot}/repository/typebot.repository.ts | 8 +- .../typebot/routes}/typebot.router.ts | 12 +- .../typebot}/services/typebot.service.ts | 12 +- .../typebot/validate/typebot.schema.ts | 60 +++++++ .../controllers/websocket.controller.ts | 4 +- .../websocket}/dto/websocket.dto.ts | 0 .../websocket}/libs/socket.server.ts | 4 +- .../websocket}/models/websocket.model.ts | 2 +- .../repository/websocket.repository.ts | 8 +- .../websocket/routes}/websocket.router.ts | 12 +- .../websocket}/services/websocket.service.ts | 8 +- .../websocket/validate/websocket.schema.ts | 66 ++++++++ src/{whatsapp => api}/models/auth.model.ts | 0 src/{whatsapp => api}/models/chamaai.model.ts | 0 src/{whatsapp => api}/models/chat.model.ts | 0 src/{whatsapp => api}/models/contact.model.ts | 0 src/{whatsapp => api}/models/index.ts | 10 +- .../models/integration.model.ts | 0 src/{whatsapp => api}/models/label.model.ts | 0 src/{whatsapp => api}/models/message.model.ts | 0 src/{whatsapp => api}/models/proxy.model.ts | 0 .../models/settings.model.ts | 0 src/{whatsapp => api}/models/webhook.model.ts | 0 .../repository/auth.repository.ts | 0 .../repository/chamaai.repository.ts | 0 .../repository/chat.repository.ts | 0 .../repository/contact.repository.ts | 0 .../repository/integration.repository.ts | 0 .../repository/label.repository.ts | 0 .../repository/message.repository.ts | 0 .../repository/messageUp.repository.ts | 0 .../repository/proxy.repository.ts | 0 .../repository/repository.manager.ts | 10 +- .../repository/settings.repository.ts | 0 .../repository/webhook.repository.ts | 0 .../routers/chamaai.router.ts | 2 +- src/{whatsapp => api}/routers/chat.router.ts | 2 +- src/{whatsapp => api}/routers/group.router.ts | 2 +- src/{whatsapp => api}/routers/index.router.ts | 10 +- .../routers/instance.router.ts | 2 +- src/{whatsapp => api}/routers/label.router.ts | 2 +- src/{whatsapp => api}/routers/proxy.router.ts | 2 +- .../routers/sendMessage.router.ts | 2 +- .../routers/settings.router.ts | 2 +- src/{whatsapp => api}/routers/view.router.ts | 0 .../routers/webhook.router.ts | 2 +- .../server.module.ts} | 32 ++-- .../services/auth.service.ts | 0 .../services/cache.service.ts | 0 .../services/chamaai.service.ts | 0 .../services/integration.service.ts | 0 .../services/monitor.service.ts | 0 .../services/proxy.service.ts | 0 .../services/settings.service.ts | 0 .../services/webhook.service.ts | 0 .../services/whatsapp.baileys.service.ts | 4 +- .../services/whatsapp.business.service.ts | 0 .../services/whatsapp.service.ts | 16 +- src/{whatsapp => api}/types/wa.types.ts | 0 src/exceptions/400.exception.ts | 2 +- src/exceptions/401.exception.ts | 2 +- src/exceptions/403.exception.ts | 2 +- src/exceptions/404.exception.ts | 2 +- src/exceptions/500.exception.ts | 2 +- src/main.ts | 10 +- src/utils/makeProxyAgent.ts | 2 +- src/validate/validate.schema.ts | 156 +----------------- 125 files changed, 500 insertions(+), 343 deletions(-) rename src/{whatsapp => api}/abstract/abstract.cache.ts (100%) rename src/{whatsapp => api}/abstract/abstract.repository.ts (100%) rename src/{whatsapp => api}/abstract/abstract.router.ts (100%) rename src/{whatsapp => api}/controllers/chamaai.controller.ts (100%) rename src/{whatsapp => api}/controllers/chat.controller.ts (100%) rename src/{whatsapp => api}/controllers/group.controller.ts (100%) rename src/{whatsapp => api}/controllers/instance.controller.ts (98%) rename src/{whatsapp => api}/controllers/label.controller.ts (100%) rename src/{whatsapp => api}/controllers/proxy.controller.ts (100%) rename src/{whatsapp => api}/controllers/sendMessage.controller.ts (100%) rename src/{whatsapp => api}/controllers/settings.controller.ts (100%) rename src/{whatsapp => api}/controllers/webhook.controller.ts (100%) rename src/{whatsapp => api}/dto/chamaai.dto.ts (100%) rename src/{whatsapp => api}/dto/chat.dto.ts (100%) rename src/{whatsapp => api}/dto/group.dto.ts (100%) rename src/{whatsapp => api}/dto/instance.dto.ts (100%) rename src/{whatsapp => api}/dto/integration.dto.ts (100%) rename src/{whatsapp => api}/dto/label.dto.ts (100%) rename src/{whatsapp => api}/dto/proxy.dto.ts (100%) rename src/{whatsapp => api}/dto/sendMessage.dto.ts (100%) rename src/{whatsapp => api}/dto/settings.dto.ts (100%) rename src/{whatsapp => api}/dto/webhook.dto.ts (100%) rename src/{whatsapp => api}/guards/auth.guard.ts (98%) rename src/{whatsapp => api}/guards/instance.guard.ts (97%) rename src/{libs => api/integrations/chatwoot/cache}/cacheengine.ts (81%) rename src/{libs => api/integrations/chatwoot/cache}/localcache.ts (89%) rename src/{libs => api/integrations/chatwoot/cache}/rediscache.client.ts (90%) rename src/{libs => api/integrations/chatwoot/cache}/rediscache.ts (90%) rename src/{whatsapp => api/integrations/chatwoot}/controllers/chatwoot.controller.ts (86%) rename src/{whatsapp => api/integrations/chatwoot}/dto/chatwoot.dto.ts (100%) rename src/{ => api/integrations/chatwoot}/libs/postgres.client.ts (88%) rename src/{whatsapp => api/integrations/chatwoot}/models/chatwoot.model.ts (95%) rename src/{whatsapp => api/integrations/chatwoot}/repository/chatwoot.repository.ts (87%) rename src/{whatsapp/routers => api/integrations/chatwoot/routes}/chatwoot.router.ts (84%) rename src/{whatsapp => api/integrations/chatwoot}/services/chatwoot.service.ts (99%) rename src/{ => api/integrations/chatwoot}/utils/chatwoot-import-helper.ts (98%) create mode 100644 src/api/integrations/chatwoot/validate/chatwoot.schema.ts rename src/{whatsapp => api/integrations/rabbitmq}/controllers/rabbitmq.controller.ts (93%) rename src/{whatsapp => api/integrations/rabbitmq}/dto/rabbitmq.dto.ts (100%) rename src/{ => api/integrations/rabbitmq}/libs/amqp.server.ts (94%) rename src/{whatsapp => api/integrations/rabbitmq}/models/rabbitmq.model.ts (88%) rename src/{whatsapp => api/integrations/rabbitmq}/repository/rabbitmq.repository.ts (87%) rename src/{whatsapp/routers => api/integrations/rabbitmq/routes}/rabbitmq.router.ts (79%) rename src/{whatsapp => api/integrations/rabbitmq}/services/rabbitmq.service.ts (77%) create mode 100644 src/api/integrations/rabbitmq/validate/rabbitmq.schema.ts rename src/{whatsapp => api/integrations/sqs}/controllers/sqs.controller.ts (92%) rename src/{whatsapp => api/integrations/sqs}/dto/sqs.dto.ts (100%) rename src/{ => api/integrations/sqs}/libs/sqs.server.ts (94%) rename src/{whatsapp => api/integrations/sqs}/models/sqs.model.ts (87%) rename src/{whatsapp => api/integrations/sqs}/repository/sqs.repository.ts (87%) rename src/{whatsapp/routers => api/integrations/sqs/routes}/sqs.router.ts (79%) rename src/{whatsapp => api/integrations/sqs}/services/sqs.service.ts (76%) create mode 100644 src/api/integrations/sqs/validate/sqs.schema.ts rename src/{whatsapp => api/integrations/typebot}/controllers/typebot.controller.ts (92%) rename src/{whatsapp => api/integrations/typebot}/dto/typebot.dto.ts (100%) rename src/{whatsapp => api/integrations/typebot}/models/typebot.model.ts (96%) rename src/{whatsapp => api/integrations/typebot}/repository/typebot.repository.ts (88%) rename src/{whatsapp/routers => api/integrations/typebot/routes}/typebot.router.ts (88%) rename src/{whatsapp => api/integrations/typebot}/services/typebot.service.ts (98%) create mode 100644 src/api/integrations/typebot/validate/typebot.schema.ts rename src/{whatsapp => api/integrations/websocket}/controllers/websocket.controller.ts (93%) rename src/{whatsapp => api/integrations/websocket}/dto/websocket.dto.ts (100%) rename src/{ => api/integrations/websocket}/libs/socket.server.ts (86%) rename src/{whatsapp => api/integrations/websocket}/models/websocket.model.ts (89%) rename src/{whatsapp => api/integrations/websocket}/repository/websocket.repository.ts (87%) rename src/{whatsapp/routers => api/integrations/websocket/routes}/websocket.router.ts (79%) rename src/{whatsapp => api/integrations/websocket}/services/websocket.service.ts (79%) create mode 100644 src/api/integrations/websocket/validate/websocket.schema.ts rename src/{whatsapp => api}/models/auth.model.ts (100%) rename src/{whatsapp => api}/models/chamaai.model.ts (100%) rename src/{whatsapp => api}/models/chat.model.ts (100%) rename src/{whatsapp => api}/models/contact.model.ts (100%) rename src/{whatsapp => api}/models/index.ts (51%) rename src/{whatsapp => api}/models/integration.model.ts (100%) rename src/{whatsapp => api}/models/label.model.ts (100%) rename src/{whatsapp => api}/models/message.model.ts (100%) rename src/{whatsapp => api}/models/proxy.model.ts (100%) rename src/{whatsapp => api}/models/settings.model.ts (100%) rename src/{whatsapp => api}/models/webhook.model.ts (100%) rename src/{whatsapp => api}/repository/auth.repository.ts (100%) rename src/{whatsapp => api}/repository/chamaai.repository.ts (100%) rename src/{whatsapp => api}/repository/chat.repository.ts (100%) rename src/{whatsapp => api}/repository/contact.repository.ts (100%) rename src/{whatsapp => api}/repository/integration.repository.ts (100%) rename src/{whatsapp => api}/repository/label.repository.ts (100%) rename src/{whatsapp => api}/repository/message.repository.ts (100%) rename src/{whatsapp => api}/repository/messageUp.repository.ts (100%) rename src/{whatsapp => api}/repository/proxy.repository.ts (100%) rename src/{whatsapp => api}/repository/repository.manager.ts (93%) rename src/{whatsapp => api}/repository/settings.repository.ts (100%) rename src/{whatsapp => api}/repository/webhook.repository.ts (100%) rename src/{whatsapp => api}/routers/chamaai.router.ts (96%) rename src/{whatsapp => api}/routers/chat.router.ts (99%) rename src/{whatsapp => api}/routers/group.router.ts (99%) rename src/{whatsapp => api}/routers/index.router.ts (86%) rename src/{whatsapp => api}/routers/instance.router.ts (99%) rename src/{whatsapp => api}/routers/label.router.ts (97%) rename src/{whatsapp => api}/routers/proxy.router.ts (97%) rename src/{whatsapp => api}/routers/sendMessage.router.ts (99%) rename src/{whatsapp => api}/routers/settings.router.ts (96%) rename src/{whatsapp => api}/routers/view.router.ts (100%) rename src/{whatsapp => api}/routers/webhook.router.ts (98%) rename src/{whatsapp/whatsapp.module.ts => api/server.module.ts} (82%) rename src/{whatsapp => api}/services/auth.service.ts (100%) rename src/{whatsapp => api}/services/cache.service.ts (100%) rename src/{whatsapp => api}/services/chamaai.service.ts (100%) rename src/{whatsapp => api}/services/integration.service.ts (100%) rename src/{whatsapp => api}/services/monitor.service.ts (100%) rename src/{whatsapp => api}/services/proxy.service.ts (100%) rename src/{whatsapp => api}/services/settings.service.ts (100%) rename src/{whatsapp => api}/services/webhook.service.ts (100%) rename src/{whatsapp => api}/services/whatsapp.baileys.service.ts (99%) rename src/{whatsapp => api}/services/whatsapp.business.service.ts (100%) rename src/{whatsapp => api}/services/whatsapp.service.ts (98%) rename src/{whatsapp => api}/types/wa.types.ts (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index f86bcbfd..52d7080e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * Fix conversation read on chatwoot version 3.7 * Fix when receiving/sending messages from whatsapp desktop with ephemeral messages enabled * Changed returned sessions on typebot status change +* Reorganization of files and folders # 1.7.1 (2024-04-03 10:19) diff --git a/package.json b/package.json index aaef4f8a..8b31f902 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "evolution-api", - "version": "1.7.1", + "version": "1.7.2", "description": "Rest api for communication with WhatsApp", "main": "./dist/src/main.js", "scripts": { diff --git a/src/whatsapp/abstract/abstract.cache.ts b/src/api/abstract/abstract.cache.ts similarity index 100% rename from src/whatsapp/abstract/abstract.cache.ts rename to src/api/abstract/abstract.cache.ts diff --git a/src/whatsapp/abstract/abstract.repository.ts b/src/api/abstract/abstract.repository.ts similarity index 100% rename from src/whatsapp/abstract/abstract.repository.ts rename to src/api/abstract/abstract.repository.ts diff --git a/src/whatsapp/abstract/abstract.router.ts b/src/api/abstract/abstract.router.ts similarity index 100% rename from src/whatsapp/abstract/abstract.router.ts rename to src/api/abstract/abstract.router.ts diff --git a/src/whatsapp/controllers/chamaai.controller.ts b/src/api/controllers/chamaai.controller.ts similarity index 100% rename from src/whatsapp/controllers/chamaai.controller.ts rename to src/api/controllers/chamaai.controller.ts diff --git a/src/whatsapp/controllers/chat.controller.ts b/src/api/controllers/chat.controller.ts similarity index 100% rename from src/whatsapp/controllers/chat.controller.ts rename to src/api/controllers/chat.controller.ts diff --git a/src/whatsapp/controllers/group.controller.ts b/src/api/controllers/group.controller.ts similarity index 100% rename from src/whatsapp/controllers/group.controller.ts rename to src/api/controllers/group.controller.ts diff --git a/src/whatsapp/controllers/instance.controller.ts b/src/api/controllers/instance.controller.ts similarity index 98% rename from src/whatsapp/controllers/instance.controller.ts rename to src/api/controllers/instance.controller.ts index cf731064..4767db73 100644 --- a/src/whatsapp/controllers/instance.controller.ts +++ b/src/api/controllers/instance.controller.ts @@ -8,18 +8,18 @@ import { Logger } from '../../config/logger.config'; import { BadRequestException, InternalServerErrorException } from '../../exceptions'; import { RedisCache } from '../../libs/redis.client'; import { InstanceDto, SetPresenceDto } from '../dto/instance.dto'; +import { ChatwootService } from '../integrations/chatwoot/services/chatwoot.service'; +import { RabbitmqService } from '../integrations/rabbitmq/services/rabbitmq.service'; +import { SqsService } from '../integrations/sqs/services/sqs.service'; +import { TypebotService } from '../integrations/typebot/services/typebot.service'; +import { WebsocketService } from '../integrations/websocket/services/websocket.service'; import { RepositoryBroker } from '../repository/repository.manager'; import { AuthService, OldToken } from '../services/auth.service'; import { CacheService } from '../services/cache.service'; -import { ChatwootService } from '../services/chatwoot.service'; import { IntegrationService } from '../services/integration.service'; import { WAMonitoringService } from '../services/monitor.service'; -import { RabbitmqService } from '../services/rabbitmq.service'; import { SettingsService } from '../services/settings.service'; -import { SqsService } from '../services/sqs.service'; -import { TypebotService } from '../services/typebot.service'; import { WebhookService } from '../services/webhook.service'; -import { WebsocketService } from '../services/websocket.service'; import { BaileysStartupService } from '../services/whatsapp.baileys.service'; import { BusinessStartupService } from '../services/whatsapp.business.service'; import { Events, Integration, wa } from '../types/wa.types'; diff --git a/src/whatsapp/controllers/label.controller.ts b/src/api/controllers/label.controller.ts similarity index 100% rename from src/whatsapp/controllers/label.controller.ts rename to src/api/controllers/label.controller.ts diff --git a/src/whatsapp/controllers/proxy.controller.ts b/src/api/controllers/proxy.controller.ts similarity index 100% rename from src/whatsapp/controllers/proxy.controller.ts rename to src/api/controllers/proxy.controller.ts diff --git a/src/whatsapp/controllers/sendMessage.controller.ts b/src/api/controllers/sendMessage.controller.ts similarity index 100% rename from src/whatsapp/controllers/sendMessage.controller.ts rename to src/api/controllers/sendMessage.controller.ts diff --git a/src/whatsapp/controllers/settings.controller.ts b/src/api/controllers/settings.controller.ts similarity index 100% rename from src/whatsapp/controllers/settings.controller.ts rename to src/api/controllers/settings.controller.ts diff --git a/src/whatsapp/controllers/webhook.controller.ts b/src/api/controllers/webhook.controller.ts similarity index 100% rename from src/whatsapp/controllers/webhook.controller.ts rename to src/api/controllers/webhook.controller.ts diff --git a/src/whatsapp/dto/chamaai.dto.ts b/src/api/dto/chamaai.dto.ts similarity index 100% rename from src/whatsapp/dto/chamaai.dto.ts rename to src/api/dto/chamaai.dto.ts diff --git a/src/whatsapp/dto/chat.dto.ts b/src/api/dto/chat.dto.ts similarity index 100% rename from src/whatsapp/dto/chat.dto.ts rename to src/api/dto/chat.dto.ts diff --git a/src/whatsapp/dto/group.dto.ts b/src/api/dto/group.dto.ts similarity index 100% rename from src/whatsapp/dto/group.dto.ts rename to src/api/dto/group.dto.ts diff --git a/src/whatsapp/dto/instance.dto.ts b/src/api/dto/instance.dto.ts similarity index 100% rename from src/whatsapp/dto/instance.dto.ts rename to src/api/dto/instance.dto.ts diff --git a/src/whatsapp/dto/integration.dto.ts b/src/api/dto/integration.dto.ts similarity index 100% rename from src/whatsapp/dto/integration.dto.ts rename to src/api/dto/integration.dto.ts diff --git a/src/whatsapp/dto/label.dto.ts b/src/api/dto/label.dto.ts similarity index 100% rename from src/whatsapp/dto/label.dto.ts rename to src/api/dto/label.dto.ts diff --git a/src/whatsapp/dto/proxy.dto.ts b/src/api/dto/proxy.dto.ts similarity index 100% rename from src/whatsapp/dto/proxy.dto.ts rename to src/api/dto/proxy.dto.ts diff --git a/src/whatsapp/dto/sendMessage.dto.ts b/src/api/dto/sendMessage.dto.ts similarity index 100% rename from src/whatsapp/dto/sendMessage.dto.ts rename to src/api/dto/sendMessage.dto.ts diff --git a/src/whatsapp/dto/settings.dto.ts b/src/api/dto/settings.dto.ts similarity index 100% rename from src/whatsapp/dto/settings.dto.ts rename to src/api/dto/settings.dto.ts diff --git a/src/whatsapp/dto/webhook.dto.ts b/src/api/dto/webhook.dto.ts similarity index 100% rename from src/whatsapp/dto/webhook.dto.ts rename to src/api/dto/webhook.dto.ts diff --git a/src/whatsapp/guards/auth.guard.ts b/src/api/guards/auth.guard.ts similarity index 98% rename from src/whatsapp/guards/auth.guard.ts rename to src/api/guards/auth.guard.ts index a72ebfff..ccc73a58 100644 --- a/src/whatsapp/guards/auth.guard.ts +++ b/src/api/guards/auth.guard.ts @@ -7,8 +7,8 @@ import { Auth, configService } from '../../config/env.config'; import { Logger } from '../../config/logger.config'; import { ForbiddenException, UnauthorizedException } from '../../exceptions'; import { InstanceDto } from '../dto/instance.dto'; +import { repository } from '../server.module'; import { JwtPayload } from '../services/auth.service'; -import { repository } from '../whatsapp.module'; const logger = new Logger('GUARD'); diff --git a/src/whatsapp/guards/instance.guard.ts b/src/api/guards/instance.guard.ts similarity index 97% rename from src/whatsapp/guards/instance.guard.ts rename to src/api/guards/instance.guard.ts index 6b193411..2214bd43 100644 --- a/src/whatsapp/guards/instance.guard.ts +++ b/src/api/guards/instance.guard.ts @@ -12,7 +12,7 @@ import { } from '../../exceptions'; import { dbserver } from '../../libs/db.connect'; import { InstanceDto } from '../dto/instance.dto'; -import { cache, waMonitor } from '../whatsapp.module'; +import { cache, waMonitor } from '../server.module'; async function getInstance(instanceName: string) { try { diff --git a/src/libs/cacheengine.ts b/src/api/integrations/chatwoot/cache/cacheengine.ts similarity index 81% rename from src/libs/cacheengine.ts rename to src/api/integrations/chatwoot/cache/cacheengine.ts index a22d7e68..a05e3dae 100644 --- a/src/libs/cacheengine.ts +++ b/src/api/integrations/chatwoot/cache/cacheengine.ts @@ -1,5 +1,5 @@ -import { CacheConf, ConfigService } from '../config/env.config'; -import { ICache } from '../whatsapp/abstract/abstract.cache'; +import { CacheConf, ConfigService } from '../../../../config/env.config'; +import { ICache } from '../../../abstract/abstract.cache'; import { LocalCache } from './localcache'; import { RedisCache } from './rediscache'; diff --git a/src/libs/localcache.ts b/src/api/integrations/chatwoot/cache/localcache.ts similarity index 89% rename from src/libs/localcache.ts rename to src/api/integrations/chatwoot/cache/localcache.ts index fe1f295f..7bf53e71 100644 --- a/src/libs/localcache.ts +++ b/src/api/integrations/chatwoot/cache/localcache.ts @@ -1,7 +1,7 @@ import NodeCache from 'node-cache'; -import { CacheConf, CacheConfLocal, ConfigService } from '../config/env.config'; -import { ICache } from '../whatsapp/abstract/abstract.cache'; +import { CacheConf, CacheConfLocal, ConfigService } from '../../../../config/env.config'; +import { ICache } from '../../../abstract/abstract.cache'; export class LocalCache implements ICache { private conf: CacheConfLocal; diff --git a/src/libs/rediscache.client.ts b/src/api/integrations/chatwoot/cache/rediscache.client.ts similarity index 90% rename from src/libs/rediscache.client.ts rename to src/api/integrations/chatwoot/cache/rediscache.client.ts index b3f8dead..0a3ef4fc 100644 --- a/src/libs/rediscache.client.ts +++ b/src/api/integrations/chatwoot/cache/rediscache.client.ts @@ -1,7 +1,7 @@ import { createClient, RedisClientType } from 'redis'; -import { CacheConf, CacheConfRedis, configService } from '../config/env.config'; -import { Logger } from '../config/logger.config'; +import { CacheConf, CacheConfRedis, configService } from '../../../../config/env.config'; +import { Logger } from '../../../../config/logger.config'; class Redis { private logger = new Logger(Redis.name); diff --git a/src/libs/rediscache.ts b/src/api/integrations/chatwoot/cache/rediscache.ts similarity index 90% rename from src/libs/rediscache.ts rename to src/api/integrations/chatwoot/cache/rediscache.ts index cd0b1283..2a08fb3a 100644 --- a/src/libs/rediscache.ts +++ b/src/api/integrations/chatwoot/cache/rediscache.ts @@ -1,8 +1,8 @@ import { RedisClientType } from 'redis'; -import { CacheConf, CacheConfRedis, ConfigService } from '../config/env.config'; -import { Logger } from '../config/logger.config'; -import { ICache } from '../whatsapp/abstract/abstract.cache'; +import { CacheConf, CacheConfRedis, ConfigService } from '../../../../config/env.config'; +import { Logger } from '../../../../config/logger.config'; +import { ICache } from '../../../abstract/abstract.cache'; import { redisClient } from './rediscache.client'; export class RedisCache implements ICache { diff --git a/src/whatsapp/controllers/chatwoot.controller.ts b/src/api/integrations/chatwoot/controllers/chatwoot.controller.ts similarity index 86% rename from src/whatsapp/controllers/chatwoot.controller.ts rename to src/api/integrations/chatwoot/controllers/chatwoot.controller.ts index 2cccf280..03282ce5 100644 --- a/src/whatsapp/controllers/chatwoot.controller.ts +++ b/src/api/integrations/chatwoot/controllers/chatwoot.controller.ts @@ -1,15 +1,15 @@ import { isURL } from 'class-validator'; -import { ConfigService, HttpServer } from '../../config/env.config'; -import { Logger } from '../../config/logger.config'; -import { BadRequestException } from '../../exceptions'; -import { CacheEngine } from '../../libs/cacheengine'; +import { ConfigService, HttpServer } from '../../../../config/env.config'; +import { Logger } from '../../../../config/logger.config'; +import { BadRequestException } from '../../../../exceptions'; +import { InstanceDto } from '../../../dto/instance.dto'; +import { RepositoryBroker } from '../../../repository/repository.manager'; +import { waMonitor } from '../../../server.module'; +import { CacheService } from '../../../services/cache.service'; +import { CacheEngine } from '../cache/cacheengine'; import { ChatwootDto } from '../dto/chatwoot.dto'; -import { InstanceDto } from '../dto/instance.dto'; -import { RepositoryBroker } from '../repository/repository.manager'; -import { CacheService } from '../services/cache.service'; import { ChatwootService } from '../services/chatwoot.service'; -import { waMonitor } from '../whatsapp.module'; const logger = new Logger('ChatwootController'); diff --git a/src/whatsapp/dto/chatwoot.dto.ts b/src/api/integrations/chatwoot/dto/chatwoot.dto.ts similarity index 100% rename from src/whatsapp/dto/chatwoot.dto.ts rename to src/api/integrations/chatwoot/dto/chatwoot.dto.ts diff --git a/src/libs/postgres.client.ts b/src/api/integrations/chatwoot/libs/postgres.client.ts similarity index 88% rename from src/libs/postgres.client.ts rename to src/api/integrations/chatwoot/libs/postgres.client.ts index d1a68cdf..1211b075 100644 --- a/src/libs/postgres.client.ts +++ b/src/api/integrations/chatwoot/libs/postgres.client.ts @@ -1,7 +1,7 @@ import postgresql from 'pg'; -import { Chatwoot, configService } from '../config/env.config'; -import { Logger } from '../config/logger.config'; +import { Chatwoot, configService } from '../../../../config/env.config'; +import { Logger } from '../../../../config/logger.config'; const { Pool } = postgresql; diff --git a/src/whatsapp/models/chatwoot.model.ts b/src/api/integrations/chatwoot/models/chatwoot.model.ts similarity index 95% rename from src/whatsapp/models/chatwoot.model.ts rename to src/api/integrations/chatwoot/models/chatwoot.model.ts index e16352e1..659b847c 100644 --- a/src/whatsapp/models/chatwoot.model.ts +++ b/src/api/integrations/chatwoot/models/chatwoot.model.ts @@ -1,6 +1,6 @@ import { Schema } from 'mongoose'; -import { dbserver } from '../../libs/db.connect'; +import { dbserver } from '../../../../libs/db.connect'; export class ChatwootRaw { _id?: string; diff --git a/src/whatsapp/repository/chatwoot.repository.ts b/src/api/integrations/chatwoot/repository/chatwoot.repository.ts similarity index 87% rename from src/whatsapp/repository/chatwoot.repository.ts rename to src/api/integrations/chatwoot/repository/chatwoot.repository.ts index 47398d68..820f54af 100644 --- a/src/whatsapp/repository/chatwoot.repository.ts +++ b/src/api/integrations/chatwoot/repository/chatwoot.repository.ts @@ -1,10 +1,10 @@ import { readFileSync } from 'fs'; import { join } from 'path'; -import { ConfigService } from '../../config/env.config'; -import { Logger } from '../../config/logger.config'; -import { IInsert, Repository } from '../abstract/abstract.repository'; -import { ChatwootRaw, IChatwootModel } from '../models'; +import { ConfigService } from '../../../../config/env.config'; +import { Logger } from '../../../../config/logger.config'; +import { IInsert, Repository } from '../../../abstract/abstract.repository'; +import { ChatwootRaw, IChatwootModel } from '../../../models'; export class ChatwootRepository extends Repository { constructor(private readonly chatwootModel: IChatwootModel, private readonly configService: ConfigService) { diff --git a/src/whatsapp/routers/chatwoot.router.ts b/src/api/integrations/chatwoot/routes/chatwoot.router.ts similarity index 84% rename from src/whatsapp/routers/chatwoot.router.ts rename to src/api/integrations/chatwoot/routes/chatwoot.router.ts index c232e007..2df2f18f 100644 --- a/src/whatsapp/routers/chatwoot.router.ts +++ b/src/api/integrations/chatwoot/routes/chatwoot.router.ts @@ -1,12 +1,12 @@ import { RequestHandler, Router } from 'express'; -import { Logger } from '../../config/logger.config'; -import { chatwootSchema, instanceNameSchema } from '../../validate/validate.schema'; -import { RouterBroker } from '../abstract/abstract.router'; +import { Logger } from '../../../../config/logger.config'; +import { chatwootSchema, instanceNameSchema } from '../../../../validate/validate.schema'; +import { RouterBroker } from '../../../abstract/abstract.router'; +import { InstanceDto } from '../../../dto/instance.dto'; +import { HttpStatus } from '../../../routers/index.router'; +import { chatwootController } from '../../../server.module'; import { ChatwootDto } from '../dto/chatwoot.dto'; -import { InstanceDto } from '../dto/instance.dto'; -import { chatwootController } from '../whatsapp.module'; -import { HttpStatus } from './index.router'; const logger = new Logger('ChatwootRouter'); diff --git a/src/whatsapp/services/chatwoot.service.ts b/src/api/integrations/chatwoot/services/chatwoot.service.ts similarity index 99% rename from src/whatsapp/services/chatwoot.service.ts rename to src/api/integrations/chatwoot/services/chatwoot.service.ts index d2c1f139..35fbb7af 100644 --- a/src/whatsapp/services/chatwoot.service.ts +++ b/src/api/integrations/chatwoot/services/chatwoot.service.ts @@ -15,18 +15,18 @@ import Jimp from 'jimp'; import mimeTypes from 'mime-types'; import path from 'path'; -import { Chatwoot, ConfigService, HttpServer } from '../../config/env.config'; -import { Logger } from '../../config/logger.config'; -import { chatwootImport } from '../../utils/chatwoot-import-helper'; -import i18next from '../../utils/i18n'; -import { ICache } from '../abstract/abstract.cache'; +import { Chatwoot, ConfigService, HttpServer } from '../../../../config/env.config'; +import { Logger } from '../../../../config/logger.config'; +import i18next from '../../../../utils/i18n'; +import { ICache } from '../../../abstract/abstract.cache'; +import { InstanceDto } from '../../../dto/instance.dto'; +import { Options, Quoted, SendAudioDto, SendMediaDto, SendTextDto } from '../../../dto/sendMessage.dto'; +import { ChatwootRaw, ContactRaw, MessageRaw } from '../../../models'; +import { RepositoryBroker } from '../../../repository/repository.manager'; +import { WAMonitoringService } from '../../../services/monitor.service'; +import { Events } from '../../../types/wa.types'; import { ChatwootDto } from '../dto/chatwoot.dto'; -import { InstanceDto } from '../dto/instance.dto'; -import { Options, Quoted, SendAudioDto, SendMediaDto, SendTextDto } from '../dto/sendMessage.dto'; -import { ChatwootRaw, ContactRaw, MessageRaw } from '../models'; -import { RepositoryBroker } from '../repository/repository.manager'; -import { Events } from '../types/wa.types'; -import { WAMonitoringService } from './monitor.service'; +import { chatwootImport } from '../utils/chatwoot-import-helper'; export class ChatwootService { private readonly logger = new Logger(ChatwootService.name); diff --git a/src/utils/chatwoot-import-helper.ts b/src/api/integrations/chatwoot/utils/chatwoot-import-helper.ts similarity index 98% rename from src/utils/chatwoot-import-helper.ts rename to src/api/integrations/chatwoot/utils/chatwoot-import-helper.ts index 3283683f..dd0bb23a 100644 --- a/src/utils/chatwoot-import-helper.ts +++ b/src/api/integrations/chatwoot/utils/chatwoot-import-helper.ts @@ -1,12 +1,12 @@ import { inbox } from '@figuro/chatwoot-sdk'; import { proto } from '@whiskeysockets/baileys'; -import { Chatwoot, configService } from '../config/env.config'; -import { Logger } from '../config/logger.config'; +import { InstanceDto } from '../../../../api/dto/instance.dto'; +import { ChatwootRaw, ContactRaw, MessageRaw } from '../../../../api/models'; +import { Chatwoot, configService } from '../../../../config/env.config'; +import { Logger } from '../../../../config/logger.config'; import { postgresClient } from '../libs/postgres.client'; -import { InstanceDto } from '../whatsapp/dto/instance.dto'; -import { ChatwootRaw, ContactRaw, MessageRaw } from '../whatsapp/models'; -import { ChatwootService } from '../whatsapp/services/chatwoot.service'; +import { ChatwootService } from '../services/chatwoot.service'; type ChatwootUser = { user_type: string; diff --git a/src/api/integrations/chatwoot/validate/chatwoot.schema.ts b/src/api/integrations/chatwoot/validate/chatwoot.schema.ts new file mode 100644 index 00000000..d2784daf --- /dev/null +++ b/src/api/integrations/chatwoot/validate/chatwoot.schema.ts @@ -0,0 +1,42 @@ +import { JSONSchema7 } from 'json-schema'; +import { v4 } from 'uuid'; + +const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => { + const properties = {}; + propertyNames.forEach( + (property) => + (properties[property] = { + minLength: 1, + description: `The "${property}" cannot be empty`, + }), + ); + return { + if: { + propertyNames: { + enum: [...propertyNames], + }, + }, + then: { properties }, + }; +}; + +export const chatwootSchema: JSONSchema7 = { + $id: v4(), + type: 'object', + properties: { + enabled: { type: 'boolean', enum: [true, false] }, + account_id: { type: 'string' }, + token: { type: 'string' }, + url: { type: 'string' }, + sign_msg: { type: 'boolean', enum: [true, false] }, + sign_delimiter: { type: ['string', 'null'] }, + reopen_conversation: { type: 'boolean', enum: [true, false] }, + conversation_pending: { type: 'boolean', enum: [true, false] }, + auto_create: { type: 'boolean', enum: [true, false] }, + import_contacts: { type: 'boolean', enum: [true, false] }, + import_messages: { type: 'boolean', enum: [true, false] }, + days_limit_import_messages: { type: 'number' }, + }, + required: ['enabled', 'account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'], + ...isNotEmpty('account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'), +}; diff --git a/src/whatsapp/controllers/rabbitmq.controller.ts b/src/api/integrations/rabbitmq/controllers/rabbitmq.controller.ts similarity index 93% rename from src/whatsapp/controllers/rabbitmq.controller.ts rename to src/api/integrations/rabbitmq/controllers/rabbitmq.controller.ts index 527c5006..0b10e954 100644 --- a/src/whatsapp/controllers/rabbitmq.controller.ts +++ b/src/api/integrations/rabbitmq/controllers/rabbitmq.controller.ts @@ -1,5 +1,5 @@ -import { Logger } from '../../config/logger.config'; -import { InstanceDto } from '../dto/instance.dto'; +import { Logger } from '../../../../config/logger.config'; +import { InstanceDto } from '../../../dto/instance.dto'; import { RabbitmqDto } from '../dto/rabbitmq.dto'; import { RabbitmqService } from '../services/rabbitmq.service'; diff --git a/src/whatsapp/dto/rabbitmq.dto.ts b/src/api/integrations/rabbitmq/dto/rabbitmq.dto.ts similarity index 100% rename from src/whatsapp/dto/rabbitmq.dto.ts rename to src/api/integrations/rabbitmq/dto/rabbitmq.dto.ts diff --git a/src/libs/amqp.server.ts b/src/api/integrations/rabbitmq/libs/amqp.server.ts similarity index 94% rename from src/libs/amqp.server.ts rename to src/api/integrations/rabbitmq/libs/amqp.server.ts index fc95b33c..5628fac9 100644 --- a/src/libs/amqp.server.ts +++ b/src/api/integrations/rabbitmq/libs/amqp.server.ts @@ -1,7 +1,7 @@ import * as amqp from 'amqplib/callback_api'; -import { configService, Rabbitmq } from '../config/env.config'; -import { Logger } from '../config/logger.config'; +import { configService, Rabbitmq } from '../../../../config/env.config'; +import { Logger } from '../../../../config/logger.config'; const logger = new Logger('AMQP'); diff --git a/src/whatsapp/models/rabbitmq.model.ts b/src/api/integrations/rabbitmq/models/rabbitmq.model.ts similarity index 88% rename from src/whatsapp/models/rabbitmq.model.ts rename to src/api/integrations/rabbitmq/models/rabbitmq.model.ts index e89ee3b1..ba0ac1af 100644 --- a/src/whatsapp/models/rabbitmq.model.ts +++ b/src/api/integrations/rabbitmq/models/rabbitmq.model.ts @@ -1,6 +1,6 @@ import { Schema } from 'mongoose'; -import { dbserver } from '../../libs/db.connect'; +import { dbserver } from '../../../../libs/db.connect'; export class RabbitmqRaw { _id?: string; diff --git a/src/whatsapp/repository/rabbitmq.repository.ts b/src/api/integrations/rabbitmq/repository/rabbitmq.repository.ts similarity index 87% rename from src/whatsapp/repository/rabbitmq.repository.ts rename to src/api/integrations/rabbitmq/repository/rabbitmq.repository.ts index 3dfb5ec2..cb30c7c3 100644 --- a/src/whatsapp/repository/rabbitmq.repository.ts +++ b/src/api/integrations/rabbitmq/repository/rabbitmq.repository.ts @@ -1,10 +1,10 @@ import { readFileSync } from 'fs'; import { join } from 'path'; -import { ConfigService } from '../../config/env.config'; -import { Logger } from '../../config/logger.config'; -import { IInsert, Repository } from '../abstract/abstract.repository'; -import { IRabbitmqModel, RabbitmqRaw } from '../models'; +import { ConfigService } from '../../../../config/env.config'; +import { Logger } from '../../../../config/logger.config'; +import { IInsert, Repository } from '../../../abstract/abstract.repository'; +import { IRabbitmqModel, RabbitmqRaw } from '../../../models'; export class RabbitmqRepository extends Repository { constructor(private readonly rabbitmqModel: IRabbitmqModel, private readonly configService: ConfigService) { diff --git a/src/whatsapp/routers/rabbitmq.router.ts b/src/api/integrations/rabbitmq/routes/rabbitmq.router.ts similarity index 79% rename from src/whatsapp/routers/rabbitmq.router.ts rename to src/api/integrations/rabbitmq/routes/rabbitmq.router.ts index e3f65283..c7d567e1 100644 --- a/src/whatsapp/routers/rabbitmq.router.ts +++ b/src/api/integrations/rabbitmq/routes/rabbitmq.router.ts @@ -1,12 +1,12 @@ import { RequestHandler, Router } from 'express'; -import { Logger } from '../../config/logger.config'; -import { instanceNameSchema, rabbitmqSchema } from '../../validate/validate.schema'; -import { RouterBroker } from '../abstract/abstract.router'; -import { InstanceDto } from '../dto/instance.dto'; +import { Logger } from '../../../../config/logger.config'; +import { instanceNameSchema, rabbitmqSchema } from '../../../../validate/validate.schema'; +import { RouterBroker } from '../../../abstract/abstract.router'; +import { InstanceDto } from '../../../dto/instance.dto'; +import { HttpStatus } from '../../../routers/index.router'; +import { rabbitmqController } from '../../../server.module'; import { RabbitmqDto } from '../dto/rabbitmq.dto'; -import { rabbitmqController } from '../whatsapp.module'; -import { HttpStatus } from './index.router'; const logger = new Logger('RabbitmqRouter'); diff --git a/src/whatsapp/services/rabbitmq.service.ts b/src/api/integrations/rabbitmq/services/rabbitmq.service.ts similarity index 77% rename from src/whatsapp/services/rabbitmq.service.ts rename to src/api/integrations/rabbitmq/services/rabbitmq.service.ts index a377595b..efb822fd 100644 --- a/src/whatsapp/services/rabbitmq.service.ts +++ b/src/api/integrations/rabbitmq/services/rabbitmq.service.ts @@ -1,9 +1,9 @@ -import { Logger } from '../../config/logger.config'; -import { initQueues } from '../../libs/amqp.server'; -import { InstanceDto } from '../dto/instance.dto'; +import { Logger } from '../../../../config/logger.config'; +import { InstanceDto } from '../../../dto/instance.dto'; +import { RabbitmqRaw } from '../../../models'; +import { WAMonitoringService } from '../../../services/monitor.service'; import { RabbitmqDto } from '../dto/rabbitmq.dto'; -import { RabbitmqRaw } from '../models'; -import { WAMonitoringService } from './monitor.service'; +import { initQueues } from '../libs/amqp.server'; export class RabbitmqService { constructor(private readonly waMonitor: WAMonitoringService) {} diff --git a/src/api/integrations/rabbitmq/validate/rabbitmq.schema.ts b/src/api/integrations/rabbitmq/validate/rabbitmq.schema.ts new file mode 100644 index 00000000..7a786bb4 --- /dev/null +++ b/src/api/integrations/rabbitmq/validate/rabbitmq.schema.ts @@ -0,0 +1,66 @@ +import { JSONSchema7 } from 'json-schema'; +import { v4 } from 'uuid'; + +const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => { + const properties = {}; + propertyNames.forEach( + (property) => + (properties[property] = { + minLength: 1, + description: `The "${property}" cannot be empty`, + }), + ); + return { + if: { + propertyNames: { + enum: [...propertyNames], + }, + }, + then: { properties }, + }; +}; + +export const rabbitmqSchema: JSONSchema7 = { + $id: v4(), + type: 'object', + properties: { + enabled: { type: 'boolean', enum: [true, false] }, + events: { + type: 'array', + minItems: 0, + items: { + type: 'string', + enum: [ + 'APPLICATION_STARTUP', + 'QRCODE_UPDATED', + 'MESSAGES_SET', + 'MESSAGES_UPSERT', + 'MESSAGES_UPDATE', + 'MESSAGES_DELETE', + 'SEND_MESSAGE', + 'CONTACTS_SET', + 'CONTACTS_UPSERT', + 'CONTACTS_UPDATE', + 'PRESENCE_UPDATE', + 'CHATS_SET', + 'CHATS_UPSERT', + 'CHATS_UPDATE', + 'CHATS_DELETE', + 'GROUPS_UPSERT', + 'GROUP_UPDATE', + 'GROUP_PARTICIPANTS_UPDATE', + 'CONNECTION_UPDATE', + 'LABELS_EDIT', + 'LABELS_ASSOCIATION', + 'CALL', + 'NEW_JWT_TOKEN', + 'TYPEBOT_START', + 'TYPEBOT_CHANGE_STATUS', + 'CHAMA_AI_ACTION', + ], + }, + }, + }, + required: ['enabled'], + ...isNotEmpty('enabled'), +}; diff --git a/src/whatsapp/controllers/sqs.controller.ts b/src/api/integrations/sqs/controllers/sqs.controller.ts similarity index 92% rename from src/whatsapp/controllers/sqs.controller.ts rename to src/api/integrations/sqs/controllers/sqs.controller.ts index 8dfebc6c..d6dd346b 100644 --- a/src/whatsapp/controllers/sqs.controller.ts +++ b/src/api/integrations/sqs/controllers/sqs.controller.ts @@ -1,5 +1,5 @@ -import { Logger } from '../../config/logger.config'; -import { InstanceDto } from '../dto/instance.dto'; +import { Logger } from '../../../../config/logger.config'; +import { InstanceDto } from '../../../dto/instance.dto'; import { SqsDto } from '../dto/sqs.dto'; import { SqsService } from '../services/sqs.service'; diff --git a/src/whatsapp/dto/sqs.dto.ts b/src/api/integrations/sqs/dto/sqs.dto.ts similarity index 100% rename from src/whatsapp/dto/sqs.dto.ts rename to src/api/integrations/sqs/dto/sqs.dto.ts diff --git a/src/libs/sqs.server.ts b/src/api/integrations/sqs/libs/sqs.server.ts similarity index 94% rename from src/libs/sqs.server.ts rename to src/api/integrations/sqs/libs/sqs.server.ts index 04184542..e1c328cb 100644 --- a/src/libs/sqs.server.ts +++ b/src/api/integrations/sqs/libs/sqs.server.ts @@ -1,7 +1,7 @@ import { SQS } from 'aws-sdk'; -import { configService, Sqs } from '../config/env.config'; -import { Logger } from '../config/logger.config'; +import { configService, Sqs } from '../../../../config/env.config'; +import { Logger } from '../../../../config/logger.config'; const logger = new Logger('SQS'); diff --git a/src/whatsapp/models/sqs.model.ts b/src/api/integrations/sqs/models/sqs.model.ts similarity index 87% rename from src/whatsapp/models/sqs.model.ts rename to src/api/integrations/sqs/models/sqs.model.ts index 2d5f432f..c3ac4fb1 100644 --- a/src/whatsapp/models/sqs.model.ts +++ b/src/api/integrations/sqs/models/sqs.model.ts @@ -1,6 +1,6 @@ import { Schema } from 'mongoose'; -import { dbserver } from '../../libs/db.connect'; +import { dbserver } from '../../../../libs/db.connect'; export class SqsRaw { _id?: string; diff --git a/src/whatsapp/repository/sqs.repository.ts b/src/api/integrations/sqs/repository/sqs.repository.ts similarity index 87% rename from src/whatsapp/repository/sqs.repository.ts rename to src/api/integrations/sqs/repository/sqs.repository.ts index 50ea1cd3..7e149daa 100644 --- a/src/whatsapp/repository/sqs.repository.ts +++ b/src/api/integrations/sqs/repository/sqs.repository.ts @@ -1,10 +1,10 @@ import { readFileSync } from 'fs'; import { join } from 'path'; -import { ConfigService } from '../../config/env.config'; -import { Logger } from '../../config/logger.config'; -import { IInsert, Repository } from '../abstract/abstract.repository'; -import { ISqsModel, SqsRaw } from '../models'; +import { ConfigService } from '../../../../config/env.config'; +import { Logger } from '../../../../config/logger.config'; +import { IInsert, Repository } from '../../../abstract/abstract.repository'; +import { ISqsModel, SqsRaw } from '../../../models'; export class SqsRepository extends Repository { constructor(private readonly sqsModel: ISqsModel, private readonly configService: ConfigService) { diff --git a/src/whatsapp/routers/sqs.router.ts b/src/api/integrations/sqs/routes/sqs.router.ts similarity index 79% rename from src/whatsapp/routers/sqs.router.ts rename to src/api/integrations/sqs/routes/sqs.router.ts index e1bf8e93..8b03bb3a 100644 --- a/src/whatsapp/routers/sqs.router.ts +++ b/src/api/integrations/sqs/routes/sqs.router.ts @@ -1,12 +1,12 @@ import { RequestHandler, Router } from 'express'; -import { Logger } from '../../config/logger.config'; -import { instanceNameSchema, sqsSchema } from '../../validate/validate.schema'; -import { RouterBroker } from '../abstract/abstract.router'; -import { InstanceDto } from '../dto/instance.dto'; +import { Logger } from '../../../../config/logger.config'; +import { instanceNameSchema, sqsSchema } from '../../../../validate/validate.schema'; +import { RouterBroker } from '../../../abstract/abstract.router'; +import { InstanceDto } from '../../../dto/instance.dto'; +import { HttpStatus } from '../../../routers/index.router'; +import { sqsController } from '../../../server.module'; import { SqsDto } from '../dto/sqs.dto'; -import { sqsController } from '../whatsapp.module'; -import { HttpStatus } from './index.router'; const logger = new Logger('SqsRouter'); diff --git a/src/whatsapp/services/sqs.service.ts b/src/api/integrations/sqs/services/sqs.service.ts similarity index 76% rename from src/whatsapp/services/sqs.service.ts rename to src/api/integrations/sqs/services/sqs.service.ts index 236d4ceb..52780104 100644 --- a/src/whatsapp/services/sqs.service.ts +++ b/src/api/integrations/sqs/services/sqs.service.ts @@ -1,9 +1,9 @@ -import { Logger } from '../../config/logger.config'; -import { initQueues } from '../../libs/sqs.server'; -import { InstanceDto } from '../dto/instance.dto'; +import { Logger } from '../../../../config/logger.config'; +import { InstanceDto } from '../../../dto/instance.dto'; +import { SqsRaw } from '../../../models'; +import { WAMonitoringService } from '../../../services/monitor.service'; import { SqsDto } from '../dto/sqs.dto'; -import { SqsRaw } from '../models'; -import { WAMonitoringService } from './monitor.service'; +import { initQueues } from '../libs/sqs.server'; export class SqsService { constructor(private readonly waMonitor: WAMonitoringService) {} diff --git a/src/api/integrations/sqs/validate/sqs.schema.ts b/src/api/integrations/sqs/validate/sqs.schema.ts new file mode 100644 index 00000000..54379c29 --- /dev/null +++ b/src/api/integrations/sqs/validate/sqs.schema.ts @@ -0,0 +1,66 @@ +import { JSONSchema7 } from 'json-schema'; +import { v4 } from 'uuid'; + +const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => { + const properties = {}; + propertyNames.forEach( + (property) => + (properties[property] = { + minLength: 1, + description: `The "${property}" cannot be empty`, + }), + ); + return { + if: { + propertyNames: { + enum: [...propertyNames], + }, + }, + then: { properties }, + }; +}; + +export const sqsSchema: JSONSchema7 = { + $id: v4(), + type: 'object', + properties: { + enabled: { type: 'boolean', enum: [true, false] }, + events: { + type: 'array', + minItems: 0, + items: { + type: 'string', + enum: [ + 'APPLICATION_STARTUP', + 'QRCODE_UPDATED', + 'MESSAGES_SET', + 'MESSAGES_UPSERT', + 'MESSAGES_UPDATE', + 'MESSAGES_DELETE', + 'SEND_MESSAGE', + 'CONTACTS_SET', + 'CONTACTS_UPSERT', + 'CONTACTS_UPDATE', + 'PRESENCE_UPDATE', + 'CHATS_SET', + 'CHATS_UPSERT', + 'CHATS_UPDATE', + 'CHATS_DELETE', + 'GROUPS_UPSERT', + 'GROUP_UPDATE', + 'GROUP_PARTICIPANTS_UPDATE', + 'CONNECTION_UPDATE', + 'LABELS_EDIT', + 'LABELS_ASSOCIATION', + 'CALL', + 'NEW_JWT_TOKEN', + 'TYPEBOT_START', + 'TYPEBOT_CHANGE_STATUS', + 'CHAMA_AI_ACTION', + ], + }, + }, + }, + required: ['enabled'], + ...isNotEmpty('enabled'), +}; diff --git a/src/whatsapp/controllers/typebot.controller.ts b/src/api/integrations/typebot/controllers/typebot.controller.ts similarity index 92% rename from src/whatsapp/controllers/typebot.controller.ts rename to src/api/integrations/typebot/controllers/typebot.controller.ts index 53dc967f..bb52a370 100644 --- a/src/whatsapp/controllers/typebot.controller.ts +++ b/src/api/integrations/typebot/controllers/typebot.controller.ts @@ -1,5 +1,5 @@ -import { Logger } from '../../config/logger.config'; -import { InstanceDto } from '../dto/instance.dto'; +import { Logger } from '../../../../config/logger.config'; +import { InstanceDto } from '../../../dto/instance.dto'; import { TypebotDto } from '../dto/typebot.dto'; import { TypebotService } from '../services/typebot.service'; diff --git a/src/whatsapp/dto/typebot.dto.ts b/src/api/integrations/typebot/dto/typebot.dto.ts similarity index 100% rename from src/whatsapp/dto/typebot.dto.ts rename to src/api/integrations/typebot/dto/typebot.dto.ts diff --git a/src/whatsapp/models/typebot.model.ts b/src/api/integrations/typebot/models/typebot.model.ts similarity index 96% rename from src/whatsapp/models/typebot.model.ts rename to src/api/integrations/typebot/models/typebot.model.ts index c8ae7105..9060b6e0 100644 --- a/src/whatsapp/models/typebot.model.ts +++ b/src/api/integrations/typebot/models/typebot.model.ts @@ -1,6 +1,6 @@ import { Schema } from 'mongoose'; -import { dbserver } from '../../libs/db.connect'; +import { dbserver } from '../../../../libs/db.connect'; class Session { remoteJid?: string; diff --git a/src/whatsapp/repository/typebot.repository.ts b/src/api/integrations/typebot/repository/typebot.repository.ts similarity index 88% rename from src/whatsapp/repository/typebot.repository.ts rename to src/api/integrations/typebot/repository/typebot.repository.ts index 8653e9c9..45453c63 100644 --- a/src/whatsapp/repository/typebot.repository.ts +++ b/src/api/integrations/typebot/repository/typebot.repository.ts @@ -1,10 +1,10 @@ import { readFileSync } from 'fs'; import { join } from 'path'; -import { ConfigService } from '../../config/env.config'; -import { Logger } from '../../config/logger.config'; -import { IInsert, Repository } from '../abstract/abstract.repository'; -import { ITypebotModel, TypebotRaw } from '../models'; +import { ConfigService } from '../../../../config/env.config'; +import { Logger } from '../../../../config/logger.config'; +import { IInsert, Repository } from '../../../abstract/abstract.repository'; +import { ITypebotModel, TypebotRaw } from '../../../models'; export class TypebotRepository extends Repository { constructor(private readonly typebotModel: ITypebotModel, private readonly configService: ConfigService) { diff --git a/src/whatsapp/routers/typebot.router.ts b/src/api/integrations/typebot/routes/typebot.router.ts similarity index 88% rename from src/whatsapp/routers/typebot.router.ts rename to src/api/integrations/typebot/routes/typebot.router.ts index 0f785de3..b9694c54 100644 --- a/src/whatsapp/routers/typebot.router.ts +++ b/src/api/integrations/typebot/routes/typebot.router.ts @@ -1,17 +1,17 @@ import { RequestHandler, Router } from 'express'; -import { Logger } from '../../config/logger.config'; +import { Logger } from '../../../../config/logger.config'; import { instanceNameSchema, typebotSchema, typebotStartSchema, typebotStatusSchema, -} from '../../validate/validate.schema'; -import { RouterBroker } from '../abstract/abstract.router'; -import { InstanceDto } from '../dto/instance.dto'; +} from '../../../../validate/validate.schema'; +import { RouterBroker } from '../../../abstract/abstract.router'; +import { InstanceDto } from '../../../dto/instance.dto'; +import { HttpStatus } from '../../../routers/index.router'; +import { typebotController } from '../../../server.module'; import { TypebotDto } from '../dto/typebot.dto'; -import { typebotController } from '../whatsapp.module'; -import { HttpStatus } from './index.router'; const logger = new Logger('TypebotRouter'); diff --git a/src/whatsapp/services/typebot.service.ts b/src/api/integrations/typebot/services/typebot.service.ts similarity index 98% rename from src/whatsapp/services/typebot.service.ts rename to src/api/integrations/typebot/services/typebot.service.ts index 8c267759..6c322552 100644 --- a/src/whatsapp/services/typebot.service.ts +++ b/src/api/integrations/typebot/services/typebot.service.ts @@ -1,13 +1,13 @@ import axios from 'axios'; import EventEmitter2 from 'eventemitter2'; -import { ConfigService, Typebot } from '../../config/env.config'; -import { Logger } from '../../config/logger.config'; -import { InstanceDto } from '../dto/instance.dto'; +import { ConfigService, Typebot } from '../../../../config/env.config'; +import { Logger } from '../../../../config/logger.config'; +import { InstanceDto } from '../../../dto/instance.dto'; +import { MessageRaw } from '../../../models'; +import { WAMonitoringService } from '../../../services/monitor.service'; +import { Events } from '../../../types/wa.types'; import { Session, TypebotDto } from '../dto/typebot.dto'; -import { MessageRaw } from '../models'; -import { Events } from '../types/wa.types'; -import { WAMonitoringService } from './monitor.service'; export class TypebotService { constructor( diff --git a/src/api/integrations/typebot/validate/typebot.schema.ts b/src/api/integrations/typebot/validate/typebot.schema.ts new file mode 100644 index 00000000..fde9d973 --- /dev/null +++ b/src/api/integrations/typebot/validate/typebot.schema.ts @@ -0,0 +1,60 @@ +import { JSONSchema7 } from 'json-schema'; +import { v4 } from 'uuid'; + +const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => { + const properties = {}; + propertyNames.forEach( + (property) => + (properties[property] = { + minLength: 1, + description: `The "${property}" cannot be empty`, + }), + ); + return { + if: { + propertyNames: { + enum: [...propertyNames], + }, + }, + then: { properties }, + }; +}; + +export const typebotSchema: JSONSchema7 = { + $id: v4(), + type: 'object', + properties: { + enabled: { type: 'boolean', enum: [true, false] }, + url: { type: 'string' }, + typebot: { type: 'string' }, + expire: { type: 'integer' }, + delay_message: { type: 'integer' }, + unknown_message: { type: 'string' }, + listening_from_me: { type: 'boolean', enum: [true, false] }, + }, + required: ['enabled', 'url', 'typebot', 'expire', 'delay_message', 'unknown_message', 'listening_from_me'], + ...isNotEmpty('enabled', 'url', 'typebot', 'expire', 'delay_message', 'unknown_message', 'listening_from_me'), +}; + +export const typebotStatusSchema: JSONSchema7 = { + $id: v4(), + type: 'object', + properties: { + remoteJid: { type: 'string' }, + status: { type: 'string', enum: ['opened', 'closed', 'paused'] }, + }, + required: ['remoteJid', 'status'], + ...isNotEmpty('remoteJid', 'status'), +}; + +export const typebotStartSchema: JSONSchema7 = { + $id: v4(), + type: 'object', + properties: { + remoteJid: { type: 'string' }, + url: { type: 'string' }, + typebot: { type: 'string' }, + }, + required: ['remoteJid', 'url', 'typebot'], + ...isNotEmpty('remoteJid', 'url', 'typebot'), +}; diff --git a/src/whatsapp/controllers/websocket.controller.ts b/src/api/integrations/websocket/controllers/websocket.controller.ts similarity index 93% rename from src/whatsapp/controllers/websocket.controller.ts rename to src/api/integrations/websocket/controllers/websocket.controller.ts index 15abde70..2d207b74 100644 --- a/src/whatsapp/controllers/websocket.controller.ts +++ b/src/api/integrations/websocket/controllers/websocket.controller.ts @@ -1,5 +1,5 @@ -import { Logger } from '../../config/logger.config'; -import { InstanceDto } from '../dto/instance.dto'; +import { Logger } from '../../../../config/logger.config'; +import { InstanceDto } from '../../../dto/instance.dto'; import { WebsocketDto } from '../dto/websocket.dto'; import { WebsocketService } from '../services/websocket.service'; diff --git a/src/whatsapp/dto/websocket.dto.ts b/src/api/integrations/websocket/dto/websocket.dto.ts similarity index 100% rename from src/whatsapp/dto/websocket.dto.ts rename to src/api/integrations/websocket/dto/websocket.dto.ts diff --git a/src/libs/socket.server.ts b/src/api/integrations/websocket/libs/socket.server.ts similarity index 86% rename from src/libs/socket.server.ts rename to src/api/integrations/websocket/libs/socket.server.ts index ecf01ab1..81f97847 100644 --- a/src/libs/socket.server.ts +++ b/src/api/integrations/websocket/libs/socket.server.ts @@ -1,8 +1,8 @@ import { Server } from 'http'; import { Server as SocketIO } from 'socket.io'; -import { configService, Cors, Websocket } from '../config/env.config'; -import { Logger } from '../config/logger.config'; +import { configService, Cors, Websocket } from '../../../../config/env.config'; +import { Logger } from '../../../../config/logger.config'; const logger = new Logger('Socket'); diff --git a/src/whatsapp/models/websocket.model.ts b/src/api/integrations/websocket/models/websocket.model.ts similarity index 89% rename from src/whatsapp/models/websocket.model.ts rename to src/api/integrations/websocket/models/websocket.model.ts index e96332b1..9e824597 100644 --- a/src/whatsapp/models/websocket.model.ts +++ b/src/api/integrations/websocket/models/websocket.model.ts @@ -1,6 +1,6 @@ import { Schema } from 'mongoose'; -import { dbserver } from '../../libs/db.connect'; +import { dbserver } from '../../../../libs/db.connect'; export class WebsocketRaw { _id?: string; diff --git a/src/whatsapp/repository/websocket.repository.ts b/src/api/integrations/websocket/repository/websocket.repository.ts similarity index 87% rename from src/whatsapp/repository/websocket.repository.ts rename to src/api/integrations/websocket/repository/websocket.repository.ts index 19823194..48d5b7d3 100644 --- a/src/whatsapp/repository/websocket.repository.ts +++ b/src/api/integrations/websocket/repository/websocket.repository.ts @@ -1,10 +1,10 @@ import { readFileSync } from 'fs'; import { join } from 'path'; -import { ConfigService } from '../../config/env.config'; -import { Logger } from '../../config/logger.config'; -import { IInsert, Repository } from '../abstract/abstract.repository'; -import { IWebsocketModel, WebsocketRaw } from '../models'; +import { ConfigService } from '../../../../config/env.config'; +import { Logger } from '../../../../config/logger.config'; +import { IInsert, Repository } from '../../../abstract/abstract.repository'; +import { IWebsocketModel, WebsocketRaw } from '../../../models'; export class WebsocketRepository extends Repository { constructor(private readonly websocketModel: IWebsocketModel, private readonly configService: ConfigService) { diff --git a/src/whatsapp/routers/websocket.router.ts b/src/api/integrations/websocket/routes/websocket.router.ts similarity index 79% rename from src/whatsapp/routers/websocket.router.ts rename to src/api/integrations/websocket/routes/websocket.router.ts index f04cad0d..271c1ce2 100644 --- a/src/whatsapp/routers/websocket.router.ts +++ b/src/api/integrations/websocket/routes/websocket.router.ts @@ -1,12 +1,12 @@ import { RequestHandler, Router } from 'express'; -import { Logger } from '../../config/logger.config'; -import { instanceNameSchema, websocketSchema } from '../../validate/validate.schema'; -import { RouterBroker } from '../abstract/abstract.router'; -import { InstanceDto } from '../dto/instance.dto'; +import { Logger } from '../../../../config/logger.config'; +import { instanceNameSchema, websocketSchema } from '../../../../validate/validate.schema'; +import { RouterBroker } from '../../../abstract/abstract.router'; +import { InstanceDto } from '../../../dto/instance.dto'; +import { HttpStatus } from '../../../routers/index.router'; +import { websocketController } from '../../../server.module'; import { WebsocketDto } from '../dto/websocket.dto'; -import { websocketController } from '../whatsapp.module'; -import { HttpStatus } from './index.router'; const logger = new Logger('WebsocketRouter'); diff --git a/src/whatsapp/services/websocket.service.ts b/src/api/integrations/websocket/services/websocket.service.ts similarity index 79% rename from src/whatsapp/services/websocket.service.ts rename to src/api/integrations/websocket/services/websocket.service.ts index 20663bbf..fcbb4353 100644 --- a/src/whatsapp/services/websocket.service.ts +++ b/src/api/integrations/websocket/services/websocket.service.ts @@ -1,8 +1,8 @@ -import { Logger } from '../../config/logger.config'; -import { InstanceDto } from '../dto/instance.dto'; +import { Logger } from '../../../../config/logger.config'; +import { InstanceDto } from '../../../dto/instance.dto'; +import { WebsocketRaw } from '../../../models'; +import { WAMonitoringService } from '../../../services/monitor.service'; import { WebsocketDto } from '../dto/websocket.dto'; -import { WebsocketRaw } from '../models'; -import { WAMonitoringService } from './monitor.service'; export class WebsocketService { constructor(private readonly waMonitor: WAMonitoringService) {} diff --git a/src/api/integrations/websocket/validate/websocket.schema.ts b/src/api/integrations/websocket/validate/websocket.schema.ts new file mode 100644 index 00000000..ddddeee2 --- /dev/null +++ b/src/api/integrations/websocket/validate/websocket.schema.ts @@ -0,0 +1,66 @@ +import { JSONSchema7 } from 'json-schema'; +import { v4 } from 'uuid'; + +const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => { + const properties = {}; + propertyNames.forEach( + (property) => + (properties[property] = { + minLength: 1, + description: `The "${property}" cannot be empty`, + }), + ); + return { + if: { + propertyNames: { + enum: [...propertyNames], + }, + }, + then: { properties }, + }; +}; + +export const websocketSchema: JSONSchema7 = { + $id: v4(), + type: 'object', + properties: { + enabled: { type: 'boolean', enum: [true, false] }, + events: { + type: 'array', + minItems: 0, + items: { + type: 'string', + enum: [ + 'APPLICATION_STARTUP', + 'QRCODE_UPDATED', + 'MESSAGES_SET', + 'MESSAGES_UPSERT', + 'MESSAGES_UPDATE', + 'MESSAGES_DELETE', + 'SEND_MESSAGE', + 'CONTACTS_SET', + 'CONTACTS_UPSERT', + 'CONTACTS_UPDATE', + 'PRESENCE_UPDATE', + 'CHATS_SET', + 'CHATS_UPSERT', + 'CHATS_UPDATE', + 'CHATS_DELETE', + 'GROUPS_UPSERT', + 'GROUP_UPDATE', + 'GROUP_PARTICIPANTS_UPDATE', + 'CONNECTION_UPDATE', + 'LABELS_EDIT', + 'LABELS_ASSOCIATION', + 'CALL', + 'NEW_JWT_TOKEN', + 'TYPEBOT_START', + 'TYPEBOT_CHANGE_STATUS', + 'CHAMA_AI_ACTION', + ], + }, + }, + }, + required: ['enabled'], + ...isNotEmpty('enabled'), +}; diff --git a/src/whatsapp/models/auth.model.ts b/src/api/models/auth.model.ts similarity index 100% rename from src/whatsapp/models/auth.model.ts rename to src/api/models/auth.model.ts diff --git a/src/whatsapp/models/chamaai.model.ts b/src/api/models/chamaai.model.ts similarity index 100% rename from src/whatsapp/models/chamaai.model.ts rename to src/api/models/chamaai.model.ts diff --git a/src/whatsapp/models/chat.model.ts b/src/api/models/chat.model.ts similarity index 100% rename from src/whatsapp/models/chat.model.ts rename to src/api/models/chat.model.ts diff --git a/src/whatsapp/models/contact.model.ts b/src/api/models/contact.model.ts similarity index 100% rename from src/whatsapp/models/contact.model.ts rename to src/api/models/contact.model.ts diff --git a/src/whatsapp/models/index.ts b/src/api/models/index.ts similarity index 51% rename from src/whatsapp/models/index.ts rename to src/api/models/index.ts index 743b9760..6cec09a9 100644 --- a/src/whatsapp/models/index.ts +++ b/src/api/models/index.ts @@ -1,15 +1,15 @@ +export * from '../integrations/chatwoot/models/chatwoot.model'; +export * from '../integrations/rabbitmq/models/rabbitmq.model'; +export * from '../integrations/sqs/models/sqs.model'; +export * from '../integrations/typebot/models/typebot.model'; +export * from '../integrations/websocket/models/websocket.model'; export * from './auth.model'; export * from './chamaai.model'; export * from './chat.model'; -export * from './chatwoot.model'; export * from './contact.model'; export * from './integration.model'; export * from './label.model'; export * from './message.model'; export * from './proxy.model'; -export * from './rabbitmq.model'; export * from './settings.model'; -export * from './sqs.model'; -export * from './typebot.model'; export * from './webhook.model'; -export * from './websocket.model'; diff --git a/src/whatsapp/models/integration.model.ts b/src/api/models/integration.model.ts similarity index 100% rename from src/whatsapp/models/integration.model.ts rename to src/api/models/integration.model.ts diff --git a/src/whatsapp/models/label.model.ts b/src/api/models/label.model.ts similarity index 100% rename from src/whatsapp/models/label.model.ts rename to src/api/models/label.model.ts diff --git a/src/whatsapp/models/message.model.ts b/src/api/models/message.model.ts similarity index 100% rename from src/whatsapp/models/message.model.ts rename to src/api/models/message.model.ts diff --git a/src/whatsapp/models/proxy.model.ts b/src/api/models/proxy.model.ts similarity index 100% rename from src/whatsapp/models/proxy.model.ts rename to src/api/models/proxy.model.ts diff --git a/src/whatsapp/models/settings.model.ts b/src/api/models/settings.model.ts similarity index 100% rename from src/whatsapp/models/settings.model.ts rename to src/api/models/settings.model.ts diff --git a/src/whatsapp/models/webhook.model.ts b/src/api/models/webhook.model.ts similarity index 100% rename from src/whatsapp/models/webhook.model.ts rename to src/api/models/webhook.model.ts diff --git a/src/whatsapp/repository/auth.repository.ts b/src/api/repository/auth.repository.ts similarity index 100% rename from src/whatsapp/repository/auth.repository.ts rename to src/api/repository/auth.repository.ts diff --git a/src/whatsapp/repository/chamaai.repository.ts b/src/api/repository/chamaai.repository.ts similarity index 100% rename from src/whatsapp/repository/chamaai.repository.ts rename to src/api/repository/chamaai.repository.ts diff --git a/src/whatsapp/repository/chat.repository.ts b/src/api/repository/chat.repository.ts similarity index 100% rename from src/whatsapp/repository/chat.repository.ts rename to src/api/repository/chat.repository.ts diff --git a/src/whatsapp/repository/contact.repository.ts b/src/api/repository/contact.repository.ts similarity index 100% rename from src/whatsapp/repository/contact.repository.ts rename to src/api/repository/contact.repository.ts diff --git a/src/whatsapp/repository/integration.repository.ts b/src/api/repository/integration.repository.ts similarity index 100% rename from src/whatsapp/repository/integration.repository.ts rename to src/api/repository/integration.repository.ts diff --git a/src/whatsapp/repository/label.repository.ts b/src/api/repository/label.repository.ts similarity index 100% rename from src/whatsapp/repository/label.repository.ts rename to src/api/repository/label.repository.ts diff --git a/src/whatsapp/repository/message.repository.ts b/src/api/repository/message.repository.ts similarity index 100% rename from src/whatsapp/repository/message.repository.ts rename to src/api/repository/message.repository.ts diff --git a/src/whatsapp/repository/messageUp.repository.ts b/src/api/repository/messageUp.repository.ts similarity index 100% rename from src/whatsapp/repository/messageUp.repository.ts rename to src/api/repository/messageUp.repository.ts diff --git a/src/whatsapp/repository/proxy.repository.ts b/src/api/repository/proxy.repository.ts similarity index 100% rename from src/whatsapp/repository/proxy.repository.ts rename to src/api/repository/proxy.repository.ts diff --git a/src/whatsapp/repository/repository.manager.ts b/src/api/repository/repository.manager.ts similarity index 93% rename from src/whatsapp/repository/repository.manager.ts rename to src/api/repository/repository.manager.ts index 10207eb3..2ea54aa1 100644 --- a/src/whatsapp/repository/repository.manager.ts +++ b/src/api/repository/repository.manager.ts @@ -4,22 +4,22 @@ import { join } from 'path'; import { Auth, ConfigService, Database } from '../../config/env.config'; import { Logger } from '../../config/logger.config'; +import { ChatwootRepository } from '../integrations/chatwoot/repository/chatwoot.repository'; +import { RabbitmqRepository } from '../integrations/rabbitmq/repository/rabbitmq.repository'; +import { SqsRepository } from '../integrations/sqs/repository/sqs.repository'; +import { TypebotRepository } from '../integrations/typebot/repository/typebot.repository'; +import { WebsocketRepository } from '../integrations/websocket/repository/websocket.repository'; import { AuthRepository } from './auth.repository'; import { ChamaaiRepository } from './chamaai.repository'; import { ChatRepository } from './chat.repository'; -import { ChatwootRepository } from './chatwoot.repository'; import { ContactRepository } from './contact.repository'; import { IntegrationRepository } from './integration.repository'; import { LabelRepository } from './label.repository'; import { MessageRepository } from './message.repository'; import { MessageUpRepository } from './messageUp.repository'; import { ProxyRepository } from './proxy.repository'; -import { RabbitmqRepository } from './rabbitmq.repository'; import { SettingsRepository } from './settings.repository'; -import { SqsRepository } from './sqs.repository'; -import { TypebotRepository } from './typebot.repository'; import { WebhookRepository } from './webhook.repository'; -import { WebsocketRepository } from './websocket.repository'; export class RepositoryBroker { constructor( public readonly message: MessageRepository, diff --git a/src/whatsapp/repository/settings.repository.ts b/src/api/repository/settings.repository.ts similarity index 100% rename from src/whatsapp/repository/settings.repository.ts rename to src/api/repository/settings.repository.ts diff --git a/src/whatsapp/repository/webhook.repository.ts b/src/api/repository/webhook.repository.ts similarity index 100% rename from src/whatsapp/repository/webhook.repository.ts rename to src/api/repository/webhook.repository.ts diff --git a/src/whatsapp/routers/chamaai.router.ts b/src/api/routers/chamaai.router.ts similarity index 96% rename from src/whatsapp/routers/chamaai.router.ts rename to src/api/routers/chamaai.router.ts index e8021306..93644af3 100644 --- a/src/whatsapp/routers/chamaai.router.ts +++ b/src/api/routers/chamaai.router.ts @@ -5,7 +5,7 @@ import { chamaaiSchema, instanceNameSchema } from '../../validate/validate.schem import { RouterBroker } from '../abstract/abstract.router'; import { ChamaaiDto } from '../dto/chamaai.dto'; import { InstanceDto } from '../dto/instance.dto'; -import { chamaaiController } from '../whatsapp.module'; +import { chamaaiController } from '../server.module'; import { HttpStatus } from './index.router'; const logger = new Logger('ChamaaiRouter'); diff --git a/src/whatsapp/routers/chat.router.ts b/src/api/routers/chat.router.ts similarity index 99% rename from src/whatsapp/routers/chat.router.ts rename to src/api/routers/chat.router.ts index a0ce3216..e8c82a16 100644 --- a/src/whatsapp/routers/chat.router.ts +++ b/src/api/routers/chat.router.ts @@ -38,7 +38,7 @@ import { InstanceDto } from '../dto/instance.dto'; import { ContactQuery } from '../repository/contact.repository'; import { MessageQuery } from '../repository/message.repository'; import { MessageUpQuery } from '../repository/messageUp.repository'; -import { chatController } from '../whatsapp.module'; +import { chatController } from '../server.module'; import { HttpStatus } from './index.router'; const logger = new Logger('ChatRouter'); diff --git a/src/whatsapp/routers/group.router.ts b/src/api/routers/group.router.ts similarity index 99% rename from src/whatsapp/routers/group.router.ts rename to src/api/routers/group.router.ts index bf088129..244dfee2 100644 --- a/src/whatsapp/routers/group.router.ts +++ b/src/api/routers/group.router.ts @@ -30,7 +30,7 @@ import { GroupUpdateParticipantDto, GroupUpdateSettingDto, } from '../dto/group.dto'; -import { groupController } from '../whatsapp.module'; +import { groupController } from '../server.module'; import { HttpStatus } from './index.router'; const logger = new Logger('GroupRouter'); diff --git a/src/whatsapp/routers/index.router.ts b/src/api/routers/index.router.ts similarity index 86% rename from src/whatsapp/routers/index.router.ts rename to src/api/routers/index.router.ts index 51460339..8d17ab6f 100644 --- a/src/whatsapp/routers/index.router.ts +++ b/src/api/routers/index.router.ts @@ -4,21 +4,21 @@ import fs from 'fs'; import { Auth, configService } from '../../config/env.config'; import { authGuard } from '../guards/auth.guard'; import { instanceExistsGuard, instanceLoggedGuard } from '../guards/instance.guard'; +import { ChatwootRouter } from '../integrations/chatwoot/routes/chatwoot.router'; +import { RabbitmqRouter } from '../integrations/rabbitmq/routes/rabbitmq.router'; +import { SqsRouter } from '../integrations/sqs/routes/sqs.router'; +import { TypebotRouter } from '../integrations/typebot/routes/typebot.router'; +import { WebsocketRouter } from '../integrations/websocket/routes/websocket.router'; import { ChamaaiRouter } from './chamaai.router'; import { ChatRouter } from './chat.router'; -import { ChatwootRouter } from './chatwoot.router'; import { GroupRouter } from './group.router'; import { InstanceRouter } from './instance.router'; import { LabelRouter } from './label.router'; import { ProxyRouter } from './proxy.router'; -import { RabbitmqRouter } from './rabbitmq.router'; import { MessageRouter } from './sendMessage.router'; import { SettingsRouter } from './settings.router'; -import { SqsRouter } from './sqs.router'; -import { TypebotRouter } from './typebot.router'; import { ViewsRouter } from './view.router'; import { WebhookRouter } from './webhook.router'; -import { WebsocketRouter } from './websocket.router'; enum HttpStatus { OK = 200, diff --git a/src/whatsapp/routers/instance.router.ts b/src/api/routers/instance.router.ts similarity index 99% rename from src/whatsapp/routers/instance.router.ts rename to src/api/routers/instance.router.ts index fa78c197..a56271a4 100644 --- a/src/whatsapp/routers/instance.router.ts +++ b/src/api/routers/instance.router.ts @@ -6,8 +6,8 @@ import { dbserver } from '../../libs/db.connect'; import { instanceNameSchema, oldTokenSchema, presenceOnlySchema } from '../../validate/validate.schema'; import { RouterBroker } from '../abstract/abstract.router'; import { InstanceDto, SetPresenceDto } from '../dto/instance.dto'; +import { instanceController } from '../server.module'; import { OldToken } from '../services/auth.service'; -import { instanceController } from '../whatsapp.module'; import { HttpStatus } from './index.router'; const logger = new Logger('InstanceRouter'); diff --git a/src/whatsapp/routers/label.router.ts b/src/api/routers/label.router.ts similarity index 97% rename from src/whatsapp/routers/label.router.ts rename to src/api/routers/label.router.ts index a856ff6d..a6002bb9 100644 --- a/src/whatsapp/routers/label.router.ts +++ b/src/api/routers/label.router.ts @@ -4,7 +4,7 @@ import { Logger } from '../../config/logger.config'; import { handleLabelSchema } from '../../validate/validate.schema'; import { RouterBroker } from '../abstract/abstract.router'; import { HandleLabelDto, LabelDto } from '../dto/label.dto'; -import { labelController } from '../whatsapp.module'; +import { labelController } from '../server.module'; import { HttpStatus } from './index.router'; const logger = new Logger('LabelRouter'); diff --git a/src/whatsapp/routers/proxy.router.ts b/src/api/routers/proxy.router.ts similarity index 97% rename from src/whatsapp/routers/proxy.router.ts rename to src/api/routers/proxy.router.ts index 2ae0141b..284fe368 100644 --- a/src/whatsapp/routers/proxy.router.ts +++ b/src/api/routers/proxy.router.ts @@ -5,7 +5,7 @@ import { instanceNameSchema, proxySchema } from '../../validate/validate.schema' import { RouterBroker } from '../abstract/abstract.router'; import { InstanceDto } from '../dto/instance.dto'; import { ProxyDto } from '../dto/proxy.dto'; -import { proxyController } from '../whatsapp.module'; +import { proxyController } from '../server.module'; import { HttpStatus } from './index.router'; const logger = new Logger('ProxyRouter'); diff --git a/src/whatsapp/routers/sendMessage.router.ts b/src/api/routers/sendMessage.router.ts similarity index 99% rename from src/whatsapp/routers/sendMessage.router.ts rename to src/api/routers/sendMessage.router.ts index 51b60593..908a1a58 100644 --- a/src/whatsapp/routers/sendMessage.router.ts +++ b/src/api/routers/sendMessage.router.ts @@ -30,7 +30,7 @@ import { SendTemplateDto, SendTextDto, } from '../dto/sendMessage.dto'; -import { sendMessageController } from '../whatsapp.module'; +import { sendMessageController } from '../server.module'; import { HttpStatus } from './index.router'; const logger = new Logger('MessageRouter'); diff --git a/src/whatsapp/routers/settings.router.ts b/src/api/routers/settings.router.ts similarity index 96% rename from src/whatsapp/routers/settings.router.ts rename to src/api/routers/settings.router.ts index 57e56b0d..c2d3bad9 100644 --- a/src/whatsapp/routers/settings.router.ts +++ b/src/api/routers/settings.router.ts @@ -5,7 +5,7 @@ import { instanceNameSchema, settingsSchema } from '../../validate/validate.sche import { RouterBroker } from '../abstract/abstract.router'; import { InstanceDto } from '../dto/instance.dto'; import { SettingsDto } from '../dto/settings.dto'; -import { settingsController } from '../whatsapp.module'; +import { settingsController } from '../server.module'; import { HttpStatus } from './index.router'; const logger = new Logger('SettingsRouter'); diff --git a/src/whatsapp/routers/view.router.ts b/src/api/routers/view.router.ts similarity index 100% rename from src/whatsapp/routers/view.router.ts rename to src/api/routers/view.router.ts diff --git a/src/whatsapp/routers/webhook.router.ts b/src/api/routers/webhook.router.ts similarity index 98% rename from src/whatsapp/routers/webhook.router.ts rename to src/api/routers/webhook.router.ts index 255b6ac5..1e4ddcac 100644 --- a/src/whatsapp/routers/webhook.router.ts +++ b/src/api/routers/webhook.router.ts @@ -6,7 +6,7 @@ import { instanceNameSchema, webhookSchema } from '../../validate/validate.schem import { RouterBroker } from '../abstract/abstract.router'; import { InstanceDto } from '../dto/instance.dto'; import { WebhookDto } from '../dto/webhook.dto'; -import { webhookController } from '../whatsapp.module'; +import { webhookController } from '../server.module'; import { HttpStatus } from './index.router'; const logger = new Logger('WebhookRouter'); diff --git a/src/whatsapp/whatsapp.module.ts b/src/api/server.module.ts similarity index 82% rename from src/whatsapp/whatsapp.module.ts rename to src/api/server.module.ts index 366988e2..67512cac 100644 --- a/src/whatsapp/whatsapp.module.ts +++ b/src/api/server.module.ts @@ -1,23 +1,33 @@ import { configService } from '../config/env.config'; import { eventEmitter } from '../config/event.config'; import { Logger } from '../config/logger.config'; -import { CacheEngine } from '../libs/cacheengine'; import { dbserver } from '../libs/db.connect'; import { RedisCache } from '../libs/redis.client'; import { ChamaaiController } from './controllers/chamaai.controller'; import { ChatController } from './controllers/chat.controller'; -import { ChatwootController } from './controllers/chatwoot.controller'; import { GroupController } from './controllers/group.controller'; import { InstanceController } from './controllers/instance.controller'; import { LabelController } from './controllers/label.controller'; import { ProxyController } from './controllers/proxy.controller'; -import { RabbitmqController } from './controllers/rabbitmq.controller'; import { SendMessageController } from './controllers/sendMessage.controller'; import { SettingsController } from './controllers/settings.controller'; -import { SqsController } from './controllers/sqs.controller'; -import { TypebotController } from './controllers/typebot.controller'; import { WebhookController } from './controllers/webhook.controller'; -import { WebsocketController } from './controllers/websocket.controller'; +import { CacheEngine } from './integrations/chatwoot/cache/cacheengine'; +import { ChatwootController } from './integrations/chatwoot/controllers/chatwoot.controller'; +import { ChatwootRepository } from './integrations/chatwoot/repository/chatwoot.repository'; +import { ChatwootService } from './integrations/chatwoot/services/chatwoot.service'; +import { RabbitmqController } from './integrations/rabbitmq/controllers/rabbitmq.controller'; +import { RabbitmqRepository } from './integrations/rabbitmq/repository/rabbitmq.repository'; +import { RabbitmqService } from './integrations/rabbitmq/services/rabbitmq.service'; +import { SqsController } from './integrations/sqs/controllers/sqs.controller'; +import { SqsRepository } from './integrations/sqs/repository/sqs.repository'; +import { SqsService } from './integrations/sqs/services/sqs.service'; +import { TypebotController } from './integrations/typebot/controllers/typebot.controller'; +import { TypebotRepository } from './integrations/typebot/repository/typebot.repository'; +import { TypebotService } from './integrations/typebot/services/typebot.service'; +import { WebsocketController } from './integrations/websocket/controllers/websocket.controller'; +import { WebsocketRepository } from './integrations/websocket/repository/websocket.repository'; +import { WebsocketService } from './integrations/websocket/services/websocket.service'; import { AuthModel, ChamaaiModel, @@ -39,33 +49,23 @@ import { LabelModel } from './models/label.model'; import { AuthRepository } from './repository/auth.repository'; import { ChamaaiRepository } from './repository/chamaai.repository'; import { ChatRepository } from './repository/chat.repository'; -import { ChatwootRepository } from './repository/chatwoot.repository'; import { ContactRepository } from './repository/contact.repository'; import { IntegrationRepository } from './repository/integration.repository'; import { LabelRepository } from './repository/label.repository'; import { MessageRepository } from './repository/message.repository'; import { MessageUpRepository } from './repository/messageUp.repository'; import { ProxyRepository } from './repository/proxy.repository'; -import { RabbitmqRepository } from './repository/rabbitmq.repository'; import { RepositoryBroker } from './repository/repository.manager'; import { SettingsRepository } from './repository/settings.repository'; -import { SqsRepository } from './repository/sqs.repository'; -import { TypebotRepository } from './repository/typebot.repository'; import { WebhookRepository } from './repository/webhook.repository'; -import { WebsocketRepository } from './repository/websocket.repository'; import { AuthService } from './services/auth.service'; import { CacheService } from './services/cache.service'; import { ChamaaiService } from './services/chamaai.service'; -import { ChatwootService } from './services/chatwoot.service'; import { IntegrationService } from './services/integration.service'; import { WAMonitoringService } from './services/monitor.service'; import { ProxyService } from './services/proxy.service'; -import { RabbitmqService } from './services/rabbitmq.service'; import { SettingsService } from './services/settings.service'; -import { SqsService } from './services/sqs.service'; -import { TypebotService } from './services/typebot.service'; import { WebhookService } from './services/webhook.service'; -import { WebsocketService } from './services/websocket.service'; const logger = new Logger('WA MODULE'); diff --git a/src/whatsapp/services/auth.service.ts b/src/api/services/auth.service.ts similarity index 100% rename from src/whatsapp/services/auth.service.ts rename to src/api/services/auth.service.ts diff --git a/src/whatsapp/services/cache.service.ts b/src/api/services/cache.service.ts similarity index 100% rename from src/whatsapp/services/cache.service.ts rename to src/api/services/cache.service.ts diff --git a/src/whatsapp/services/chamaai.service.ts b/src/api/services/chamaai.service.ts similarity index 100% rename from src/whatsapp/services/chamaai.service.ts rename to src/api/services/chamaai.service.ts diff --git a/src/whatsapp/services/integration.service.ts b/src/api/services/integration.service.ts similarity index 100% rename from src/whatsapp/services/integration.service.ts rename to src/api/services/integration.service.ts diff --git a/src/whatsapp/services/monitor.service.ts b/src/api/services/monitor.service.ts similarity index 100% rename from src/whatsapp/services/monitor.service.ts rename to src/api/services/monitor.service.ts diff --git a/src/whatsapp/services/proxy.service.ts b/src/api/services/proxy.service.ts similarity index 100% rename from src/whatsapp/services/proxy.service.ts rename to src/api/services/proxy.service.ts diff --git a/src/whatsapp/services/settings.service.ts b/src/api/services/settings.service.ts similarity index 100% rename from src/whatsapp/services/settings.service.ts rename to src/api/services/settings.service.ts diff --git a/src/whatsapp/services/webhook.service.ts b/src/api/services/webhook.service.ts similarity index 100% rename from src/whatsapp/services/webhook.service.ts rename to src/api/services/webhook.service.ts diff --git a/src/whatsapp/services/whatsapp.baileys.service.ts b/src/api/services/whatsapp.baileys.service.ts similarity index 99% rename from src/whatsapp/services/whatsapp.baileys.service.ts rename to src/api/services/whatsapp.baileys.service.ts index 4cf9f4e2..ef39b0fc 100644 --- a/src/whatsapp/services/whatsapp.baileys.service.ts +++ b/src/api/services/whatsapp.baileys.service.ts @@ -59,7 +59,6 @@ import { INSTANCE_DIR } from '../../config/path.config'; import { BadRequestException, InternalServerErrorException, NotFoundException } from '../../exceptions'; import { dbserver } from '../../libs/db.connect'; import { RedisCache } from '../../libs/redis.client'; -import { chatwootImport } from '../../utils/chatwoot-import-helper'; import { makeProxyAgent } from '../../utils/makeProxyAgent'; import { useMultiFileAuthStateDb } from '../../utils/use-multi-file-auth-state-db'; import { useMultiFileAuthStateRedisDb } from '../../utils/use-multi-file-auth-state-redis-db'; @@ -110,13 +109,14 @@ import { SendTextDto, StatusMessage, } from '../dto/sendMessage.dto'; +import { chatwootImport } from '../integrations/chatwoot/utils/chatwoot-import-helper'; import { SettingsRaw } from '../models'; import { ChatRaw } from '../models/chat.model'; import { ContactRaw } from '../models/contact.model'; import { MessageRaw, MessageUpdateRaw } from '../models/message.model'; import { RepositoryBroker } from '../repository/repository.manager'; +import { waMonitor } from '../server.module'; import { Events, MessageSubtype, TypeMediaMessage, wa } from '../types/wa.types'; -import { waMonitor } from '../whatsapp.module'; import { CacheService } from './cache.service'; import { WAStartupService } from './whatsapp.service'; diff --git a/src/whatsapp/services/whatsapp.business.service.ts b/src/api/services/whatsapp.business.service.ts similarity index 100% rename from src/whatsapp/services/whatsapp.business.service.ts rename to src/api/services/whatsapp.business.service.ts diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/api/services/whatsapp.service.ts similarity index 98% rename from src/whatsapp/services/whatsapp.service.ts rename to src/api/services/whatsapp.service.ts index eaa4dc65..b9cece5a 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/api/services/whatsapp.service.ts @@ -20,23 +20,23 @@ import { import { Logger } from '../../config/logger.config'; import { ROOT_DIR } from '../../config/path.config'; import { NotFoundException } from '../../exceptions'; -import { getAMQP, removeQueues } from '../../libs/amqp.server'; -import { getIO } from '../../libs/socket.server'; -import { getSQS, removeQueues as removeQueuesSQS } from '../../libs/sqs.server'; +import { ChatwootRaw } from '../integrations/chatwoot/models/chatwoot.model'; +import { ChatwootService } from '../integrations/chatwoot/services/chatwoot.service'; +import { getAMQP, removeQueues } from '../integrations/rabbitmq/libs/amqp.server'; +import { getSQS, removeQueues as removeQueuesSQS } from '../integrations/sqs/libs/sqs.server'; +import { TypebotService } from '../integrations/typebot/services/typebot.service'; +import { getIO } from '../integrations/websocket/libs/socket.server'; +import { WebsocketRaw } from '../integrations/websocket/models/websocket.model'; import { ChamaaiRaw, IntegrationRaw, ProxyRaw, RabbitmqRaw, SettingsRaw, SqsRaw, TypebotRaw } from '../models'; -import { ChatwootRaw } from '../models/chatwoot.model'; import { WebhookRaw } from '../models/webhook.model'; -import { WebsocketRaw } from '../models/websocket.model'; import { ContactQuery } from '../repository/contact.repository'; import { MessageQuery } from '../repository/message.repository'; import { MessageUpQuery } from '../repository/messageUp.repository'; import { RepositoryBroker } from '../repository/repository.manager'; +import { waMonitor } from '../server.module'; import { Events, wa } from '../types/wa.types'; -import { waMonitor } from '../whatsapp.module'; import { CacheService } from './cache.service'; import { ChamaaiService } from './chamaai.service'; -import { ChatwootService } from './chatwoot.service'; -import { TypebotService } from './typebot.service'; export class WAStartupService { constructor( diff --git a/src/whatsapp/types/wa.types.ts b/src/api/types/wa.types.ts similarity index 100% rename from src/whatsapp/types/wa.types.ts rename to src/api/types/wa.types.ts diff --git a/src/exceptions/400.exception.ts b/src/exceptions/400.exception.ts index 833295c1..6697aeb2 100644 --- a/src/exceptions/400.exception.ts +++ b/src/exceptions/400.exception.ts @@ -1,4 +1,4 @@ -import { HttpStatus } from '../whatsapp/routers/index.router'; +import { HttpStatus } from '../api/routers/index.router'; export class BadRequestException { constructor(...objectError: any[]) { diff --git a/src/exceptions/401.exception.ts b/src/exceptions/401.exception.ts index d5424c71..8fd72da2 100644 --- a/src/exceptions/401.exception.ts +++ b/src/exceptions/401.exception.ts @@ -1,4 +1,4 @@ -import { HttpStatus } from '../whatsapp/routers/index.router'; +import { HttpStatus } from '../api/routers/index.router'; export class UnauthorizedException { constructor(...objectError: any[]) { diff --git a/src/exceptions/403.exception.ts b/src/exceptions/403.exception.ts index f53ca9a5..a7c118bd 100644 --- a/src/exceptions/403.exception.ts +++ b/src/exceptions/403.exception.ts @@ -1,4 +1,4 @@ -import { HttpStatus } from '../whatsapp/routers/index.router'; +import { HttpStatus } from '../api/routers/index.router'; export class ForbiddenException { constructor(...objectError: any[]) { diff --git a/src/exceptions/404.exception.ts b/src/exceptions/404.exception.ts index 1119d1a1..6c06f095 100644 --- a/src/exceptions/404.exception.ts +++ b/src/exceptions/404.exception.ts @@ -1,4 +1,4 @@ -import { HttpStatus } from '../whatsapp/routers/index.router'; +import { HttpStatus } from '../api/routers/index.router'; export class NotFoundException { constructor(...objectError: any[]) { diff --git a/src/exceptions/500.exception.ts b/src/exceptions/500.exception.ts index 2a41dfa5..445f240b 100644 --- a/src/exceptions/500.exception.ts +++ b/src/exceptions/500.exception.ts @@ -1,4 +1,4 @@ -import { HttpStatus } from '../whatsapp/routers/index.router'; +import { HttpStatus } from '../api/routers/index.router'; export class InternalServerErrorException { constructor(...objectError: any[]) { diff --git a/src/main.ts b/src/main.ts index 554d95e8..49a3d153 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,17 +6,17 @@ import cors from 'cors'; import express, { json, NextFunction, Request, Response, urlencoded } from 'express'; import { join } from 'path'; +import { initAMQP } from './api/integrations/rabbitmq/libs/amqp.server'; +import { initSQS } from './api/integrations/sqs/libs/sqs.server'; +import { initIO } from './api/integrations/websocket/libs/socket.server'; +import { HttpStatus, router } from './api/routers/index.router'; +import { waMonitor } from './api/server.module'; import { Auth, configService, Cors, HttpServer, Rabbitmq, Sqs, Webhook } from './config/env.config'; import { onUnexpectedError } from './config/error.config'; import { Logger } from './config/logger.config'; import { ROOT_DIR } from './config/path.config'; import { swaggerRouter } from './docs/swagger.conf'; -import { initAMQP } from './libs/amqp.server'; -import { initIO } from './libs/socket.server'; -import { initSQS } from './libs/sqs.server'; import { ServerUP } from './utils/server-up'; -import { HttpStatus, router } from './whatsapp/routers/index.router'; -import { waMonitor } from './whatsapp/whatsapp.module'; function initWA() { waMonitor.loadInstance(); diff --git a/src/utils/makeProxyAgent.ts b/src/utils/makeProxyAgent.ts index 45486523..60d5f20c 100644 --- a/src/utils/makeProxyAgent.ts +++ b/src/utils/makeProxyAgent.ts @@ -1,6 +1,6 @@ import { HttpsProxyAgent } from 'https-proxy-agent'; -import { wa } from '../whatsapp/types/wa.types'; +import { wa } from '../api/types/wa.types'; export function makeProxyAgent(proxy: wa.Proxy | string) { if (typeof proxy === 'string') { diff --git a/src/validate/validate.schema.ts b/src/validate/validate.schema.ts index b723826a..6bafb9b9 100644 --- a/src/validate/validate.schema.ts +++ b/src/validate/validate.schema.ts @@ -1,6 +1,12 @@ import { JSONSchema7, JSONSchema7Definition } from 'json-schema'; import { v4 } from 'uuid'; +// Integrations Schema +export * from '../api/integrations/chatwoot/validate/chatwoot.schema'; +export * from '../api/integrations/rabbitmq/validate/rabbitmq.schema'; +export * from '../api/integrations/sqs/validate/sqs.schema'; +export * from '../api/integrations/typebot/validate/typebot.schema'; + const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => { const properties = {}; propertyNames.forEach( @@ -957,27 +963,6 @@ export const webhookSchema: JSONSchema7 = { ...isNotEmpty('url'), }; -export const chatwootSchema: JSONSchema7 = { - $id: v4(), - type: 'object', - properties: { - enabled: { type: 'boolean', enum: [true, false] }, - account_id: { type: 'string' }, - token: { type: 'string' }, - url: { type: 'string' }, - sign_msg: { type: 'boolean', enum: [true, false] }, - sign_delimiter: { type: ['string', 'null'] }, - reopen_conversation: { type: 'boolean', enum: [true, false] }, - conversation_pending: { type: 'boolean', enum: [true, false] }, - auto_create: { type: 'boolean', enum: [true, false] }, - import_contacts: { type: 'boolean', enum: [true, false] }, - import_messages: { type: 'boolean', enum: [true, false] }, - days_limit_import_messages: { type: 'number' }, - }, - required: ['enabled', 'account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'], - ...isNotEmpty('account_id', 'token', 'url', 'sign_msg', 'reopen_conversation', 'conversation_pending'), -}; - export const settingsSchema: JSONSchema7 = { $id: v4(), type: 'object', @@ -1039,135 +1024,6 @@ export const websocketSchema: JSONSchema7 = { ...isNotEmpty('enabled'), }; -export const rabbitmqSchema: JSONSchema7 = { - $id: v4(), - type: 'object', - properties: { - enabled: { type: 'boolean', enum: [true, false] }, - events: { - type: 'array', - minItems: 0, - items: { - type: 'string', - enum: [ - 'APPLICATION_STARTUP', - 'QRCODE_UPDATED', - 'MESSAGES_SET', - 'MESSAGES_UPSERT', - 'MESSAGES_UPDATE', - 'MESSAGES_DELETE', - 'SEND_MESSAGE', - 'CONTACTS_SET', - 'CONTACTS_UPSERT', - 'CONTACTS_UPDATE', - 'PRESENCE_UPDATE', - 'CHATS_SET', - 'CHATS_UPSERT', - 'CHATS_UPDATE', - 'CHATS_DELETE', - 'GROUPS_UPSERT', - 'GROUP_UPDATE', - 'GROUP_PARTICIPANTS_UPDATE', - 'CONNECTION_UPDATE', - 'LABELS_EDIT', - 'LABELS_ASSOCIATION', - 'CALL', - 'NEW_JWT_TOKEN', - 'TYPEBOT_START', - 'TYPEBOT_CHANGE_STATUS', - 'CHAMA_AI_ACTION', - ], - }, - }, - }, - required: ['enabled'], - ...isNotEmpty('enabled'), -}; - -export const sqsSchema: JSONSchema7 = { - $id: v4(), - type: 'object', - properties: { - enabled: { type: 'boolean', enum: [true, false] }, - events: { - type: 'array', - minItems: 0, - items: { - type: 'string', - enum: [ - 'APPLICATION_STARTUP', - 'QRCODE_UPDATED', - 'MESSAGES_SET', - 'MESSAGES_UPSERT', - 'MESSAGES_UPDATE', - 'MESSAGES_DELETE', - 'SEND_MESSAGE', - 'CONTACTS_SET', - 'CONTACTS_UPSERT', - 'CONTACTS_UPDATE', - 'PRESENCE_UPDATE', - 'CHATS_SET', - 'CHATS_UPSERT', - 'CHATS_UPDATE', - 'CHATS_DELETE', - 'GROUPS_UPSERT', - 'GROUP_UPDATE', - 'GROUP_PARTICIPANTS_UPDATE', - 'CONNECTION_UPDATE', - 'LABELS_EDIT', - 'LABELS_ASSOCIATION', - 'CALL', - 'NEW_JWT_TOKEN', - 'TYPEBOT_START', - 'TYPEBOT_CHANGE_STATUS', - 'CHAMA_AI_ACTION', - ], - }, - }, - }, - required: ['enabled'], - ...isNotEmpty('enabled'), -}; - -export const typebotSchema: JSONSchema7 = { - $id: v4(), - type: 'object', - properties: { - enabled: { type: 'boolean', enum: [true, false] }, - url: { type: 'string' }, - typebot: { type: 'string' }, - expire: { type: 'integer' }, - delay_message: { type: 'integer' }, - unknown_message: { type: 'string' }, - listening_from_me: { type: 'boolean', enum: [true, false] }, - }, - required: ['enabled', 'url', 'typebot', 'expire', 'delay_message', 'unknown_message', 'listening_from_me'], - ...isNotEmpty('enabled', 'url', 'typebot', 'expire', 'delay_message', 'unknown_message', 'listening_from_me'), -}; - -export const typebotStatusSchema: JSONSchema7 = { - $id: v4(), - type: 'object', - properties: { - remoteJid: { type: 'string' }, - status: { type: 'string', enum: ['opened', 'closed', 'paused'] }, - }, - required: ['remoteJid', 'status'], - ...isNotEmpty('remoteJid', 'status'), -}; - -export const typebotStartSchema: JSONSchema7 = { - $id: v4(), - type: 'object', - properties: { - remoteJid: { type: 'string' }, - url: { type: 'string' }, - typebot: { type: 'string' }, - }, - required: ['remoteJid', 'url', 'typebot'], - ...isNotEmpty('remoteJid', 'url', 'typebot'), -}; - export const proxySchema: JSONSchema7 = { $id: v4(), type: 'object',