From e5be7c2cd48a3e299b9f0f62053c5ce4727b8a0d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 7 Apr 2026 00:05:06 +0100 Subject: [PATCH] refactor: dedupe gateway push string helper --- src/gateway/server-methods/push.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/gateway/server-methods/push.ts b/src/gateway/server-methods/push.ts index 7cdf3125965..62f593dd2e9 100644 --- a/src/gateway/server-methods/push.ts +++ b/src/gateway/server-methods/push.ts @@ -10,16 +10,9 @@ import { } from "../../infra/push-apns.js"; import { ErrorCodes, errorShape, validatePushTestParams } from "../protocol/index.js"; import { respondInvalidParams, respondUnavailableOnThrow } from "./nodes.helpers.js"; +import { normalizeTrimmedString } from "./record-shared.js"; import type { GatewayRequestHandlers } from "./types.js"; -function normalizeOptionalString(value: unknown): string | undefined { - if (typeof value !== "string") { - return undefined; - } - const trimmed = value.trim(); - return trimmed.length > 0 ? trimmed : undefined; -} - export const pushHandlers: GatewayRequestHandlers = { "push.test": async ({ params, respond }) => { if (!validatePushTestParams(params)) { @@ -37,8 +30,8 @@ export const pushHandlers: GatewayRequestHandlers = { return; } - const title = normalizeOptionalString(params.title) ?? "OpenClaw"; - const body = normalizeOptionalString(params.body) ?? `Push test for node ${nodeId}`; + const title = normalizeTrimmedString(params.title) ?? "OpenClaw"; + const body = normalizeTrimmedString(params.body) ?? `Push test for node ${nodeId}`; await respondUnavailableOnThrow(respond, async () => { const registration = await loadApnsRegistration(nodeId);