Skip to content

Commit 2187b19

Browse files
committed
refactor: dedupe extension lowercase helpers
1 parent a44a26f commit 2187b19

17 files changed

Lines changed: 41 additions & 35 deletions

extensions/feishu/src/bot-sender-name.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
12
import { createFeishuClient } from "./client.js";
23
import type { ResolvedFeishuAccount } from "./types.js";
34

@@ -37,7 +38,7 @@ function correctFeishuScopeInUrl(url: string): string {
3738
}
3839

3940
function shouldSuppressPermissionErrorNotice(permissionError: FeishuPermissionError): boolean {
40-
const message = permissionError.message.toLowerCase();
41+
const message = normalizeLowercaseStringOrEmpty(permissionError.message);
4142
return IGNORED_PERMISSION_SCOPE_TOKENS.some((token) => message.includes(token));
4243
}
4344

extensions/feishu/src/monitor.startup.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
12
import type { RuntimeEnv } from "../runtime-api.js";
23
import { probeFeishu } from "./probe.js";
34
import type { ResolvedFeishuAccount } from "./types.js";
@@ -33,13 +34,12 @@ export type FeishuMonitorBotIdentity = {
3334
};
3435

3536
function isTimeoutErrorMessage(message: string | undefined): boolean {
36-
return !!(
37-
message?.toLowerCase().includes("timeout") || message?.toLowerCase().includes("timed out")
38-
);
37+
const lower = normalizeLowercaseStringOrEmpty(message);
38+
return lower.includes("timeout") || lower.includes("timed out");
3939
}
4040

4141
function isAbortErrorMessage(message: string | undefined): boolean {
42-
return message?.toLowerCase().includes("aborted") ?? false;
42+
return normalizeLowercaseStringOrEmpty(message).includes("aborted");
4343
}
4444

