"use strict"; /** * System settings service. * Applies validation and business rules for admin configuration updates. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.getSettings = getSettings; exports.parseSettingsUpdates = parseSettingsUpdates; exports.updateSettings = updateSettings; const settingsRepository = __importStar(require("../repositories/settingsRepository")); function clampInt(value, min, max) { return Math.min(max, Math.max(min, value)); } function validateUpdates(updates) { if (updates.password_min_length !== undefined) { updates.password_min_length = clampInt(updates.password_min_length, 6, 128); } if (updates.rate_limit_window_ms !== undefined) { updates.rate_limit_window_ms = clampInt(updates.rate_limit_window_ms, 60000, 3600000); } if (updates.rate_limit_max !== undefined) { updates.rate_limit_max = clampInt(updates.rate_limit_max, 10, 10000); } if (updates.login_rate_limit_max !== undefined) { updates.login_rate_limit_max = clampInt(updates.login_rate_limit_max, 1, 100); } if (updates.daily_withdrawal_limit_usd !== undefined) { updates.daily_withdrawal_limit_usd = clampInt(updates.daily_withdrawal_limit_usd, 1, 1000000); } if (updates.large_withdrawal_threshold_usd !== undefined) { updates.large_withdrawal_threshold_usd = clampInt(updates.large_withdrawal_threshold_usd, 1, 1000000); } if (updates.candle_predict_engine_tick_ms !== undefined) { updates.candle_predict_engine_tick_ms = clampInt(updates.candle_predict_engine_tick_ms, 1000, 60000); } if (updates.candle_predict_backfill_max_per_tick !== undefined) { updates.candle_predict_backfill_max_per_tick = clampInt(updates.candle_predict_backfill_max_per_tick, 1, 50); } if (updates.candle_predict_backfill_interval_ms !== undefined) { updates.candle_predict_backfill_interval_ms = clampInt(updates.candle_predict_backfill_interval_ms, 10000, 600000); } if (updates.candle_predict_backfill_seed_max !== undefined) { updates.candle_predict_backfill_seed_max = clampInt(updates.candle_predict_backfill_seed_max, 5, 120); } if (updates.withdrawal_network_fee_usdt_micro !== undefined) { updates.withdrawal_network_fee_usdt_micro = clampInt(updates.withdrawal_network_fee_usdt_micro, 0, 100000000); } } /** * Returns the current merged system settings (DB values with defaults). * @returns Password policy, token expiry, and runtime ops configuration */ async function getSettings() { return settingsRepository.getSettings(); } /** * Builds a partial settings update from an untyped HTTP request body. * Only recognized keys with valid types are included. * @param body Raw JSON body from the client * @returns Partial settings safe to pass to the repository */ function parseSettingsUpdates(body) { const updates = {}; if (typeof body.password_min_length === 'number') { updates.password_min_length = body.password_min_length; } if (typeof body.password_require_uppercase === 'boolean') { updates.password_require_uppercase = body.password_require_uppercase; } if (typeof body.password_require_lowercase === 'boolean') { updates.password_require_lowercase = body.password_require_lowercase; } if (typeof body.password_require_number === 'boolean') { updates.password_require_number = body.password_require_number; } if (typeof body.password_require_special === 'boolean') { updates.password_require_special = body.password_require_special; } if (typeof body.access_token_expiry === 'string') { updates.access_token_expiry = body.access_token_expiry; } if (typeof body.refresh_token_expiry === 'string') { updates.refresh_token_expiry = body.refresh_token_expiry; } if (typeof body.require_email_verification_for_login === 'boolean') { updates.require_email_verification_for_login = body.require_email_verification_for_login; } if (typeof body.allow_withdrawals === 'boolean') { updates.allow_withdrawals = body.allow_withdrawals; } if (typeof body.rate_limit_window_ms === 'number') { updates.rate_limit_window_ms = body.rate_limit_window_ms; } if (typeof body.rate_limit_max === 'number') { updates.rate_limit_max = body.rate_limit_max; } if (typeof body.login_rate_limit_max === 'number') { updates.login_rate_limit_max = body.login_rate_limit_max; } if (typeof body.daily_withdrawal_limit_usd === 'number') { updates.daily_withdrawal_limit_usd = body.daily_withdrawal_limit_usd; } if (typeof body.large_withdrawal_threshold_usd === 'number') { updates.large_withdrawal_threshold_usd = body.large_withdrawal_threshold_usd; } if (typeof body.candle_predict_engine_tick_ms === 'number') { updates.candle_predict_engine_tick_ms = body.candle_predict_engine_tick_ms; } if (typeof body.candle_predict_backfill_max_per_tick === 'number') { updates.candle_predict_backfill_max_per_tick = body.candle_predict_backfill_max_per_tick; } if (typeof body.candle_predict_backfill_interval_ms === 'number') { updates.candle_predict_backfill_interval_ms = body.candle_predict_backfill_interval_ms; } if (typeof body.candle_predict_backfill_seed_max === 'number') { updates.candle_predict_backfill_seed_max = body.candle_predict_backfill_seed_max; } if (typeof body.withdrawal_network_fee_usdt_micro === 'number') { updates.withdrawal_network_fee_usdt_micro = body.withdrawal_network_fee_usdt_micro; } return updates; } /** * Persists settings changes and returns the updated configuration. * @param updates Partial settings from [parseSettingsUpdates] * @returns Full settings after update */ async function updateSettings(updates) { validateUpdates(updates); await settingsRepository.updateSettings(updates); return settingsRepository.getSettings(); } //# sourceMappingURL=settingsService.js.map