refactor: share configured account id helper

This commit is contained in:
Peter Steinberger
2026-04-20 15:21:20 +01:00
parent 0a9edac632
commit f73d8e8d9e
3 changed files with 19 additions and 36 deletions

View File

@@ -0,0 +1,17 @@
/** List normalized configured account ids from a raw channel account record map. */
export function listConfiguredAccountIds(params: {
accounts: Record<string, unknown> | undefined;
normalizeAccountId: (accountId: string) => string;
}): string[] {
if (!params.accounts) {
return [];
}
const ids = new Set<string>();
for (const key of Object.keys(params.accounts)) {
if (!key) {
continue;
}
ids.add(params.normalizeAccountId(key));
}
return [...ids];
}

View File

@@ -17,6 +17,7 @@ export {
normalizeOptionalAccountId,
} from "../routing/session-key.js";
export { normalizeE164, pathExists, resolveUserPath } from "../utils.js";
export { listConfiguredAccountIds } from "./account-configured-ids.js";
/** Resolve an account by id, then fall back to the default account when the primary lacks credentials. */
export function resolveAccountWithDefaultFallback<TAccount>(params: {
@@ -43,21 +44,3 @@ export function resolveAccountWithDefaultFallback<TAccount>(params: {
}
return fallback;
}
/** List normalized configured account ids from a raw channel account record map. */
export function listConfiguredAccountIds(params: {
accounts: Record<string, unknown> | undefined;
normalizeAccountId: (accountId: string) => string;
}): string[] {
if (!params.accounts) {
return [];
}
const ids = new Set<string>();
for (const key of Object.keys(params.accounts)) {
if (!key) {
continue;
}
ids.add(params.normalizeAccountId(key));
}
return [...ids];
}

View File

@@ -1,20 +1,3 @@
export { resolveMergedAccountConfig } from "../channels/plugins/account-helpers.js";
export { resolveNormalizedAccountEntry } from "../routing/account-lookup.js";
/** List normalized configured account ids from a raw channel account record map. */
export function listConfiguredAccountIds(params: {
accounts: Record<string, unknown> | undefined;
normalizeAccountId: (accountId: string) => string;
}): string[] {
if (!params.accounts) {
return [];
}
const ids = new Set<string>();
for (const key of Object.keys(params.accounts)) {
if (!key) {
continue;
}
ids.add(params.normalizeAccountId(key));
}
return [...ids];
}
export { listConfiguredAccountIds } from "./account-configured-ids.js";