LibreChat/client/src/utils/terms.ts
Marco Beretta 79b836d79f
📃 fix: Enforce Terms Acceptance on the Server and Mark Backfilled Consent (#17063)
* fix: Enforce Terms Acceptance on the Server When modalAcceptance Is On

* fix: Mark Backfilled Terms Acceptance Timestamps

* test: Cover Server-Enforced Terms Acceptance in the Mock Harness

* fix: Gate Management Routes and Skill Sync and Resolve Terms Policy Fail-Closed

* fix: Evict Cached Auth Documents When Terms Acceptance Is Reset

* fix: Guard Skill Sync Behind Terms Acceptance for Every Skill List Route

* fix: Move Terms Skill-Sync Guard Into the API Package and Evict All Users on Reset

* fix: Batch Terms Reset Cache Eviction and Sign the Spec User In Fresh

* fix: Let Stop Through the Terms Gate, Refresh Startup Config, and Wait Out Failed Eviction

* refactor: Narrow the Terms Exemptions and Share One Refusal Path Across Clients

* refactor: Compose the JWT Terms Gate Through an API Package Helper

* style: Sort Imports for the Shared Terms Refusal Helper

* test: Expose the Terms Gate Helper in the JWT Auth Spec Mock

* test: Cover the Terms Refusal Code on Pre-Stream Upload Errors
2026-10-14 17:45:28 +02:00

24 lines
1 KiB
TypeScript

import { QueryKeys, TERMS_NOT_ACCEPTED_CODE } from 'librechat-data-provider';
import type { QueryClient } from '@tanstack/react-query';
/** Reads the stable code from a flat `{ code }` or a nested `{ error: { code } }` response body. */
export function hasTermsRefusal(data: unknown): boolean {
if (data == null || typeof data !== 'object') {
return false;
}
const { code, error } = data as { code?: unknown; error?: { code?: unknown } };
return code === TERMS_NOT_ACCEPTED_CODE || error?.code === TERMS_NOT_ACCEPTED_CODE;
}
/**
* Terms were reset or enabled mid-session: refetching the startup config and the terms status
* activates the acceptance query, which reopens the modal. Returns whether `data` was a refusal.
*/
export function reopenTermsOnRefusal(queryClient: QueryClient, data: unknown): boolean {
if (!hasTermsRefusal(data)) {
return false;
}
void queryClient.invalidateQueries([QueryKeys.startupConfig]);
void queryClient.invalidateQueries([QueryKeys.userTerms]);
return true;
}