Loading backend/README.md +10 −0 Original line number Diff line number Diff line Loading @@ -5,3 +5,13 @@ Built with Prisma, TypeScript and oidc-provider ## Development Move `example.env` to `.env` and edit to your desires ### Development Environment Behavior These all have the prereq of `NODE_ENV = development` | Env var | Example | Purpose | | ------------------------------- | ------- | ----------------------------------------------------------------------------------------- | | `DEV_TRUST_PROXIES` | `true` | Forces proxies to be trusted while still in development (behind ngrok or other dev proxy) | | `DEV_USE_APUB_STUB` | `true` | Use a placeholder implementation of activitypub federation | | `DEV_BYPASS_TOKEN_VERIFICATION` | `true` | Disable verification of tokens | backend/src/__tests__/federation.test.ts +9 −9 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ import { import { AuthSession } from "../controllers/AuthSession.js"; import { openTunnel, Tunnel } from "@hongminhee/localtunnel"; import { Server } from "node:http"; import { type APub as TAPub } from "../lib/apub/utils.js"; import { type APub as TAPub } from "../apub/utils.js"; import { type Federation } from "@fedify/fedify"; import { randomUUID } from "node:crypto"; import { configure, getConsoleSink } from "@logtape/logtape"; Loading Loading @@ -86,7 +86,7 @@ const getTestConfig = async (): Promise<{ typeof entry.auth === "string" && // "label" in entry && typeof entry.label === "string" typeof entry.label === "string", ) ) { return { Loading @@ -106,9 +106,9 @@ let federation: Federation<any>; * These modules may use process.env immediately */ const load = async () => { const lib_express = await import("../lib/express.js"); const lib_apub_utils = await import("../lib/apub/utils.js"); const lib_apub_federation = await import("../lib/apub/federation.js"); const lib_express = await import("../routes/express.js"); const lib_apub_utils = await import("../apub/utils.js"); const lib_apub_federation = await import("../apub/federation.js"); Express = lib_express.app; APub = lib_apub_utils.APub; Loading Loading @@ -137,7 +137,7 @@ beforeAll(async () => { ActiveTunnel = await openTunnel({ port: PORT, service: "localhost.run" }); console.log( `[Prepare] Tunnel localhost:${PORT} -> ${ActiveTunnel.url} (pid: ${ActiveTunnel.pid})` `[Prepare] Tunnel localhost:${PORT} -> ${ActiveTunnel.url} (pid: ${ActiveTunnel.pid})`, ); // modify environment Loading Loading @@ -171,7 +171,7 @@ afterAll(async () => { }); describe.for( TestConfig.accounts.map(({ label, ...account }) => ({ label, account })) TestConfig.accounts.map(({ label, ...account }) => ({ label, account })), )("Deliver to $label", { concurrent: true }, async ({ label, account }) => { let TestKit: FediTestKit; let sessionId: string; Loading @@ -195,7 +195,7 @@ describe.for( if (!DRY_SEND) await TestKit.setup(); }, account.type === "MBIN" ? 60000 : 10000 account.type === "MBIN" ? 60000 : 10000, ); test.sequential("APub#sendDM", async () => { Loading @@ -208,7 +208,7 @@ describe.for( } else { const version = await TestKit.getVersion(); await ctx.annotate( `${label} reports as using version ${account.type} ${version}` `${label} reports as using version ${account.type} ${version}`, ); await TestKit.expectToHave(sessionCode, 1000); } Loading backend/src/lib/apub/federation.ts→backend/src/apub/federation.ts +10 −11 Original line number Diff line number Diff line Loading @@ -16,9 +16,9 @@ import { import { RedisKvStore, RedisMessageQueue } from "@fedify/redis"; import { Redis } from "ioredis"; import { FedifyTransformers } from "./transformers.js"; import { prisma } from "../prisma.js"; import { prisma } from "../lib/prisma.js"; import { APub } from "./utils.js"; import { Handoff } from "../../handoff/index.js"; import { Handoff } from "../handoff/index.js"; // @auth@some.domain export const USER_IDENTIFIER = "auth"; Loading Loading @@ -81,9 +81,8 @@ federation publicKey: await importJwk(publicKey, "public"), }); } else { const { privateKey, publicKey } = await generateCryptoKeyPair( "RSASSA-PKCS1-v1_5" ); const { privateKey, publicKey } = await generateCryptoKeyPair("RSASSA-PKCS1-v1_5"); await prisma.fediverseKeyPair.create({ data: { keyType: "RSASSA-PKCS1-v1_5", Loading Loading @@ -127,7 +126,7 @@ federation new Reject({ actor: follow.objectId, object: follow, }) }), ); }) .on(Create, async (ctx, create) => { Loading Loading @@ -156,7 +155,7 @@ federation.setOutboxDispatcher( return { items: [], }; } }, ); federation.setObjectDispatcher( Loading @@ -173,7 +172,7 @@ federation.setObjectDispatcher( const recipient = await lookupObject( authSession.user_sub, APub.options(ctx) APub.options(ctx), ); const apub = new APub(ctx); Loading @@ -183,7 +182,7 @@ federation.setObjectDispatcher( ...authSession, target: recipient!, }); } }, ); federation.setObjectDispatcher( Loading @@ -200,7 +199,7 @@ federation.setObjectDispatcher( const recipient = await lookupObject( authSession.user_sub, APub.options(ctx) APub.options(ctx), ); const apub = new APub(ctx); Loading @@ -210,5 +209,5 @@ federation.setObjectDispatcher( ...authSession, target: recipient!, }); } }, ); backend/src/lib/apub/transformers.ts→backend/src/apub/transformers.ts +0 −0 File moved. View file backend/src/lib/apub/utils.live.ts→backend/src/apub/utils.live.ts +3 −3 Original line number Diff line number Diff line Loading @@ -14,9 +14,9 @@ import { } from "@fedify/fedify"; import { federation, USER_IDENTIFIER } from "./federation.js"; import { Temporal } from "@js-temporal/polyfill"; import { AuthSession } from "../../controllers/AuthSession.js"; import { IProfile } from "../instance/userMeta.js"; import { getSafeURL } from "../utils.js"; import { AuthSession } from "../controllers/AuthSession.js"; import { IProfile } from "../lib/instance/userMeta.js"; import { getSafeURL } from "../lib/utils.js"; type BuildObjectOpts = { id: string; Loading Loading
backend/README.md +10 −0 Original line number Diff line number Diff line Loading @@ -5,3 +5,13 @@ Built with Prisma, TypeScript and oidc-provider ## Development Move `example.env` to `.env` and edit to your desires ### Development Environment Behavior These all have the prereq of `NODE_ENV = development` | Env var | Example | Purpose | | ------------------------------- | ------- | ----------------------------------------------------------------------------------------- | | `DEV_TRUST_PROXIES` | `true` | Forces proxies to be trusted while still in development (behind ngrok or other dev proxy) | | `DEV_USE_APUB_STUB` | `true` | Use a placeholder implementation of activitypub federation | | `DEV_BYPASS_TOKEN_VERIFICATION` | `true` | Disable verification of tokens |
backend/src/__tests__/federation.test.ts +9 −9 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ import { import { AuthSession } from "../controllers/AuthSession.js"; import { openTunnel, Tunnel } from "@hongminhee/localtunnel"; import { Server } from "node:http"; import { type APub as TAPub } from "../lib/apub/utils.js"; import { type APub as TAPub } from "../apub/utils.js"; import { type Federation } from "@fedify/fedify"; import { randomUUID } from "node:crypto"; import { configure, getConsoleSink } from "@logtape/logtape"; Loading Loading @@ -86,7 +86,7 @@ const getTestConfig = async (): Promise<{ typeof entry.auth === "string" && // "label" in entry && typeof entry.label === "string" typeof entry.label === "string", ) ) { return { Loading @@ -106,9 +106,9 @@ let federation: Federation<any>; * These modules may use process.env immediately */ const load = async () => { const lib_express = await import("../lib/express.js"); const lib_apub_utils = await import("../lib/apub/utils.js"); const lib_apub_federation = await import("../lib/apub/federation.js"); const lib_express = await import("../routes/express.js"); const lib_apub_utils = await import("../apub/utils.js"); const lib_apub_federation = await import("../apub/federation.js"); Express = lib_express.app; APub = lib_apub_utils.APub; Loading Loading @@ -137,7 +137,7 @@ beforeAll(async () => { ActiveTunnel = await openTunnel({ port: PORT, service: "localhost.run" }); console.log( `[Prepare] Tunnel localhost:${PORT} -> ${ActiveTunnel.url} (pid: ${ActiveTunnel.pid})` `[Prepare] Tunnel localhost:${PORT} -> ${ActiveTunnel.url} (pid: ${ActiveTunnel.pid})`, ); // modify environment Loading Loading @@ -171,7 +171,7 @@ afterAll(async () => { }); describe.for( TestConfig.accounts.map(({ label, ...account }) => ({ label, account })) TestConfig.accounts.map(({ label, ...account }) => ({ label, account })), )("Deliver to $label", { concurrent: true }, async ({ label, account }) => { let TestKit: FediTestKit; let sessionId: string; Loading @@ -195,7 +195,7 @@ describe.for( if (!DRY_SEND) await TestKit.setup(); }, account.type === "MBIN" ? 60000 : 10000 account.type === "MBIN" ? 60000 : 10000, ); test.sequential("APub#sendDM", async () => { Loading @@ -208,7 +208,7 @@ describe.for( } else { const version = await TestKit.getVersion(); await ctx.annotate( `${label} reports as using version ${account.type} ${version}` `${label} reports as using version ${account.type} ${version}`, ); await TestKit.expectToHave(sessionCode, 1000); } Loading
backend/src/lib/apub/federation.ts→backend/src/apub/federation.ts +10 −11 Original line number Diff line number Diff line Loading @@ -16,9 +16,9 @@ import { import { RedisKvStore, RedisMessageQueue } from "@fedify/redis"; import { Redis } from "ioredis"; import { FedifyTransformers } from "./transformers.js"; import { prisma } from "../prisma.js"; import { prisma } from "../lib/prisma.js"; import { APub } from "./utils.js"; import { Handoff } from "../../handoff/index.js"; import { Handoff } from "../handoff/index.js"; // @auth@some.domain export const USER_IDENTIFIER = "auth"; Loading Loading @@ -81,9 +81,8 @@ federation publicKey: await importJwk(publicKey, "public"), }); } else { const { privateKey, publicKey } = await generateCryptoKeyPair( "RSASSA-PKCS1-v1_5" ); const { privateKey, publicKey } = await generateCryptoKeyPair("RSASSA-PKCS1-v1_5"); await prisma.fediverseKeyPair.create({ data: { keyType: "RSASSA-PKCS1-v1_5", Loading Loading @@ -127,7 +126,7 @@ federation new Reject({ actor: follow.objectId, object: follow, }) }), ); }) .on(Create, async (ctx, create) => { Loading Loading @@ -156,7 +155,7 @@ federation.setOutboxDispatcher( return { items: [], }; } }, ); federation.setObjectDispatcher( Loading @@ -173,7 +172,7 @@ federation.setObjectDispatcher( const recipient = await lookupObject( authSession.user_sub, APub.options(ctx) APub.options(ctx), ); const apub = new APub(ctx); Loading @@ -183,7 +182,7 @@ federation.setObjectDispatcher( ...authSession, target: recipient!, }); } }, ); federation.setObjectDispatcher( Loading @@ -200,7 +199,7 @@ federation.setObjectDispatcher( const recipient = await lookupObject( authSession.user_sub, APub.options(ctx) APub.options(ctx), ); const apub = new APub(ctx); Loading @@ -210,5 +209,5 @@ federation.setObjectDispatcher( ...authSession, target: recipient!, }); } }, );
backend/src/lib/apub/utils.live.ts→backend/src/apub/utils.live.ts +3 −3 Original line number Diff line number Diff line Loading @@ -14,9 +14,9 @@ import { } from "@fedify/fedify"; import { federation, USER_IDENTIFIER } from "./federation.js"; import { Temporal } from "@js-temporal/polyfill"; import { AuthSession } from "../../controllers/AuthSession.js"; import { IProfile } from "../instance/userMeta.js"; import { getSafeURL } from "../utils.js"; import { AuthSession } from "../controllers/AuthSession.js"; import { IProfile } from "../lib/instance/userMeta.js"; import { getSafeURL } from "../lib/utils.js"; type BuildObjectOpts = { id: string; Loading