49 lines
1.8 KiB
JavaScript
49 lines
1.8 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Helpers for admin user list free-text search (ID, email hash, name, referral).
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.tryParseUuid = tryParseUuid;
|
|
exports.looksLikeEmail = looksLikeEmail;
|
|
exports.escapeLikePattern = escapeLikePattern;
|
|
exports.classifyAdminUserSearch = classifyAdminUserSearch;
|
|
exports.isUuidPrefix = isUuidPrefix;
|
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
const UUID_HEX32_RE = /^[0-9a-f]{32}$/i;
|
|
const UUID_PREFIX_RE = /^[0-9a-f-]{8,36}$/i;
|
|
/** Normalize braces/case/hyphenless forms into canonical lowercase UUID, or null. */
|
|
function tryParseUuid(term) {
|
|
const cleaned = term.trim().replace(/^\{|\}$/g, '').toLowerCase();
|
|
if (UUID_RE.test(cleaned))
|
|
return cleaned;
|
|
if (UUID_HEX32_RE.test(cleaned)) {
|
|
return `${cleaned.slice(0, 8)}-${cleaned.slice(8, 12)}-${cleaned.slice(12, 16)}-${cleaned.slice(16, 20)}-${cleaned.slice(20)}`;
|
|
}
|
|
return null;
|
|
}
|
|
function looksLikeEmail(term) {
|
|
return term.includes('@') && !/\s/.test(term);
|
|
}
|
|
/** Escape `%` / `_` / `\` for ILIKE / LIKE patterns. */
|
|
function escapeLikePattern(term) {
|
|
return term.replace(/\\/g, '\\\\').replace(/%/g, '\\%').replace(/_/g, '\\_');
|
|
}
|
|
function classifyAdminUserSearch(term) {
|
|
const t = term.trim();
|
|
if (!t)
|
|
return 'general';
|
|
if (tryParseUuid(t))
|
|
return 'uuid';
|
|
if (looksLikeEmail(t))
|
|
return 'email';
|
|
return 'general';
|
|
}
|
|
/** True when the term is a plausible UUID prefix (min 8 hex digits ignoring hyphens). */
|
|
function isUuidPrefix(term) {
|
|
const t = term.trim().toLowerCase();
|
|
if (!UUID_PREFIX_RE.test(t))
|
|
return false;
|
|
const hex = t.replace(/-/g, '');
|
|
return hex.length >= 8 && hex.length < 32 && /^[0-9a-f]+$/.test(hex);
|
|
}
|
|
//# sourceMappingURL=adminUserSearch.js.map
|