4545
export async function fetchBotIdentityForMonitor(

extensions/feishu/src/setup-surface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
type OpenClawConfig,
1313
type SecretInput,
1414
} from "openclaw/plugin-sdk/setup";
15+
import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/text-runtime";
1516
import {
1617
inspectFeishuCredentials,
1718
resolveDefaultFeishuAccountId,
@@ -102,7 +103,7 @@ function isFeishuConfigured(cfg: OpenClawConfig, accountId?: string | null): boo
102103
return false;
103104
}
104105
const rec = value as Record<string, unknown>;
105-
const source = normalizeString(rec.source)?.toLowerCase();
106+
const source = normalizeOptionalLowercaseString(normalizeString(rec.source));
106107
const id = normalizeString(rec.id);
107108
if (source === "env" && id) {
108109
return Boolean(normalizeString(process.env[id]));

extensions/imessage/src/normalize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function normalizeIMessageHandle(raw: string): string {
4747
return "";
4848
}
4949
const value = trimmed.slice(prefix.length).trim();
50-
return `${prefix.toLowerCase()}${value}`;
50+
return `${normalizeLowercaseStringOrEmpty(prefix)}${value}`;
5151
}
5252
if (trimmed.includes("@")) {
5353
return normalizeLowercaseStringOrEmpty(trimmed);

extensions/imessage/src/probe.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { loadConfig } from "openclaw/plugin-sdk/config-runtime";
33
import { runCommandWithTimeout } from "openclaw/plugin-sdk/process-runtime";
44
import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
55
import { detectBinary } from "openclaw/plugin-sdk/setup";
6+
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
67
import { createIMessageRpcClient } from "./client.js";
78
import { DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS } from "./constants.js";
89

@@ -35,7 +36,7 @@ async function probeRpcSupport(cliPath: string, timeoutMs: number): Promise<RpcS
3536
try {
3637
const result = await runCommandWithTimeout([cliPath, "rpc", "--help"], { timeoutMs });
3738
const combined = `${result.stdout}\n${result.stderr}`.trim();
38-
const normalized = combined.toLowerCase();
39+
const normalized = normalizeLowercaseStringOrEmpty(combined);
3940
if (normalized.includes("unknown command") && normalized.includes("rpc")) {
4041
const fatal = {
4142
supported: false,

extensions/imessage/src/test-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function normalizeIMessageTestHandle(raw: string): string {
2121
}
2222
if (/^(chat_id:|chat_guid:|chat_identifier:)/i.test(trimmed)) {
2323
return trimmed.replace(/^(chat_id:|chat_guid:|chat_identifier:)/i, (match) =>
24-
match.toLowerCase(),
24+
normalizeLowercaseStringOrEmpty(match),
2525
);
2626
}
2727
if (trimmed.includes("@")) {

extensions/nextcloud-talk/src/approval-auth.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import {
22
createResolvedApproverActionAuthAdapter,
33
resolveApprovalApprovers,
44
} from "openclaw/plugin-sdk/approval-auth-runtime";
5+
import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/text-runtime";
56
import { resolveNextcloudTalkAccount } from "./accounts.js";
67
import type { CoreConfig } from "./types.js";
78

89
function normalizeNextcloudTalkApproverId(value: string | number): string | undefined {
9-
const normalized = String(value)
10-
.trim()
11-
.replace(/^(nextcloud-talk|nc-talk|nc):/i, "")
12-
.trim()
13-
.toLowerCase();
14-
return normalized || undefined;
10+
return normalizeOptionalLowercaseString(
11+
String(value)
12+
.trim()
13+
.replace(/^(nextcloud-talk|nc-talk|nc):/i, ""),
14+
);
1515
}
1616

1717
export const nextcloudTalkApprovalAuth = createResolvedApproverActionAuthAdapter({

extensions/nextcloud-talk/src/channel.adapters.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ export const nextcloudTalkSecurityAdapter = {
3939
resolveAllowFrom: (account) => account.config.allowFrom,
4040
policyPathSuffix: "dmPolicy",
4141
normalizeEntry: (raw) =>
42-
raw
43-
.trim()
44-
.replace(/^(nextcloud-talk|nc-talk|nc):/i, "")
45-
.trim()
46-
.toLowerCase(),
42+
normalizeLowercaseStringOrEmpty(raw.trim().replace(/^(nextcloud-talk|nc-talk|nc):/i, "")),
4743
}),
4844
};
4945

extensions/nextcloud-talk/src/policy.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { resolveInboundMentionDecision } from "openclaw/plugin-sdk/channel-inbound";
2+
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
23
import type {
34
AllowlistMatch,
45
ChannelGroupContext,
@@ -15,10 +16,7 @@ import {
1516
import type { NextcloudTalkRoomConfig } from "./types.js";
1617

1718
function normalizeAllowEntry(raw: string): string {
18-
return raw
19-
.trim()
20-
.toLowerCase()
21-
.replace(/^(nextcloud-talk|nc-talk|nc):/i, "");
19+
return normalizeLowercaseStringOrEmpty(raw.trim().replace(/^(nextcloud-talk|nc-talk|nc):/i, ""));
2220
}
2321

2422
export function normalizeNextcloudTalkAllowlist(

extensions/nextcloud-talk/src/signature.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createHmac, randomBytes } from "node:crypto";
2+
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
23
import type { NextcloudTalkWebhookHeaders } from "./types.js";
34

45
const SIGNATURE_HEADER = "x-nextcloud-talk-signature";
@@ -41,7 +42,7 @@ export function extractNextcloudTalkHeaders(
4142
headers: Record<string, string | string[] | undefined>,
4243
): NextcloudTalkWebhookHeaders | null {
4344
const getHeader = (name: string): string | undefined => {
44-
const value = headers[name] ?? headers[name.toLowerCase()];
45+
const value = headers[name] ?? headers[normalizeLowercaseStringOrEmpty(name)];
4546
return Array.isArray(value) ? value[0] : value;
4647
};
4748

0 commit comments

Comments
 (0)