import "@js-temporal/polyfill";
import "urlpattern-polyfill";
globalThis.addEventListener = () => {};
import { $ as UrlError, K as createRequest, Q as logRequest, Y as getRemoteDocument, rt as validatePublicUrl } from "./vocab-C5EUmVTj.mjs";
import { a as validateCryptoKey } from "./key-CvS3OKm_.mjs";
import { n as doubleKnock } from "./http-B7ppDy7F.mjs";
import { getLogger } from "@logtape/logtape";
//#region src/runtime/authdocloader.ts
const logger = getLogger([
	"fedify",
	"runtime",
	"docloader"
]);
/**
* Gets an authenticated {@link DocumentLoader} for the given identity.
* Note that an authenticated document loader intentionally does not cache
* the fetched documents.
* @param identity The identity to get the document loader for.
*                 The actor's key pair.
* @param options The options for the document loader.
* @returns The authenticated document loader.
* @throws {TypeError} If the key is invalid or unsupported.
* @since 0.4.0
*/
function getAuthenticatedDocumentLoader(identity, { allowPrivateAddress, userAgent, specDeterminer, tracerProvider } = {}) {
	validateCryptoKey(identity.privateKey);
	async function load(url, options) {
		if (!allowPrivateAddress) try {
			await validatePublicUrl(url);
		} catch (error) {
			if (error instanceof UrlError) logger.error("Disallowed private URL: {url}", {
				url,
				error
			});
			throw error;
		}
		return getRemoteDocument(url, await doubleKnock(createRequest(url, { userAgent }), identity, {
			specDeterminer,
			log: logRequest,
			tracerProvider,
			signal: options?.signal
		}), load);
	}
	return load;
}
//#endregion
export { getAuthenticatedDocumentLoader as t };
