@fedify/fedify
Version:
An ActivityPub server framework
125 lines • 4.37 kB
TypeScript
import { type TracerProvider } from "@opentelemetry/api";
import type { GetUserAgentOptions } from "../runtime/docloader.js";
import { Application, Group, Organization, Person, Service } from "./vocab.js";
/**
* Actor types are {@link Object} types that are capable of performing
* activities.
*/
export type Actor = Application | Group | Organization | Person | Service;
/**
* Checks if the given object is an {@link Actor}.
* @param object The object to check.
* @returns `true` if the given object is an {@link Actor}.
*/
export declare function isActor(object: unknown): object is Actor;
/**
* A string representation of an actor type name.
*/
export type ActorTypeName = "Application" | "Group" | "Organization" | "Person" | "Service";
/**
* Gets the type name of the given actor.
* @param actor The actor to get the type name of.
* @returns The type name of the given actor.
*/
export declare function getActorTypeName(actor: Actor): ActorTypeName;
/**
* Gets the actor class by the given type name.
* @param typeName The type name to get the actor class by.
* @returns The actor class by the given type name.
*/
export declare function getActorClassByTypeName(typeName: ActorTypeName): typeof Application | typeof Group | typeof Organization | typeof Person | typeof Service;
/**
* Options for {@link getActorHandle}.
* @since 1.3.0
*/
export interface GetActorHandleOptions extends NormalizeActorHandleOptions {
/**
* 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;
/**
* The OpenTelemetry tracer provider. If omitted, the global tracer provider
* is used.
* @since 1.3.0
*/
tracerProvider?: TracerProvider;
}
/**
* Gets the actor handle, of the form `@username@domain`, from the given actor
* or an actor URI.
*
* @example
* ``` typescript
* // Get the handle of an actor object:
* await getActorHandle(
* new Person({ id: new URL("https://fosstodon.org/users/hongminhee") })
* );
*
* // Get the handle of an actor URI:
* await getActorHandle(new URL("https://fosstodon.org/users/hongminhee"));
* ```
*
* @param actor The actor or actor URI to get the handle from.
* @param options The extra options for getting the actor handle.
* @returns The actor handle. It starts with `@` and is followed by the
* username and domain, separated by `@` by default (it can be
* customized with the options).
* @throws {TypeError} If the actor does not have enough information to get the
* handle.
* @since 0.4.0
*/
export declare function getActorHandle(actor: Actor | URL, options?: GetActorHandleOptions): Promise<`@${string}@${string}` | `${string}@${string}`>;
/**
* Options for {@link normalizeActorHandle}.
* @since 0.9.0
*/
export interface NormalizeActorHandleOptions {
/**
* Whether to trim the leading `@` from the actor handle. Turned off by
* default.
*/
trimLeadingAt?: boolean;
/**
* Whether to convert the domain part of the actor handle to punycode, if it
* is an internationalized domain name. Turned off by default.
*/
punycode?: boolean;
}
/**
* Normalizes the given actor handle.
* @param handle The full handle of the actor to normalize.
* @param options The options for normalizing the actor handle.
* @returns The normalized actor handle.
* @throws {TypeError} If the actor handle is invalid.
* @since 0.9.0
*/
export declare function normalizeActorHandle(handle: string, options?: NormalizeActorHandleOptions): `@${string}@${string}` | `${string}@${string}`;
/**
* The object that can be a recipient of an activity.
*
* Note that every {@link Actor} is also a {@link Recipient}.
*/
export interface Recipient {
/**
* The URI of the actor.
*/
readonly id: URL | null;
/**
* The URI of the actor's inbox.
*/
readonly inboxId: URL | null;
/**
* The endpoints of the actor.
*/
readonly endpoints?: {
/**
* The URI of the actor's shared inbox.
*/
sharedInbox: URL | null;
} | null;
}
//# sourceMappingURL=actor.d.ts.map