A context.
Type Parameters
TContextDataProperties
The origin of the federated server, including the scheme (http:// or
https://) and the host (e.g., example.com:8080).
canonicalOrigin: stringThe canonical origin of the federated server, including the scheme
(http:// or https://) and the host (e.g., example.com:8080).
When the associated Federation object does not have any explicit canonical origin, it is the same as the Context.origin.
The host of the federated server, including the hostname
(e.g., example.com) and the port following a colon (e.g., :8080)
if it is not the default port for the scheme.
The hostname of the federated server (e.g., example.com). This is
the same as the host without the port.
data: TContextDataThe user-defined data associated with the context.
tracerProvider: TracerProviderThe OpenTelemetry tracer provider.
meterProvider: MeterProviderThe OpenTelemetry meter provider.
documentLoader: DocumentLoaderThe document loader for loading remote JSON-LD documents.
contextLoader: DocumentLoaderThe context loader for loading remote JSON-LD contexts.
verifyPortableObject: PortableObjectVerifierThe FEP-ef61 portable object policy that this context applies to
portable objects it dereferences. It is verifyPortableObject() with
this context's document loader, context loader, and tracer provider as
defaults, which the options passed to it override.
Since its name is the same as the verifyPortableObject option of
property accessors, lookupObject(), and traverseCollection(), passing
a context as their options applies the policy, e.g.,
await create.getObject(ctx). Objects parsed with a context as options,
such as activities that inboxes receive, and objects that accessors
fetch with a context as options also use it by default for their
property accessors. It never verifies an object by itself being
there: it only applies to objects that are dereferenced.
It is optional only so that custom implementations of this interface keep working; contexts that Fedify creates always have it.
federation: Federation<TContextData>The federation object that this context belongs to.
Methods
clone(data: TContextData): Context<TContextData>Creates a new context with the same properties as this one, but with the given data.
getNodeInfoUri(): URLBuilds the URI of the NodeInfo document.
getActorUri(identifier: string): URLBuilds the URI of an actor with the given identifier.
getPortableActorUri(): URLBuilds the FEP-ef61 portable ID of an actor with the given identifier under the given DID authority.
The path is the same as the one Context.getActorUri builds, but
the result is an ap+ef61: URI whose authority is the DID, e.g.,
ap+ef61://did:key:z6Mk.../users/alice. Such an actor can be served
through the FEP-ef61 gateway endpoint,
/.well-known/apgateway/did:key:z6Mk.../users/alice, by the same actor
dispatcher.
The returned URL keeps the DID authority percent-encoded, because
the URL class cannot represent the canonical form. Use formatIri()
from @fedify/vocab-runtime to get the canonical string, e.g.,
ap+ef61://did:key:z6Mk.../users/alice.
getObjectUri<TObject extends Object>(cls: ConstructorWithTypeId<TObject>,): URLBuilds the URI of an object with the given class and values.
getPortableObjectUri<TObject extends Object>(): URLBuilds the FEP-ef61 portable ID of an object with the given class and values under the given DID authority.
The path is the same as the one Context.getObjectUri builds from
the object dispatcher's path, but the result is an ap+ef61: URI whose
authority is the DID, e.g., ap+ef61://did:key:z6Mk.../notes/123.
Such an object can be served through the FEP-ef61 gateway endpoint,
/.well-known/apgateway/did:key:z6Mk.../notes/123, by the same object
dispatcher.
The returned URL keeps the DID authority percent-encoded, because
the URL class cannot represent the canonical form. Use formatIri()
from @fedify/vocab-runtime to get the canonical string, e.g.,
ap+ef61://did:key:z6Mk.../notes/123.
getPortableInboxUri(): URLBuilds the FEP-ef61 portable ID of an actor's inbox with the given identifier under the given DID authority.
The path is the same as the one Context.getInboxUri builds from
the inbox path, but the result is an ap+ef61: URI whose authority is
the DID, e.g., ap+ef61://did:key:z6Mk.../users/alice/inbox. If
a portable actor has it as its inbox and lists this server in its
gateways, this server accepts deliveries to the inbox through
the FEP-ef61 gateway endpoint, e.g.,
POST /.well-known/apgateway/did:key:z6Mk.../users/alice/inbox, and
dispatches them to the inbox listeners.
The returned URL keeps the DID authority percent-encoded, because
the URL class cannot represent the canonical form. Use formatIri()
from @fedify/vocab-runtime to get the canonical string.
getOutboxUri(identifier: string): URLBuilds the URI of an actor's outbox with the given identifier.
getPortableOutboxUri(): URLBuilds the FEP-ef61 portable ID of an actor's outbox with the given identifier under the given DID authority.
The path is the same as the one Context.getOutboxUri builds, but
the result is an ap+ef61: URI whose authority is the DID, e.g.,
ap+ef61://did:key:z6Mk.../users/alice/outbox. If a portable actor has
it as its outbox and its ID is under the same DID, the collection is
served through the FEP-ef61 gateway endpoint, e.g.,
/.well-known/apgateway/did:key:z6Mk.../users/alice/outbox, by the same
collection dispatcher.
The returned URL keeps the DID authority percent-encoded, because
the URL class cannot represent the canonical form. Use formatIri()
from @fedify/vocab-runtime to get the canonical string.
getMediaUploaderUri(identifier: string): URLBuilds the URI of an actor's media upload endpoint with the given
identifier. This is the endpoint advertised under endpoints.uploadMedia
in the actor document.
getInboxUri(): URLBuilds the URI of the shared inbox.
getInboxUri(identifier: string): URLBuilds the URI of an actor's inbox with the given identifier.
getFollowingUri(identifier: string): URLBuilds the URI of an actor's following collection with the given identifier.
getPortableFollowingUri(): URLBuilds the FEP-ef61 portable ID of an actor's following collection with the given identifier under the given DID authority.
The path is the same as the one Context.getFollowingUri builds, but
the result is an ap+ef61: URI whose authority is the DID, e.g.,
ap+ef61://did:key:z6Mk.../users/alice/following. If a portable actor has
it as its following and its ID is under the same DID, the collection is
served through the FEP-ef61 gateway endpoint, e.g.,
/.well-known/apgateway/did:key:z6Mk.../users/alice/following, by the same
collection dispatcher.
The returned URL keeps the DID authority percent-encoded, because
the URL class cannot represent the canonical form. Use formatIri()
from @fedify/vocab-runtime to get the canonical string.
getFollowersUri(identifier: string): URLBuilds the URI of an actor's followers collection with the given identifier.
getPortableFollowersUri(): URLBuilds the FEP-ef61 portable ID of an actor's followers collection with the given identifier under the given DID authority.
The path is the same as the one Context.getFollowersUri builds, but
the result is an ap+ef61: URI whose authority is the DID, e.g.,
ap+ef61://did:key:z6Mk.../users/alice/followers. If a portable actor has
it as its followers and its ID is under the same DID, the collection is
served through the FEP-ef61 gateway endpoint, e.g.,
/.well-known/apgateway/did:key:z6Mk.../users/alice/followers, by the same
collection dispatcher.
The returned URL keeps the DID authority percent-encoded, because
the URL class cannot represent the canonical form. Use formatIri()
from @fedify/vocab-runtime to get the canonical string.
getLikedUri(identifier: string): URLBuilds the URI of an actor's liked collection with the given identifier.
getPortableLikedUri(): URLBuilds the FEP-ef61 portable ID of an actor's liked collection with the given identifier under the given DID authority.
The path is the same as the one Context.getLikedUri builds, but
the result is an ap+ef61: URI whose authority is the DID, e.g.,
ap+ef61://did:key:z6Mk.../users/alice/liked. If a portable actor has
it as its liked and its ID is under the same DID, the collection is
served through the FEP-ef61 gateway endpoint, e.g.,
/.well-known/apgateway/did:key:z6Mk.../users/alice/liked, by the same
collection dispatcher.
The returned URL keeps the DID authority percent-encoded, because
the URL class cannot represent the canonical form. Use formatIri()
from @fedify/vocab-runtime to get the canonical string.
getFeaturedUri(identifier: string): URLBuilds the URI of an actor's featured collection with the given identifier.
getPortableFeaturedUri(): URLBuilds the FEP-ef61 portable ID of an actor's featured collection with the given identifier under the given DID authority.
The path is the same as the one Context.getFeaturedUri builds, but
the result is an ap+ef61: URI whose authority is the DID, e.g.,
ap+ef61://did:key:z6Mk.../users/alice/featured. If a portable actor has
it as its featured and its ID is under the same DID, the collection is
served through the FEP-ef61 gateway endpoint, e.g.,
/.well-known/apgateway/did:key:z6Mk.../users/alice/featured, by the same
collection dispatcher.
The returned URL keeps the DID authority percent-encoded, because
the URL class cannot represent the canonical form. Use formatIri()
from @fedify/vocab-runtime to get the canonical string.
getFeaturedTagsUri(identifier: string): URLBuilds the URI of an actor's featured tags collection with the given identifier.
getPortableFeaturedTagsUri(): URLBuilds the FEP-ef61 portable ID of an actor's featured tags collection with the given identifier under the given DID authority.
The path is the same as the one Context.getFeaturedTagsUri builds, but
the result is an ap+ef61: URI whose authority is the DID, e.g.,
ap+ef61://did:key:z6Mk.../users/alice/tags. If a portable actor has
it as its featuredTags and its ID is under the same DID, the collection is
served through the FEP-ef61 gateway endpoint, e.g.,
/.well-known/apgateway/did:key:z6Mk.../users/alice/tags, by the same
collection dispatcher.
The returned URL keeps the DID authority percent-encoded, because
the URL class cannot represent the canonical form. Use formatIri()
from @fedify/vocab-runtime to get the canonical string.
parseUri(uri: URL | null,options?: ParseUriOptions): ParseUriResult | nullDetermines the type of the URI and extracts the associated data.
By default, only URIs on this server's origin are recognized. With
the portable option, FEP-ef61 portable IDs, e.g.,
ap+ef61://did:key:z6Mk.../users/alice, and their compatible
identifiers on any gateway, e.g.,
https://example.com/.well-known/apgateway/did:key:z6Mk.../users/alice,
are also recognized by the same paths that the gateway endpoint routes
to the dispatchers, and the result has the DID in its authority
property.
The DID of a portable ID is anyone's to choose, so recognizing it does
not mean that this server hosts anything for the DID. Check that
authority is the DID that the application stores for the actor or
object before acting on it:
const parsed = ctx.parseUri(follow.objectId, { portable: true }); if (parsed?.type !== "actor") return; const user = await getUser(parsed.identifier); if (user == null) return; if (parsed.authority != null && parsed.authority !== user.did) return;
getActorKeyPairs(identifier: string): Promise<ActorKeyPair[]>Gets the key pairs for an actor.
getDocumentLoader(identity: { identifier: string; } | { username: string; }): Promise<DocumentLoader>Gets an authenticated DocumentLoader for the given identity. Note that an authenticated document loader intentionally does not cache the fetched documents.
getDocumentLoader(identity: { keyId: URL; privateKey: CryptoKey; }): DocumentLoaderGets an authenticated DocumentLoader for the given identity. Note that an authenticated document loader intentionally does not cache the fetched documents.
lookupObject(options?: LookupObjectOptions): Promise<Object | null>Looks up an ActivityStreams object by its URI (including acct: URIs)
or a fediverse handle (e.g., @user@server or user@server).
traverseCollection(collection: Collection,options?: TraverseCollectionOptions): AsyncIterable<Object | Link>Traverses a collection, yielding each item in the collection. If the collection is paginated, it will fetch the next page automatically.
lookupNodeInfo(options?: GetNodeInfoOptions & { parse?: "strict" | "best-effort"; }): Promise<NodeInfo | undefined>Fetches the NodeInfo document from the given URL.
lookupNodeInfo(options?: GetNodeInfoOptions & { parse: "none"; }): Promise<JsonValue | undefined>Fetches the NodeInfo document from the given URL.
lookupWebFinger(options?: LookupWebFingerOptions): Promise<ResourceDescriptor | null>Looks up a WebFinger resource.
It's almost the same as the lookupWebFinger function, but it uses the context's configuration by default.
sendActivity(): Promise<void>Sends an activity to recipients' inboxes.
sendActivity(): Promise<void>Sends an activity to the inboxes of the sender's followers.
routeActivity(): Promise<boolean>Manually routes an activity to the appropriate inbox listener.
It is useful for routing an activity that is not received from the network, or for routing an activity that is enclosed in another activity.
Note that the activity will be verified if it has Object Integrity Proofs or is equivalent to the actual remote object. If the activity is not verified, it will be rejected.
enqueueTask<TData>(): Promise<void>Enqueues a custom background task. The payload is validated against the task's schema, serialized, and processed by the task's handler on a background worker.
enqueueTaskMany<TData>(): Promise<void>Enqueues multiple payloads for a custom background task at once. Uses the queue's bulk enqueue operation when available. Without deduplication, it may fall back to parallel single enqueues when the queue does not implement bulk enqueue.
getCollectionUri<TParam extends Record<string, string>>(name: string | symbol,values: TParam): URLBuilds the URI of a collection of objects with the given name and values.
Builds the FEP-ef61 portable ID of a custom collection with the given name and values under the given DID authority.
The path is the same as the one Context.getCollectionUri builds,
but the result is an ap+ef61: URI whose authority is the DID, e.g.,
ap+ef61://did:key:z6Mk.../users/alice/bookmarks. If the collection
dispatcher maps the collection to a portable actor under the same DID
with CustomCollectionCallbackSetters.mapPortableOwner(), the
collection is served through the FEP-ef61 gateway endpoint, e.g.,
/.well-known/apgateway/did:key:z6Mk.../users/alice/bookmarks.
The returned URL keeps the DID authority percent-encoded, because
the URL class cannot represent the canonical form. Use formatIri()
from @fedify/vocab-runtime to get the canonical string.