refactor: share normalized account lookups

This commit is contained in:
Peter Steinberger
2026-03-22 18:24:20 +00:00
parent 017d295edb
commit d06413e335
10 changed files with 132 additions and 41 deletions

View File

@@ -6,6 +6,29 @@ import { resolveNextcloudTalkAccount } from "./accounts.js";
import type { CoreConfig } from "./types.js";
describe("resolveNextcloudTalkAccount", () => {
it("matches normalized configured account ids", () => {
const account = resolveNextcloudTalkAccount({
cfg: {
channels: {
"nextcloud-talk": {
accounts: {
"Ops Team": {
baseUrl: "https://cloud.example.com",
botSecret: "bot-secret",
},
},
},
},
} as CoreConfig,
accountId: "ops-team",
});
expect(account.accountId).toBe("ops-team");
expect(account.baseUrl).toBe("https://cloud.example.com");
expect(account.secret).toBe("bot-secret");
expect(account.secretSource).toBe("config");
});
it.runIf(process.platform !== "win32")("rejects symlinked botSecretFile paths", () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-nextcloud-talk-"));
const secretFile = path.join(dir, "secret.txt");

View File

@@ -1,4 +1,7 @@
import { mergeAccountConfig } from "openclaw/plugin-sdk/account-resolution";
import {
mergeAccountConfig,
resolveNormalizedAccountEntry,
} from "openclaw/plugin-sdk/account-resolution";
import { tryReadSecretFileSync } from "openclaw/plugin-sdk/infra-runtime";
import {
createAccountListHelpers,
@@ -48,17 +51,13 @@ function resolveAccountConfig(
cfg: CoreConfig,
accountId: string,
): NextcloudTalkAccountConfig | undefined {
const accounts = cfg.channels?.["nextcloud-talk"]?.accounts;
if (!accounts || typeof accounts !== "object") {
return undefined;
}
const direct = accounts[accountId] as NextcloudTalkAccountConfig | undefined;
if (direct) {
return direct;
}
const normalized = normalizeAccountId(accountId);
const matchKey = Object.keys(accounts).find((key) => normalizeAccountId(key) === normalized);
return matchKey ? (accounts[matchKey] as NextcloudTalkAccountConfig | undefined) : undefined;
return resolveNormalizedAccountEntry(
cfg.channels?.["nextcloud-talk"]?.accounts as
| Record<string, NextcloudTalkAccountConfig>
| undefined,
accountId,
normalizeAccountId,
);
}
function mergeNextcloudTalkAccountConfig(