Files
openclaw/src/routing/account-lookup.ts
2026-03-22 19:01:52 +00:00

31 lines
1016 B
TypeScript

export function resolveAccountEntry<T>(
accounts: Record<string, T> | undefined,
accountId: string,
): T | undefined {
if (!accounts || typeof accounts !== "object") {
return undefined;
}
if (Object.hasOwn(accounts, accountId)) {
return accounts[accountId];
}
const normalized = accountId.toLowerCase();
const matchKey = Object.keys(accounts).find((key) => key.toLowerCase() === normalized);
return matchKey ? accounts[matchKey] : undefined;
}
export function resolveNormalizedAccountEntry<T>(
accounts: Record<string, T> | undefined,
accountId: string,
normalizeAccountId: (accountId: string) => string,
): T | undefined {
if (!accounts || typeof accounts !== "object") {
return undefined;
}
if (Object.hasOwn(accounts, accountId)) {
return accounts[accountId];
}
const normalized = normalizeAccountId(accountId);
const matchKey = Object.keys(accounts).find((key) => normalizeAccountId(key) === normalized);
return matchKey ? accounts[matchKey] : undefined;
}