mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-26 07:01:15 +00:00
fix(push): parse APNs relay timeout as strict decimal (#107883)
Co-authored-by: Peter Steinberger <peter@steipete.me>
This commit is contained in:
@@ -107,6 +107,43 @@ describe("push-apns.relay", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.each(["0x1000", "2e4", "2500ms"])(
|
||||
"falls back for non-decimal env timeout %s",
|
||||
(timeoutMs) => {
|
||||
const resolved = resolveApnsRelayConfigFromEnv({
|
||||
OPENCLAW_APNS_RELAY_BASE_URL: "https://relay.example.com",
|
||||
OPENCLAW_APNS_RELAY_TIMEOUT_MS: timeoutMs,
|
||||
} as NodeJS.ProcessEnv);
|
||||
|
||||
expectRelayConfig(resolved, {
|
||||
baseUrl: "https://relay.example.com",
|
||||
timeoutMs: 10_000,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("retains numeric timeout config values", () => {
|
||||
const resolved = resolveApnsRelayConfigFromEnv(
|
||||
{
|
||||
OPENCLAW_APNS_RELAY_BASE_URL: "https://relay.example.com",
|
||||
} as NodeJS.ProcessEnv,
|
||||
{
|
||||
push: {
|
||||
apns: {
|
||||
relay: {
|
||||
timeoutMs: 2500,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expectRelayConfig(resolved, {
|
||||
baseUrl: "https://relay.example.com",
|
||||
timeoutMs: 2500,
|
||||
});
|
||||
});
|
||||
|
||||
it("allows loopback http URLs for alternate truthy env values", () => {
|
||||
const resolved = resolveApnsRelayConfigFromEnv({
|
||||
OPENCLAW_APNS_RELAY_BASE_URL: "http://[::1]:8787",
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
// Sends APNs notifications through the configured relay endpoint.
|
||||
import { URL } from "node:url";
|
||||
import { resolveTimerTimeoutMs } from "@openclaw/normalization-core/number-coercion";
|
||||
import {
|
||||
parseStrictPositiveInteger,
|
||||
resolveTimerTimeoutMs,
|
||||
} from "@openclaw/normalization-core/number-coercion";
|
||||
import {
|
||||
normalizeLowercaseStringOrEmpty,
|
||||
normalizeOptionalString,
|
||||
@@ -83,7 +86,7 @@ function normalizeTimeoutMs(value: string | number | undefined): number {
|
||||
if (raw === undefined || raw === "") {
|
||||
return DEFAULT_APNS_RELAY_TIMEOUT_MS;
|
||||
}
|
||||
const parsed = Number(raw);
|
||||
const parsed = typeof raw === "number" ? raw : parseStrictPositiveInteger(raw);
|
||||
return resolveTimerTimeoutMs(parsed, DEFAULT_APNS_RELAY_TIMEOUT_MS, 1000);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user