fix(plugins): use conditional require for production Docker compatibility
Replace static require('backend/src/...') with NODE_ENV-conditional
requires in compiled plugin JS and TypeScript sources.
In production Docker /app/backend/src/ does not exist — only /app/dist/.
Fixes MODULE_NOT_FOUND errors on UnifiedStorageProvider, ext-api,
leads, nanobana, and uploads plugins.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,8 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const client_s3_1 = require("@aws-sdk/client-s3");
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
||||||
const lib_storage_1 = require("@aws-sdk/lib-storage");
|
const lib_storage_1 = require("@aws-sdk/lib-storage");
|
||||||
const StorageProvider_1 = require("../../backend/src/core/StorageProvider");
|
let storageProvider;
|
||||||
const plugin_config_1 = require("../../backend/src/core/plugin-config");
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
storageProvider = require('../../dist/core/StorageProvider').storageProvider;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
storageProvider = require('../../backend/src/core/StorageProvider').storageProvider;
|
||||||
|
}
|
||||||
const sharp_1 = __importDefault(require("sharp"));
|
const sharp_1 = __importDefault(require("sharp"));
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const fs_1 = __importDefault(require("fs"));
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
@@ -31,7 +36,7 @@ class UnifiedStorageProviderPlugin {
|
|||||||
}
|
}
|
||||||
async activate(ctx) {
|
async activate(ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
const cfg = plugin_config_1.pluginConfig.get('UnifiedStorageProvider') || {};
|
const cfg = ctx.config.get('UnifiedStorageProvider') || {};
|
||||||
if (!fs_1.default.existsSync(this.localFallbackDir)) {
|
if (!fs_1.default.existsSync(this.localFallbackDir)) {
|
||||||
fs_1.default.mkdirSync(this.localFallbackDir, { recursive: true });
|
fs_1.default.mkdirSync(this.localFallbackDir, { recursive: true });
|
||||||
}
|
}
|
||||||
@@ -52,7 +57,7 @@ class UnifiedStorageProviderPlugin {
|
|||||||
credentials: { accessKeyId: accessKey, secretAccessKey: secretKey },
|
credentials: { accessKeyId: accessKey, secretAccessKey: secretKey },
|
||||||
forcePathStyle: true,
|
forcePathStyle: true,
|
||||||
});
|
});
|
||||||
StorageProvider_1.storageProvider.register(this);
|
storageProvider.register(this);
|
||||||
ctx.logger.info(`UnifiedStorageProvider ativo — bucket: ${this.bucket} endpoint: ${endpoint}`);
|
ctx.logger.info(`UnifiedStorageProvider ativo — bucket: ${this.bucket} endpoint: ${endpoint}`);
|
||||||
this.startSyncWorker();
|
this.startSyncWorker();
|
||||||
}
|
}
|
||||||
@@ -152,7 +157,7 @@ class UnifiedStorageProviderPlugin {
|
|||||||
});
|
});
|
||||||
this.routesRegistered = true;
|
this.routesRegistered = true;
|
||||||
}
|
}
|
||||||
setInterval(() => { StorageProvider_1.storageProvider.updateHealth(); }, 30000);
|
setInterval(() => { storageProvider.updateHealth(); }, 30000);
|
||||||
}
|
}
|
||||||
async deactivate(ctx) {
|
async deactivate(ctx) {
|
||||||
this.s3 = null;
|
this.s3 = null;
|
||||||
@@ -184,6 +189,7 @@ class UnifiedStorageProviderPlugin {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (httpStatus === 403 || code === 'AccessDenied') {
|
if (httpStatus === 403 || code === 'AccessDenied') {
|
||||||
|
// 403 pode ser pagamento atrasado ou permissão negada
|
||||||
return {
|
return {
|
||||||
healthy: false, configured: true, reason: 'billing_error',
|
healthy: false, configured: true, reason: 'billing_error',
|
||||||
message: 'Acesso negado ao Wasabi (HTTP 403). Verifique se a conta está ativa e o pagamento em dia.',
|
message: 'Acesso negado ao Wasabi (HTTP 403). Verifique se a conta está ativa e o pagamento em dia.',
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -20,9 +20,21 @@ exports.buildExtRoutes = buildExtRoutes;
|
|||||||
const fs_1 = require("fs");
|
const fs_1 = require("fs");
|
||||||
const promises_1 = require("fs/promises");
|
const promises_1 = require("fs/promises");
|
||||||
const express_1 = require("express");
|
const express_1 = require("express");
|
||||||
const dragonfly_1 = require("../../../backend/src/infra/cache/dragonfly");
|
let dragonfly;
|
||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
dragonfly = require('../../../dist/infra/cache/dragonfly').dragonfly;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dragonfly = require('../../../backend/src/infra/cache/dragonfly').dragonfly;
|
||||||
|
}
|
||||||
const brain_1 = require("../../secretaria/brain");
|
const brain_1 = require("../../secretaria/brain");
|
||||||
const rich_message_1 = require("../../../backend/dist/modules/whatsapp/rich-message");
|
let sendRichMessage;
|
||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
sendRichMessage = require('../../../dist/modules/whatsapp/rich-message').sendRichMessage;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sendRichMessage = require('../../../backend/dist/modules/whatsapp/rich-message').sendRichMessage;
|
||||||
|
}
|
||||||
function uuid() {
|
function uuid() {
|
||||||
try {
|
try {
|
||||||
return crypto.randomUUID();
|
return crypto.randomUUID();
|
||||||
@@ -168,7 +180,7 @@ function buildExtRoutes(prisma, manager, db, config, hooks) {
|
|||||||
res.status(404).json({ error: 'Instância não encontrada' });
|
res.status(404).json({ error: 'Instância não encontrada' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const qrBase64 = await dragonfly_1.dragonfly.get(`instance:${instanceId}:qr`);
|
const qrBase64 = await dragonfly.get(`instance:${instanceId}:qr`);
|
||||||
if (!qrBase64) {
|
if (!qrBase64) {
|
||||||
res.status(404).json({ error: 'QR não disponível — inicie a conexão primeiro' });
|
res.status(404).json({ error: 'QR não disponível — inicie a conexão primeiro' });
|
||||||
return;
|
return;
|
||||||
@@ -496,7 +508,7 @@ function buildExtRoutes(prisma, manager, db, config, hooks) {
|
|||||||
const cleanList = nativeList
|
const cleanList = nativeList
|
||||||
? { buttonText: nativeList.buttonText, sections: nativeList.sections }
|
? { buttonText: nativeList.buttonText, sections: nativeList.sections }
|
||||||
: undefined;
|
: undefined;
|
||||||
await (0, rich_message_1.sendRichMessage)(sock, chat.jid, {
|
await sendRichMessage(sock, chat.jid, {
|
||||||
text: text?.trim() || undefined,
|
text: text?.trim() || undefined,
|
||||||
footer: resolvedFooter,
|
footer: resolvedFooter,
|
||||||
nativeButtons: nativeButtons,
|
nativeButtons: nativeButtons,
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -20,8 +20,14 @@ exports.buildWebhookDispatcher = buildWebhookDispatcher;
|
|||||||
* Timeout: 10s por requisição para não bloquear o event loop.
|
* Timeout: 10s por requisição para não bloquear o event loop.
|
||||||
*/
|
*/
|
||||||
const crypto_1 = require("crypto");
|
const crypto_1 = require("crypto");
|
||||||
const logger_1 = require("../../../backend/src/config/logger");
|
let rootLogger;
|
||||||
const logger = logger_1.logger.child({ module: 'webhook-dispatcher' });
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
rootLogger = require('../../../dist/config/logger').logger;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rootLogger = require('../../../backend/src/config/logger').logger;
|
||||||
|
}
|
||||||
|
const logger = rootLogger.child({ module: 'webhook-dispatcher' });
|
||||||
const DISPATCH_TIMEOUT_MS = 10000;
|
const DISPATCH_TIMEOUT_MS = 10000;
|
||||||
// Eventos hookBus → nome de evento no payload enviado ao receptor
|
// Eventos hookBus → nome de evento no payload enviado ao receptor
|
||||||
const HOOK_TO_EVENT = {
|
const HOOK_TO_EVENT = {
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"webhook-dispatcher.js","sourceRoot":"","sources":["webhook-dispatcher.ts"],"names":[],"mappings":";;AAqEA,wDAmCC;AAxGD;;;;;;;;;;;;;;;;;GAiBG;AACH,mCAAmC;AAGnC,+D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,aAAa,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;AACpG,CAAC"}
|
||||||
@@ -19,7 +19,12 @@
|
|||||||
import { createHmac } from 'crypto'
|
import { createHmac } from 'crypto'
|
||||||
import type { PrismaClient } from '@prisma/client'
|
import type { PrismaClient } from '@prisma/client'
|
||||||
import type { HookBus } from '../../../backend/src/core/hook-bus'
|
import type { HookBus } from '../../../backend/src/core/hook-bus'
|
||||||
import { logger as rootLogger } from '../../../backend/src/config/logger'
|
let rootLogger: any
|
||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
rootLogger = require('../../../dist/config/logger').logger
|
||||||
|
} else {
|
||||||
|
rootLogger = require('../../../backend/src/config/logger').logger
|
||||||
|
}
|
||||||
|
|
||||||
const logger = rootLogger.child({ module: 'webhook-dispatcher' })
|
const logger = rootLogger.child({ module: 'webhook-dispatcher' })
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,16 @@
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.createLeadsRoutes = createLeadsRoutes;
|
exports.createLeadsRoutes = createLeadsRoutes;
|
||||||
const express_1 = require("express");
|
const express_1 = require("express");
|
||||||
const auth_1 = require("../../../backend/src/middleware/auth");
|
let authenticate;
|
||||||
const rbac_1 = require("../../../backend/src/middleware/rbac");
|
let authorize;
|
||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
authenticate = require('../../../dist/middleware/auth').authMiddleware;
|
||||||
|
authorize = require('../../../dist/middleware/rbac').adminMiddleware;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
authenticate = require('../../../backend/src/middleware/auth').authMiddleware;
|
||||||
|
authorize = require('../../../backend/src/middleware/rbac').adminMiddleware;
|
||||||
|
}
|
||||||
const STATUS_VALUES = ['new', 'contacted', 'qualified', 'converted', 'lost'];
|
const STATUS_VALUES = ['new', 'contacted', 'qualified', 'converted', 'lost'];
|
||||||
const LEAD_TYPE_VALUES = ['cold', 'member'];
|
const LEAD_TYPE_VALUES = ['cold', 'member'];
|
||||||
function translateLead(lead) {
|
function translateLead(lead) {
|
||||||
@@ -21,7 +29,7 @@ function translateLead(lead) {
|
|||||||
function createLeadsRoutes(ctx) {
|
function createLeadsRoutes(ctx) {
|
||||||
const router = (0, express_1.Router)();
|
const router = (0, express_1.Router)();
|
||||||
const { db } = ctx;
|
const { db } = ctx;
|
||||||
const protectedRoutes = [auth_1.authenticate, (0, rbac_1.authorize)(['super_admin', 'admin'])];
|
const protectedRoutes = [authenticate, authorize(['super_admin', 'admin'])];
|
||||||
// GET /api/leads/metrics — Global metrics for super admin
|
// GET /api/leads/metrics — Global metrics for super admin
|
||||||
router.get('/metrics', ...protectedRoutes, async (req, res) => {
|
router.get('/metrics', ...protectedRoutes, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
@@ -95,7 +103,7 @@ function createLeadsRoutes(ctx) {
|
|||||||
res.status(500).json({ error: 'Erro ao buscar métricas' });
|
res.status(500).json({ error: 'Erro ao buscar métricas' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
router.get('/', auth_1.authenticate, async (req, res) => {
|
router.get('/', authenticate, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { partner_id, status, type, page = '1', limit = '20' } = req.query;
|
const { partner_id, status, type, page = '1', limit = '20' } = req.query;
|
||||||
const offset = (parseInt(page) - 1) * parseInt(limit);
|
const offset = (parseInt(page) - 1) * parseInt(limit);
|
||||||
@@ -124,7 +132,7 @@ function createLeadsRoutes(ctx) {
|
|||||||
res.status(500).json({ error: 'Erro ao listar leads' });
|
res.status(500).json({ error: 'Erro ao listar leads' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
router.get('/:id', auth_1.authenticate, async (req, res) => {
|
router.get('/:id', authenticate, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const id = Number(req.params.id);
|
const id = Number(req.params.id);
|
||||||
const lead = await db('leads').where({ id }).first();
|
const lead = await db('leads').where({ id }).first();
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -5,15 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.createRoutes = createRoutes;
|
exports.createRoutes = createRoutes;
|
||||||
const express_1 = require("express");
|
const express_1 = require("express");
|
||||||
const plugin_config_1 = require("../../../backend/src/core/plugin-config");
|
|
||||||
const openai_1 = __importDefault(require("openai"));
|
const openai_1 = __importDefault(require("openai"));
|
||||||
const fs_1 = __importDefault(require("fs"));
|
const fs_1 = __importDefault(require("fs"));
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
const https_1 = __importDefault(require("https"));
|
const https_1 = __importDefault(require("https"));
|
||||||
const uuid_1 = require("uuid");
|
const uuid_1 = require("uuid");
|
||||||
const config_1 = require("../../../backend/src/config");
|
|
||||||
function createRoutes(ctx) {
|
function createRoutes(ctx) {
|
||||||
const router = (0, express_1.Router)();
|
const router = (0, express_1.Router)();
|
||||||
|
const uploadDir = process.env.UPLOAD_DIR || path_1.default.join(process.cwd(), 'uploads');
|
||||||
router.get('/', (req, res) => {
|
router.get('/', (req, res) => {
|
||||||
res.json({
|
res.json({
|
||||||
message: 'Nanobana plugin active',
|
message: 'Nanobana plugin active',
|
||||||
@@ -43,7 +42,7 @@ function createRoutes(ctx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Get Config
|
// Get Config
|
||||||
const nanobanaConfig = plugin_config_1.pluginConfig.get('nanobana');
|
const nanobanaConfig = ctx.config.get('nanobana');
|
||||||
const apiKey = nanobanaConfig?.apiKey;
|
const apiKey = nanobanaConfig?.apiKey;
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
return res.status(400).json({ error: 'OpenAI API Key não configurada no plugin Nanobana.' });
|
return res.status(400).json({ error: 'OpenAI API Key não configurada no plugin Nanobana.' });
|
||||||
@@ -58,7 +57,7 @@ function createRoutes(ctx) {
|
|||||||
// Resolve local path
|
// Resolve local path
|
||||||
if (refUrl.includes('/uploads/')) {
|
if (refUrl.includes('/uploads/')) {
|
||||||
const filename = path_1.default.basename(refUrl);
|
const filename = path_1.default.basename(refUrl);
|
||||||
imagePath = path_1.default.join(config_1.config.upload.dir, filename);
|
imagePath = path_1.default.join(uploadDir, filename);
|
||||||
}
|
}
|
||||||
if (imagePath && fs_1.default.existsSync(imagePath)) {
|
if (imagePath && fs_1.default.existsSync(imagePath)) {
|
||||||
const imageBuffer = fs_1.default.readFileSync(imagePath);
|
const imageBuffer = fs_1.default.readFileSync(imagePath);
|
||||||
@@ -121,7 +120,7 @@ function createRoutes(ctx) {
|
|||||||
// Download Image to Local Storage
|
// Download Image to Local Storage
|
||||||
const ext = '.png'; // DALL-E 3 usually png
|
const ext = '.png'; // DALL-E 3 usually png
|
||||||
const filename = `${(0, uuid_1.v4)()}${ext}`;
|
const filename = `${(0, uuid_1.v4)()}${ext}`;
|
||||||
const localPath = path_1.default.join(config_1.config.upload.dir, filename);
|
const localPath = path_1.default.join(uploadDir, filename);
|
||||||
const publicUrl = `/uploads/${filename}`;
|
const publicUrl = `/uploads/${filename}`;
|
||||||
const file = fs_1.default.createWriteStream(localPath);
|
const file = fs_1.default.createWriteStream(localPath);
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -46,8 +46,10 @@ function createUploadRoutes(ctx) {
|
|||||||
if (destination === 'cloud') {
|
if (destination === 'cloud') {
|
||||||
if (fs_1.default.existsSync(req.file.path))
|
if (fs_1.default.existsSync(req.file.path))
|
||||||
fs_1.default.unlinkSync(req.file.path);
|
fs_1.default.unlinkSync(req.file.path);
|
||||||
// Use a more robust import for the singleton
|
// Use a more robust import for the singleton (conditional for production Docker)
|
||||||
const storageCore = require('../../../../backend/src/core/StorageProvider');
|
const storageCore = process.env.NODE_ENV === 'production'
|
||||||
|
? require('../../../../dist/core/StorageProvider')
|
||||||
|
: require('../../../../backend/src/core/StorageProvider');
|
||||||
const provider = storageCore.storageProvider || (storageCore.default && storageCore.default.storageProvider);
|
const provider = storageCore.storageProvider || (storageCore.default && storageCore.default.storageProvider);
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
ctx.logger.error('[Uploads] StorageProvider not found in core');
|
ctx.logger.error('[Uploads] StorageProvider not found in core');
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -47,8 +47,10 @@ export function createUploadRoutes(ctx: PluginContext): Router {
|
|||||||
if (destination === 'cloud') {
|
if (destination === 'cloud') {
|
||||||
if (fs.existsSync(req.file.path)) fs.unlinkSync(req.file.path);
|
if (fs.existsSync(req.file.path)) fs.unlinkSync(req.file.path);
|
||||||
|
|
||||||
// Use a more robust import for the singleton
|
// Use a more robust import for the singleton (conditional for production Docker)
|
||||||
const storageCore = require('../../../../backend/src/core/StorageProvider');
|
const storageCore = process.env.NODE_ENV === 'production'
|
||||||
|
? require('../../../../dist/core/StorageProvider')
|
||||||
|
: require('../../../../backend/src/core/StorageProvider');
|
||||||
const provider = storageCore.storageProvider || (storageCore.default && storageCore.default.storageProvider);
|
const provider = storageCore.storageProvider || (storageCore.default && storageCore.default.storageProvider);
|
||||||
|
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
|
|||||||
Reference in New Issue
Block a user