
      import { Temporal } from "@js-temporal/polyfill";
      import { URLPattern } from "urlpattern-polyfill";
      globalThis.addEventListener = () => {};
    
import { validateCryptoKey } from "./key-jo5CucF6.js";
import { doubleKnock } from "./http-pgzDkXD0.js";
import { curry } from "es-toolkit";
import { UrlError, createActivityPubRequest, getDocumentLoader, getRemoteDocument, logRequest, validatePublicUrl } from "@fedify/vocab-runtime";
import { getLogger } from "@logtape/logtape";

//#region src/utils/docloader.ts
const logger = getLogger([
	"fedify",
	"utils",
	"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;
		}
		const originalRequest = createActivityPubRequest(url, { userAgent });
		const response = await doubleKnock(originalRequest, identity, {
			specDeterminer,
			log: curry(logRequest)(logger),
			tracerProvider,
			signal: options?.signal
		});
		return getRemoteDocument(url, response, load);
	}
	return load;
}
const _fetchDocumentLoader = getDocumentLoader();
const _fetchDocumentLoader_allowPrivateAddress = getDocumentLoader({ allowPrivateAddress: true });
function fetchDocumentLoader(url, arg = false) {
	const allowPrivateAddress = typeof arg === "boolean" ? arg : false;
	logger.warn("fetchDocumentLoader() function is deprecated.  Use getDocumentLoader() function instead.");
	const loader = allowPrivateAddress ? _fetchDocumentLoader_allowPrivateAddress : _fetchDocumentLoader;
	return loader(url);
}

//#endregion
export { fetchDocumentLoader, getAuthenticatedDocumentLoader };