89758a0e6b
Torna o registry de satélites (PluginPair) o gatekeeper do ext-api, em vez de uma única EXT_MASTER_KEY global: - satellites.ts: serviço + router /api/ext/v1/satellites (listar/provisionar/ revogar/rotacionar), montado fora do authMiddleware com gate de chave mestra. - apikey-auth: resolvePairKey aceita a chave do satélite (nwk_) no REST e no WS, resolvendo o tenant do par; checa revoke no banco a cada request (revoke instantâneo) + throttle de lastSeenAt. - Chave mestra e ApiKey por-tenant seguem funcionando (não-quebra). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
41 lines
2.7 KiB
JavaScript
41 lines
2.7 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 satellites_1 = require("./backend/satellites");
|
|
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, io } = 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, io);
|
|
// Gerenciador de satélites — montado ANTES do authMiddleware (gate próprio
|
|
// de chave mestra, sem exigir x-nw-email). Superadmin gerencia os PluginPairs.
|
|
app.use('/api/ext/v1/satellites', (0, satellites_1.buildSatelliteRoutes)(prisma));
|
|
logger.info('[ext-api] Gerenciador de satélites em /api/ext/v1/satellites (chave mestra)');
|
|
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
|