Unverified Commit 1856bfff authored by Hong Minhee's avatar Hong Minhee
Browse files

Activity transformers

parent 66cd7da2
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -22,6 +22,17 @@ To be released.
     -  `GetAuthenticatedDocumentLoaderOptions` interface became to extend
        `DocumentLoaderFactoryOptions` interface.

 -  Introduced `ActivityTransformer`s for adjusting outgoing activities
    before sending them so that some ActivityPub implementations with quirks
    are satisfied.

     -  Added `@fedify/fedify/compat` module.
     -  Added `ActivityTransformer` type.
     -  Added `autoIdAssigner()` function.
     -  Added `actorDehydrator()` function.
     -  Added `defaultActivityTransformers` constant.
     -  Added `CreateFederationOptions.activityTransformers` option.

 -  The `suppressError` option of Activity Vocabulary APIs,
    `traverseCollection()` function, and `Context.traverseCollection()` method
    now suppresses errors occurred JSON-LD processing.
@@ -57,6 +68,11 @@ To be released.

 -  Added `allowPrivateAddress` option to `LookupWebFingerOptions` interface.

 -  Added more log messages using the [LogTape] library.  Currently the below
    logger categories are used:

     -  `["fedify", "compat", "transformers"]`

 -  Added `-t`/`--traverse` option to the `fedify lookup` subcommand.  [[#195]]

 -  Added `-S`/`--suppress-errors` option to the `fedify lookup` subcommand.
+12 −0
Original line number Diff line number Diff line
@@ -328,6 +328,18 @@ the retry policy by providing a custom function that satisfies the `RetryPolicy`
type.  Or you can adjust the parameters of the built-in
`createExponentialBackoffRetryPolicy()` function.

### `activityTransformers`

*This API is available since Fedify 1.4.0.*

Activity transformers are a way to adjust activities before sending them to
the recipients.  It is useful for modifying the activity to fit the recipient's
ActivityPub implementation (which may have some quirks) or for adding some
additional information to the activity.

See the [*Activity transformers* section](./send.md#activity-transformers)
for details.

### `trailingSlashInsensitive`

*This API is available since Fedify 0.12.0.*
+7 −0
Original line number Diff line number Diff line
@@ -138,6 +138,13 @@ Fedify uses the following logger categories:

The `"fedify"` category is used for everything related to the Fedify library.

### `["fedify", "compat", "transformers"]`

*This category is available since Fedify 1.4.0.*

The `["fedify", "compat", "transformers"]` category is used for logging
`ActivityTransformer`-related messages.

### `["fedify", "federation"]`

The `["fedify", "federation"]` category is used for logging federation-related
+80 −3
Original line number Diff line number Diff line
@@ -143,9 +143,9 @@ of the activity. [You can get the actor's URI by calling
the `Context.getActorUri()` method.](./actor.md#constructing-actor-uris)

Every activity should have the `id` property, which is a unique IRI for the
activity.  If you don't specify the `id` property, Fedify automatically
generates a unique IRI for the activity—but it is recommended to specify
the `id` property explicitly.
activity.  If you don't specify the `id` property, [Fedify automatically
generates a unique IRI for the activity by default](#autoidassigner)—but it is
recommended to specify the `id` property explicitly.

> [!TIP]
> The activity's `id` does not have to be necessarily dereferenceable—it's
@@ -567,3 +567,80 @@ equal to the number of Ed25519 key pairs.

[FEP-8b32]: https://w3id.org/fep/8b32
[several other cases]: https://socialhub.activitypub.rocks/t/fep-8b32-object-integrity-proofs/2725/79?u=hongminhee


Activity transformers
---------------------

*This API is available since Fedify 1.4.0.*

Activity transformers are a way to adjust activities before sending them to
the recipients.  It is useful for modifying the activity to fit the recipient's
ActivityPub implementation (which may have some quirks) or for adding some
additional information to the activity.

The activity transformers are applied before they are signed with the sender's
private key and sent to the recipients.

It can be configured by setting
the [`activityTransformers`](./federation.md#activitytransformers) option.
By default, the following activity transformers are enabled:

### `autoIdAssigner()`

This activity transformer automatically assigns a unique IRI to the activity
if the `id` property is not set.  It is useful for ensuring that
the activity has a unique IRI, which is required by the ActivityPub
specification.

The generated IRI is a URN UUID like:

~~~~
urn:uuid:12345678-1234-5678-1234-567812345678
~~~~

### `actorDehydrator()`

This activity transformer <q>dehydrates</q> the `actor` property of the activity
so that it only contains the actor's URI (rather than the full actor object
inlined).  It is useful for satisfying some ActivityPub implementations like
[Threads] that have quirks, which fail to parse the activity if the `actor`
property contains the full actor object inlined.

For example, the following activity:

~~~~ typescript{3-7} twoslash
import { Follow, Person } from "@fedify/fedify";
// ---cut-before---
new Follow({
  id: new URL("http://example.com/activities/1"),
  actor: new Person({
    id: new URL("http://example.com/actors/1"),
    name: "Alice",
    preferredUsername: "alice",
  }),
  object: new Person({
    id: new URL("http://example.com/actors/2"),
    name: "Bob",
    preferredUsername: "bob",
  }),
});
~~~~

is transformed into:

~~~~ typescript twoslash
import { Follow, Person } from "@fedify/fedify";
// ---cut-before---
new Follow({
  id: new URL("http://example.com/activities/1"),
  actor: new URL("http://example.com/actors/1"),  // [!code highlight]
  object: new Person({
    id: new URL("http://example.com/actors/2"),
    name: "Bob",
    preferredUsername: "bob",
  }),
});
~~~~

[Threads]: https://www.threads.net/

src/compat/mod.ts

0 → 100644
+2 −0
Original line number Diff line number Diff line
export * from "./transformers.ts";
export * from "./types.ts";
Loading