refactor: dedupe feishu string helper

This commit is contained in:
Peter Steinberger
2026-04-07 00:00:24 +01:00
parent bd2ac38c1d
commit ad8341676e
3 changed files with 6 additions and 16 deletions

View File

@@ -7,6 +7,7 @@ import {
resolveMergedAccountConfig,
} from "openclaw/plugin-sdk/account-resolution";
import { coerceSecretRef } from "openclaw/plugin-sdk/provider-auth";
import { normalizeString } from "./comment-shared.js";
import type {
FeishuConfig,
FeishuAccountConfig,
@@ -27,14 +28,6 @@ export { listFeishuAccountIds };
type FeishuCredentialResolutionMode = "inspect" | "strict";
type FeishuResolvedSecretRef = NonNullable<ReturnType<typeof coerceSecretRef>>;
function normalizeString(value: unknown): string | undefined {
if (typeof value !== "string") {
return undefined;
}
const trimmed = value.trim();
return trimmed ? trimmed : undefined;
}
function formatSecretRefLabel(ref: FeishuResolvedSecretRef): string {
return `${ref.source}:${ref.provider}:${ref.id}`;
}

View File

@@ -14,6 +14,10 @@ export function readString(value: unknown): string | undefined {
return typeof value === "string" ? value : undefined;
}
export function normalizeString(value: unknown): string | undefined {
return readString(value)?.trim() || undefined;
}
export function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null;
}

View File

@@ -17,19 +17,12 @@ import {
resolveDefaultFeishuAccountId,
resolveFeishuAccount,
} from "./accounts.js";
import { normalizeString } from "./comment-shared.js";
import { probeFeishu } from "./probe.js";
import type { FeishuAccountConfig, FeishuConfig } from "./types.js";
const channel = "feishu" as const;
function normalizeString(value: unknown): string | undefined {
if (typeof value !== "string") {
return undefined;
}
const trimmed = value.trim();
return trimmed || undefined;
}
type ScopedFeishuConfig = Partial<FeishuConfig> & Partial<FeishuAccountConfig>;
function getScopedFeishuConfig(cfg: OpenClawConfig, accountId: string): ScopedFeishuConfig {