refactor: dedupe gateway push string helper

This commit is contained in:
Peter Steinberger
2026-04-07 00:05:06 +01:00
parent f11005de45
commit e5be7c2cd4

View File

@@ -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);