Skip to content
← Public packages

@kody/api-research

Research third-party APIs: registry search, provider discovery, OpenAPI summarize, and client scaffold.

src/https.ts

19 lines · 469 B · TypeScript
export function assertHttpsUrl(value: string, label: string): URL {
	let url: URL
	try {
		url = new URL(value)
	} catch {
		throw new Error(`${label} is not a valid URL: ${value}`)
	}
	if (url.protocol !== 'https:') {
		throw new Error(
			`${label} must use https (got ${url.protocol || 'unknown protocol'})`,
		)
	}
	if (url.username || url.password) {
		throw new Error(
			`${label} must not include embedded credentials (username/password)`,
		)
	}
	return url
}