From 681fd73468c43894f4484cc0cee5f89edfc28e39 Mon Sep 17 00:00:00 2001 From: Dustin Healy <54083382+dustinhealy@users.noreply.github.com> Date: Thu, 14 May 2026 10:13:17 -0700 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20Share=20MAX=5F?= =?UTF-8?q?AUDIT=5FLOG=5FLIMIT=20between=20methods=20and=20handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Renamed the methods-layer constant from the generic `MAX_LIMIT` to `MAX_AUDIT_LOG_LIMIT`, exported it through `@librechat/data-schemas`, and consumed it from the handler instead of duplicating `500` there. Now the limit is single-sourced; bumping it once updates both the clamp inside `listAuditLogPage` and the 400-error boundary the handler returns to clients. --- packages/api/src/admin/auditLog.ts | 6 +++--- packages/data-schemas/src/index.ts | 1 + packages/data-schemas/src/methods/auditLog.ts | 4 ++-- packages/data-schemas/src/methods/index.ts | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/api/src/admin/auditLog.ts b/packages/api/src/admin/auditLog.ts index b7fdbfa580..29fb39165d 100644 --- a/packages/api/src/admin/auditLog.ts +++ b/packages/api/src/admin/auditLog.ts @@ -1,5 +1,5 @@ import { PrincipalType } from 'librechat-data-provider'; -import { logger } from '@librechat/data-schemas'; +import { logger, MAX_AUDIT_LOG_LIMIT } from '@librechat/data-schemas'; import type { AdminAuditLogEntry, AuditAction, @@ -23,7 +23,6 @@ const VALID_PRINCIPAL_TYPES = new Set(Object.values(PrincipalType)); */ const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,3})?)?(Z|[+-]\d{2}:\d{2}))?$/; const OBJECT_ID_RE = /^[a-fA-F0-9]{24}$/; -const MAX_LIMIT = 500; export interface AdminAuditLogDeps { listAuditLogPage: ( @@ -94,7 +93,8 @@ function parseLimit( const n = typeof raw === 'number' ? raw : Number.parseInt(String(raw), 10); if (!Number.isFinite(n)) return { ok: false, error: 'limit must be a number' }; if (n < 1) return { ok: false, error: 'limit must be >= 1' }; - if (n > MAX_LIMIT) return { ok: false, error: `limit must be <= ${MAX_LIMIT}` }; + if (n > MAX_AUDIT_LOG_LIMIT) + return { ok: false, error: `limit must be <= ${MAX_AUDIT_LOG_LIMIT}` }; return { ok: true, value: Math.floor(n) }; } diff --git a/packages/data-schemas/src/index.ts b/packages/data-schemas/src/index.ts index 3d99b90675..e63dc02a15 100644 --- a/packages/data-schemas/src/index.ts +++ b/packages/data-schemas/src/index.ts @@ -24,6 +24,7 @@ export { validateSkillFrontmatter, validateSkillDescription, deriveStructuredFrontmatterFields, + MAX_AUDIT_LOG_LIMIT, } from './methods'; export type * from './types'; export type * from './methods'; diff --git a/packages/data-schemas/src/methods/auditLog.ts b/packages/data-schemas/src/methods/auditLog.ts index 6adafb1e84..0e289a27f1 100644 --- a/packages/data-schemas/src/methods/auditLog.ts +++ b/packages/data-schemas/src/methods/auditLog.ts @@ -9,7 +9,7 @@ import type { import logger from '~/config/winston'; const DEFAULT_LIMIT = 100; -export const MAX_LIMIT = 500; +export const MAX_AUDIT_LOG_LIMIT = 500; const MAX_SEARCH_LENGTH = 200; export interface AuditLogMethods { @@ -96,7 +96,7 @@ function buildFilter( function clampLimit(limit?: number): number { if (!limit || Number.isNaN(limit) || limit < 1) return DEFAULT_LIMIT; - return Math.min(Math.floor(limit), MAX_LIMIT); + return Math.min(Math.floor(limit), MAX_AUDIT_LOG_LIMIT); } export function createAuditLogMethods(mongoose: typeof import('mongoose')): AuditLogMethods { diff --git a/packages/data-schemas/src/methods/index.ts b/packages/data-schemas/src/methods/index.ts index 8d3256dbc5..ac38fdf517 100644 --- a/packages/data-schemas/src/methods/index.ts +++ b/packages/data-schemas/src/methods/index.ts @@ -20,7 +20,7 @@ import { createAccessRoleMethods, type AccessRoleMethods } from './accessRole'; import { createUserGroupMethods, type UserGroupMethods } from './userGroup'; import { createAclEntryMethods, permissionBitSupersets, type AclEntryMethods } from './aclEntry'; import { createSystemGrantMethods, type SystemGrantMethods } from './systemGrant'; -import { createAuditLogMethods, type AuditLogMethods } from './auditLog'; +import { createAuditLogMethods, MAX_AUDIT_LOG_LIMIT, type AuditLogMethods } from './auditLog'; import { createShareMethods, type ShareMethods } from './share'; /* Tier 1 — Simple CRUD */ import { createActionMethods, type ActionMethods } from './action'; @@ -102,6 +102,7 @@ export { deriveStructuredFrontmatterFields, inferSkillFileCategory, }; +export { MAX_AUDIT_LOG_LIMIT }; export type AllMethods = UserMethods & SessionMethods &