UNPKG

@fedify/fedify

Version:

An ActivityPub server framework

50 lines (49 loc) 1.73 kB
import "@js-temporal/polyfill"; import "urlpattern-polyfill"; globalThis.addEventListener = () => {}; import { o as validateCryptoKey } from "./key-BAQuZEU1.mjs"; import { n as doubleKnock } from "./http-C_edJspG.mjs"; import { curry } from "es-toolkit"; import { UrlError, createActivityPubRequest, 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, maxRedirection, 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(createActivityPubRequest(url, { userAgent }), identity, { maxRedirection, specDeterminer, log: curry(logRequest)(logger), tracerProvider, signal: options?.signal }), load); } return load; } //#endregion export { getAuthenticatedDocumentLoader as t };