Loading CHANGES.md +4 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,10 @@ To be released. `DocumentLoaderFactoryOptions` interface. - Added a type parameter `TContextData` to `CreateFederationOptions` interface. - Fedify now assigns a random-generated *http:*/*https:* URI to activities if these do not have explicit `id` properties. This behavior can be disabled by excluding `autoIdAssigner()` from the `CreateFederationOptions.activityTransformers` option. - Introduced `ActivityTransformer`s for adjusting outgoing activities before sending them so that some ActivityPub implementations with quirks Loading src/compat/transformers.test.ts +13 −3 Original line number Diff line number Diff line import { assert } from "@std/assert/assert"; import { assertEquals } from "@std/assert/assert-equals"; import { assertNotEquals } from "@std/assert/assert-not-equals"; import { assertInstanceOf } from "@std/assert/assert-instance-of"; import { MemoryKvStore } from "../federation/kv.ts"; import { FederationImpl } from "../federation/middleware.ts"; import { test } from "../testing/mod.ts"; Loading @@ -21,11 +22,20 @@ test("autoIdAssigner", async () => { }), }); const result = autoIdAssigner(activity, context); assertNotEquals(result.id, null); const { id } = result; assertInstanceOf(id, URL); assertEquals(id.origin, "http://example.com"); assertEquals(id.pathname, "/"); assertEquals(id.search, ""); assert( id.hash.match( /^#Follow\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/, ), ); assertEquals( await result.toJsonLd(), await new Follow({ id: result.id, id, actor: new URL("http://example.com/actors/1"), object: new Person({ id: new URL("http://example.com/actors/2"), Loading src/compat/transformers.ts +9 −4 Original line number Diff line number Diff line Loading @@ -10,11 +10,13 @@ const logger = getLogger(["fedify", "compat", "transformers"]); * does not already have one. This is useful for ensuring that activities * have an ID before they are sent to other servers. * * The generated ID is a URN UUID like: * The generated ID is an origin URI with a fragment which contains an activity * type name with a random UUID: * * ``` * urn:uuid:12345678-1234-5678-1234-567812345678 * https://example.com/#Follow/12345678-1234-5678-1234-567812345678 * ``` * * @typeParam TContextData The type of the context data. * @param activity The activity to assign an ID to. * @param context The context of the activity. Loading @@ -23,10 +25,13 @@ const logger = getLogger(["fedify", "compat", "transformers"]); */ export function autoIdAssigner<TContextData>( activity: Activity, _context: Context<TContextData>, context: Context<TContextData>, ): Activity { if (activity.id != null) return activity; const id = new URL(`urn:uuid:${crypto.randomUUID()}`); const id = new URL( `/#${activity.constructor.name}/${crypto.randomUUID()}`, context.origin, ); logger.warn( "As the activity to send does not have an id, a new id {id} has " + "been generated for it. However, it is recommended to explicitly " + Loading Loading
CHANGES.md +4 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,10 @@ To be released. `DocumentLoaderFactoryOptions` interface. - Added a type parameter `TContextData` to `CreateFederationOptions` interface. - Fedify now assigns a random-generated *http:*/*https:* URI to activities if these do not have explicit `id` properties. This behavior can be disabled by excluding `autoIdAssigner()` from the `CreateFederationOptions.activityTransformers` option. - Introduced `ActivityTransformer`s for adjusting outgoing activities before sending them so that some ActivityPub implementations with quirks Loading
src/compat/transformers.test.ts +13 −3 Original line number Diff line number Diff line import { assert } from "@std/assert/assert"; import { assertEquals } from "@std/assert/assert-equals"; import { assertNotEquals } from "@std/assert/assert-not-equals"; import { assertInstanceOf } from "@std/assert/assert-instance-of"; import { MemoryKvStore } from "../federation/kv.ts"; import { FederationImpl } from "../federation/middleware.ts"; import { test } from "../testing/mod.ts"; Loading @@ -21,11 +22,20 @@ test("autoIdAssigner", async () => { }), }); const result = autoIdAssigner(activity, context); assertNotEquals(result.id, null); const { id } = result; assertInstanceOf(id, URL); assertEquals(id.origin, "http://example.com"); assertEquals(id.pathname, "/"); assertEquals(id.search, ""); assert( id.hash.match( /^#Follow\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/, ), ); assertEquals( await result.toJsonLd(), await new Follow({ id: result.id, id, actor: new URL("http://example.com/actors/1"), object: new Person({ id: new URL("http://example.com/actors/2"), Loading
src/compat/transformers.ts +9 −4 Original line number Diff line number Diff line Loading @@ -10,11 +10,13 @@ const logger = getLogger(["fedify", "compat", "transformers"]); * does not already have one. This is useful for ensuring that activities * have an ID before they are sent to other servers. * * The generated ID is a URN UUID like: * The generated ID is an origin URI with a fragment which contains an activity * type name with a random UUID: * * ``` * urn:uuid:12345678-1234-5678-1234-567812345678 * https://example.com/#Follow/12345678-1234-5678-1234-567812345678 * ``` * * @typeParam TContextData The type of the context data. * @param activity The activity to assign an ID to. * @param context The context of the activity. Loading @@ -23,10 +25,13 @@ const logger = getLogger(["fedify", "compat", "transformers"]); */ export function autoIdAssigner<TContextData>( activity: Activity, _context: Context<TContextData>, context: Context<TContextData>, ): Activity { if (activity.id != null) return activity; const id = new URL(`urn:uuid:${crypto.randomUUID()}`); const id = new URL( `/#${activity.constructor.name}/${crypto.randomUUID()}`, context.origin, ); logger.warn( "As the activity to send does not have an id, a new id {id} has " + "been generated for it. However, it is recommended to explicitly " + Loading