@fedify/fedify
Version:
An ActivityPub server framework
94 lines • 4.22 kB
TypeScript
import { type GetUserAgentOptions } from "../runtime/docloader.js";
import type { InboundService, JsonValue, NodeInfo, OutboundService, Protocol, Services, Software, Usage } from "./types.js";
/**
* Options for {@link getNodeInfo} function.
* @since 1.2.0
*/
export interface GetNodeInfoOptions {
/**
* Whether to directly fetch the NodeInfo document from the given URL.
* Otherwise, the NodeInfo document will be fetched from the `.well-known`
* location of the given URL.
*
* Turned off by default.
*/
direct?: boolean;
/**
* How strictly to parse the NodeInfo document.
*
* - `"strict"`: Parse the NodeInfo document strictly. If the document is
* invalid, `undefined` is returned. This is the default.
* - `"best-effort"`: Try to parse the NodeInfo document even if it is
* invalid.
* - `"none"`: Do not parse the NodeInfo document. The function will return
* the raw JSON value.
*/
parse?: "strict" | "best-effort" | "none";
/**
* The options for making `User-Agent` header.
* If a string is given, it is used as the `User-Agent` header value.
* If an object is given, it is passed to {@link getUserAgent} to generate
* the `User-Agent` header value.
* @since 1.3.0
*/
userAgent?: GetUserAgentOptions | string;
}
/**
* Fetches a NodeInfo document from the given URL.
* @param url The base URL of the server. If `options.direct` is turned off
* (default), the NodeInfo document will be fetched from
* the `.well-known` location of this URL (hence the only origin
* of the URL is used). If `options.direct` is turned on,
* the NodeInfo document will be fetched from the given URL.
* @param options Options for fetching the NodeInfo document.
* @returns The NodeInfo document if it could be fetched successfully.
* Otherwise, `undefined` is returned.
* @since 1.2.0
*/
export declare function getNodeInfo(url: URL | string, options?: GetNodeInfoOptions & {
parse?: "strict" | "best-effort";
}): Promise<NodeInfo | undefined>;
/**
* Fetches a NodeInfo document from the given URL.
* @param url The base URL of the server. If `options.direct` is turned off
* (default), the NodeInfo document will be fetched from
* the `.well-known` location of this URL (hence the only origin
* of the URL is used). If `options.direct` is turned on,
* the NodeInfo document will be fetched from the given URL.
* @param options Options for fetching the NodeInfo document.
* @returns The NodeInfo document if it could be fetched successfully.
* Otherwise, `undefined` is returned.
* @since 1.2.0
*/
export declare function getNodeInfo(url: URL | string, options: GetNodeInfoOptions & {
parse: "none";
}): Promise<JsonValue | undefined>;
/**
* Options for {@link parseNodeInfo} function.
* @since 1.2.0
*/
export interface ParseNodeInfoOptions {
/**
* Whether to try to parse the NodeInfo document even if it is invalid.
* If turned on, the function will return a best-effort result.
*
* Turned off by default.
*/
tryBestEffort?: boolean;
}
/**
* Parses a NodeInfo document.
* @param data A JSON value that complies with the NodeInfo schema.
* @param options Options for parsing the NodeInfo document.
* @returns The parsed NodeInfo document if it is valid. Otherwise, `null`
* is returned.
* @since 1.2.0
*/
export declare function parseNodeInfo(data: unknown, options?: ParseNodeInfoOptions): NodeInfo | null;
export declare function parseSoftware(data: unknown, options?: ParseNodeInfoOptions): Software | null;
export declare function parseProtocol(data: unknown): Protocol | null;
export declare function parseServices(data: unknown, options?: ParseNodeInfoOptions): Services | null;
export declare function parseInboundService(data: unknown): InboundService | null;
export declare function parseOutboundService(data: unknown): OutboundService | null;
export declare function parseUsage(data: unknown, options?: ParseNodeInfoOptions): Usage | null;
//# sourceMappingURL=client.d.ts.map