36 lines
2.2 KiB
JavaScript
36 lines
2.2 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const apikey_auth_1 = require("./backend/apikey-auth");
|
|
const routes_1 = require("./backend/routes");
|
|
const ws_bridge_1 = require("./backend/ws-bridge");
|
|
const webhook_dispatcher_1 = require("./backend/webhook-dispatcher");
|
|
const manifest_json_1 = __importDefault(require("./manifest.json"));
|
|
const plugin = {
|
|
manifest: manifest_json_1.default,
|
|
async activate(ctx) {
|
|
const { app, prisma, db, config, hooks, logger, httpServer } = ctx;
|
|
// ── REST ────────────────────────────────────────────────────────────────
|
|
const manager = globalThis.__whatsAppManager;
|
|
if (!manager) {
|
|
logger.warn('[ext-api] WhatsAppConnectionManager não disponível via globalThis.__whatsAppManager — endpoints de send desativados');
|
|
}
|
|
const authMiddleware = (0, apikey_auth_1.buildApiKeyAuth)(prisma);
|
|
const extRouter = (0, routes_1.buildExtRoutes)(prisma, manager, db, config, hooks);
|
|
app.use('/api/ext/v1', authMiddleware, extRouter);
|
|
logger.info('[ext-api] Rotas REST registradas em /api/ext/v1');
|
|
// ── WS Bridge ───────────────────────────────────────────────────────────
|
|
(0, ws_bridge_1.buildWsBridge)(httpServer, prisma, hooks);
|
|
logger.info('[ext-api] WS bridge ativo em /api/ext/v1/stream (x-nw-key auth)');
|
|
// ── Webhook Dispatcher ──────────────────────────────────────────────────
|
|
(0, webhook_dispatcher_1.buildWebhookDispatcher)(prisma, hooks);
|
|
logger.info('[ext-api] Webhook dispatcher ativo');
|
|
},
|
|
async deactivate(ctx) {
|
|
ctx.logger.warn('[ext-api] Desativado. Reinicie o servidor para remover as rotas.');
|
|
},
|
|
};
|
|
exports.default = plugin;
|
|
//# sourceMappingURL=index.js.map
|