webfinger-handler
Version:
A library that generates a handler for webfinger requests. The created handler works with Node JS HTTP request and response objects, and is otherwise framework agnostic.
118 lines (117 loc) • 3.57 kB
TypeScript
/**
* Webfinger
* @module webfinger-handler
* @see {@link module:webfinger-handler.default}
*/
type DescriptorLinks = {
rel: string;
href: string;
}[];
type Descriptor = {
subject: string;
links: DescriptorLinks;
};
type LookupResult = Descriptor | DescriptorLinks | null;
/**
* Return a JRD descriptor object for agiven acct: URI
* @callback getDescriptor
* @async
* @param {AcctUri} resource The acct: URI of the requested resource
* @returns Either: a JRD descriptor object, a JRD links array, or null if no resource was found
*/
type GetDescriptor = (acct: AcctUri) => LookupResult | Promise<LookupResult>;
/**
* Create a handler for incoming webfinger requests
* @param {getDescriptor} getDescriptor Returns a JSON Resource Descriptor object
* @returns {webfingerHandler} Method for handling webifinger requests
*/
export default class WebfingerHandler {
#private;
constructor(desc: GetDescriptor);
/**
* Webfinger handler
* @async
* @param {IncomingMessage} req The incomming HTTP request
* @param {OutgoingMessage} res The outgoing HTTP response
* @returns {Boolean} True if the request was handled, false if the request path did not match the webfinger endpoint
*/
handle(req: Req, res: Res): Promise<boolean>;
static activitypubResponse: typeof activitypubResponse;
}
/**
* An object representing an acct: URI
*/
export declare class AcctUri {
user: string;
host: string;
/**
* Construct an instance of AcctUri
* @param {Object} options The properties to set on the AcctUri instance
* @param {string} user The user part of the account name
* @param {string} host The hostname part of the account name
*/
constructor(user: string, host: string);
/**
* Parse a string into an AcctUri object
* @param {string} resource An acct: URI
* @returns {AcctUri}
*/
static parse(resource: string | null): AcctUri;
/**
* The scheme of the URI. This is always `acct:`.
*/
get scheme(): string;
/**
* Alias for `user`
*/
get userpart(): string;
/**
* The account string
* Made of the user and host concatenated with the `@` symbol
*/
get account(): string;
/**
* The full URI including the scheme
*/
get uri(): string;
toString(): string;
}
export declare const endpoint = "/.well-known/webfinger";
/**
* Incoming http request
* @external IncomingMessage
* @see {@link https://nodejs.org/api/http.html#http_class_http_incomingmessage}
*/
type Req = {
url?: string;
method?: string;
};
/**
* Outgoing http response
* @external OutgoingMessage
* @see {@link https://nodejs.org/api/http.html#http_class_http_incomingmessage}
*/
type Res = {
setHeader(k: string, v: string): unknown;
statusCode: number;
statusMessage: string;
end(msg: string): unknown;
};
/**
* Get a link for an activitypub actor
* @callback getActorLink
* @async
* @param {AcctUri} resource The acct: uri of the resource to fetch for
* @returns {(string|object)} Either the href of the actor, or the JRD link representation of the actor
*/
/**
* Generates a getDescriptor method specifically for activitypub resource
* @param {getActorLink} getActivitypubLink Method that returns an href representing an activitypub actor
* @returns {getDescriptor} Method that can be used as the Webfinger descriptor getter
*/
export declare function activitypubResponse(href: string): {
rel: string;
type: string;
href: string;
}[];
export {};