mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* feat(desktop): integrate native mobile push delivery and lifecycle * fix(desktop): preserve notification replay policy and review invariants * fix(desktop): correct notification locale namespace and auto-ack tests
38 lines
953 B
TypeScript
38 lines
953 B
TypeScript
export function cleanCloudServiceUrl(
|
|
value: string | undefined,
|
|
allowLoopbackHttp: boolean
|
|
): string | null {
|
|
const trimmed = value?.trim()
|
|
if (!trimmed) {
|
|
return null
|
|
}
|
|
try {
|
|
const parsed = new URL(trimmed)
|
|
const loopbackHost =
|
|
parsed.hostname === '127.0.0.1' ||
|
|
parsed.hostname === 'localhost' ||
|
|
parsed.hostname === '[::1]'
|
|
if (
|
|
parsed.protocol !== 'https:' &&
|
|
!(parsed.protocol === 'http:' && loopbackHost && allowLoopbackHttp)
|
|
) {
|
|
return null
|
|
}
|
|
return parsed.toString().replace(/\/$/, '')
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export function cleanCloudServiceOrigin(
|
|
value: string | undefined,
|
|
allowLoopbackHttp: boolean
|
|
): string | null {
|
|
const cleaned = cleanCloudServiceUrl(value, allowLoopbackHttp)
|
|
if (!cleaned) {
|
|
return null
|
|
}
|
|
const parsed = new URL(cleaned)
|
|
return parsed.pathname === '/' && !parsed.search && !parsed.hash ? parsed.origin : null
|
|
}
|