159 lines
6.2 KiB
JavaScript
159 lines
6.2 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Shared application bootstrap (migrations, background jobs, game registration).
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.bootstrapCore = bootstrapCore;
|
|
const config_1 = require("../config");
|
|
const connection_1 = require("../db/connection");
|
|
const bootstrap_1 = require("../games/bootstrap");
|
|
const engineRunner_1 = require("../games/engineRunner");
|
|
const depositMonitorService_1 = require("../services/depositMonitorService");
|
|
const securityService_1 = require("../services/securityService");
|
|
const fileIntegrityService_1 = require("../services/fileIntegrityService");
|
|
const dbTamperService_1 = require("../services/dbTamperService");
|
|
const sweepBatchService_1 = require("../services/sweepBatchService");
|
|
const countryService_1 = require("../services/countryService");
|
|
const userAdminStatsService_1 = require("../services/userAdminStatsService");
|
|
const adminUserExportService_1 = require("../services/adminUserExportService");
|
|
const referralService_1 = require("../services/referralService");
|
|
const analyticsMaterializedViews_1 = require("../utils/analyticsMaterializedViews");
|
|
const encryptionRotationReminderService_1 = require("../services/encryptionRotationReminderService");
|
|
const networkGuard_1 = require("../safety/networkGuard");
|
|
const productionSecretsGuard_1 = require("../safety/productionSecretsGuard");
|
|
const client_1 = require("../realtime/redis/client");
|
|
const DEPOSIT_POLL_INTERVAL_MS = 60 * 1000;
|
|
async function startDepositMonitor() {
|
|
const run = async () => {
|
|
try {
|
|
await (0, depositMonitorService_1.processTronDeposits)();
|
|
}
|
|
catch (e) {
|
|
console.error('Deposit monitor error:', e);
|
|
}
|
|
setTimeout(run, DEPOSIT_POLL_INTERVAL_MS);
|
|
};
|
|
setTimeout(run, 10 * 1000);
|
|
}
|
|
function startLedgerIntegrityMonitor() {
|
|
const intervalMs = (0, securityService_1.getIntegrityCheckIntervalMs)();
|
|
const run = async () => {
|
|
try {
|
|
const issues = await (0, securityService_1.runLedgerIntegrityCheck)();
|
|
if (issues.length > 0) {
|
|
console.warn(`[security] Ledger integrity check found ${issues.length} issue(s)`);
|
|
}
|
|
}
|
|
catch (e) {
|
|
console.error('Ledger integrity check error:', e);
|
|
}
|
|
setTimeout(run, intervalMs);
|
|
};
|
|
setTimeout(run, 30000);
|
|
}
|
|
function startFileIntegrityMonitor() {
|
|
const intervalMs = (0, securityService_1.getIntegrityCheckIntervalMs)();
|
|
const run = async () => {
|
|
try {
|
|
const issues = await (0, fileIntegrityService_1.runFileIntegrityCheck)();
|
|
if (issues.length > 0) {
|
|
console.warn(`[security] File integrity check found ${issues.length} issue(s)`);
|
|
}
|
|
}
|
|
catch (e) {
|
|
console.error('File integrity check error:', e);
|
|
}
|
|
setTimeout(run, intervalMs);
|
|
};
|
|
setTimeout(run, 45000);
|
|
}
|
|
function startDbTamperMonitor() {
|
|
const intervalMs = (0, dbTamperService_1.getTamperCheckIntervalMs)();
|
|
const run = async () => {
|
|
try {
|
|
const n = await (0, dbTamperService_1.processDbTamperEvents)();
|
|
if (n > 0) {
|
|
console.warn(`[security] Processed ${n} unauthorized DB change event(s)`);
|
|
}
|
|
}
|
|
catch (e) {
|
|
console.error('DB tamper monitor error:', e);
|
|
}
|
|
setTimeout(run, intervalMs);
|
|
};
|
|
setTimeout(run, 15000);
|
|
}
|
|
function startSweepBatchMonitor() {
|
|
const run = async () => {
|
|
try {
|
|
const n = await (0, sweepBatchService_1.createSweepBatchApprovalRequests)();
|
|
if (n > 0 && process.env.NODE_ENV !== 'production') {
|
|
console.log(`[sweep-batch] Enqueued ${n} batch approval request(s)`);
|
|
}
|
|
}
|
|
catch (e) {
|
|
console.error('Sweep batch job error:', e);
|
|
}
|
|
setTimeout(run, sweepBatchService_1.SWEEP_BATCH_INTERVAL_MS);
|
|
};
|
|
setTimeout(run, 60000);
|
|
}
|
|
function startReferralCommissionMonitor() {
|
|
const intervalMs = (0, referralService_1.getReferralCommissionPollIntervalMs)();
|
|
const run = async () => {
|
|
try {
|
|
const n = await (0, referralService_1.processPendingReferralCommissions)();
|
|
if (n > 0 && process.env.NODE_ENV !== 'production') {
|
|
console.log(`[referral] Settled ${n} pending commission(s)`);
|
|
}
|
|
}
|
|
catch (e) {
|
|
console.error('Referral commission monitor error:', e);
|
|
}
|
|
setTimeout(run, intervalMs);
|
|
};
|
|
setTimeout(run, 60000);
|
|
}
|
|
/** Core bootstrap shared by API and engine processes. */
|
|
async function bootstrapCore(opts = {}) {
|
|
const { startEngines = config_1.config.engineEnabled, startPlatformMonitors = true, runDevMigrations = config_1.config.env === 'development', } = opts;
|
|
(0, networkGuard_1.validateTestnetSafetyOrThrow)();
|
|
(0, networkGuard_1.validateProductionMainnetOrThrow)();
|
|
(0, productionSecretsGuard_1.validateProductionSecretsOrThrow)();
|
|
if (runDevMigrations) {
|
|
try {
|
|
await (0, connection_1.runMigrations)();
|
|
console.log('Migrations OK');
|
|
}
|
|
catch (e) {
|
|
console.warn('Migrations warning:', e);
|
|
}
|
|
}
|
|
await (0, countryService_1.ensureCountriesSeeded)();
|
|
if (config_1.config.redis.enabled) {
|
|
try {
|
|
await (0, client_1.connectRedis)();
|
|
console.log('[redis] Connected');
|
|
}
|
|
catch (e) {
|
|
console.warn('[redis] Connection failed (continuing without cache):', e);
|
|
}
|
|
}
|
|
(0, bootstrap_1.registerBuiltinGames)();
|
|
if (startPlatformMonitors) {
|
|
(0, userAdminStatsService_1.scheduleAdminStatsBackfill)();
|
|
(0, adminUserExportService_1.startAdminExportWorker)();
|
|
(0, analyticsMaterializedViews_1.scheduleAnalyticsMaterializedViewRefresh)();
|
|
startDepositMonitor();
|
|
startLedgerIntegrityMonitor();
|
|
startFileIntegrityMonitor();
|
|
startDbTamperMonitor();
|
|
startSweepBatchMonitor();
|
|
startReferralCommissionMonitor();
|
|
(0, encryptionRotationReminderService_1.scheduleEncryptionKeyRotationReminder)();
|
|
}
|
|
if (startEngines) {
|
|
(0, engineRunner_1.startRegisteredGameEngines)();
|
|
}
|
|
}
|
|
//# sourceMappingURL=appBootstrap.js.map
|