import "@js-temporal/polyfill";
import "urlpattern-polyfill";
import { a as getRemoteDocument, c as logRequest, l as UrlError, n as createRequest, u as validatePublicUrl } from "./docloader-C7Hk8BRD.js";
import { o as validateCryptoKey } from "./key-BHH7odYU.js";
import { t as doubleKnock } from "./http-DOLmvrYy.js";
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 };
