From 36ba2953333d13a6bbfee21612e48575fb40e8ea Mon Sep 17 00:00:00 2001 From: Daniel Holmgren Date: Thu, 14 Sep 2023 13:55:12 -0500 Subject: [PATCH] Remove appview proxy runtime flags (#1590) * remove appview proxy runtime flags * clean up proxy tests --- packages/dev-env/src/bin-network.ts | 37 ----------------- packages/pds/package.json | 5 +-- .../api/com/atproto/identity/resolveHandle.ts | 4 +- .../pds/src/api/com/atproto/repo/getRecord.ts | 4 +- .../app-view/api/app/bsky/actor/getProfile.ts | 2 +- .../api/app/bsky/actor/getProfiles.ts | 4 +- .../api/app/bsky/actor/getSuggestions.ts | 4 +- .../api/app/bsky/actor/searchActors.ts | 4 +- .../app/bsky/actor/searchActorsTypeahead.ts | 4 +- .../api/app/bsky/feed/getActorFeeds.ts | 4 +- .../api/app/bsky/feed/getActorLikes.ts | 2 +- .../api/app/bsky/feed/getAuthorFeed.ts | 2 +- .../src/app-view/api/app/bsky/feed/getFeed.ts | 4 +- .../api/app/bsky/feed/getFeedGenerator.ts | 4 +- .../api/app/bsky/feed/getFeedGenerators.ts | 4 +- .../app-view/api/app/bsky/feed/getLikes.ts | 4 +- .../api/app/bsky/feed/getPostThread.ts | 4 +- .../app-view/api/app/bsky/feed/getPosts.ts | 4 +- .../api/app/bsky/feed/getRepostedBy.ts | 4 +- .../app-view/api/app/bsky/feed/getTimeline.ts | 4 +- .../app-view/api/app/bsky/graph/getBlocks.ts | 4 +- .../api/app/bsky/graph/getFollowers.ts | 2 +- .../app-view/api/app/bsky/graph/getFollows.ts | 2 +- .../app-view/api/app/bsky/graph/getList.ts | 4 +- .../api/app/bsky/graph/getListMutes.ts | 4 +- .../app-view/api/app/bsky/graph/getLists.ts | 4 +- .../app-view/api/app/bsky/graph/getMutes.ts | 4 +- .../app/bsky/notification/getUnreadCount.ts | 4 +- .../bsky/notification/listNotifications.ts | 4 +- .../src/app-view/api/app/bsky/unspecced.ts | 4 +- packages/pds/src/context.ts | 17 +------- packages/pds/src/runtime-flags.ts | 41 +------------------ packages/pds/tests/proxied/admin.test.ts | 26 ------------ pnpm-lock.yaml | 9 +--- 34 files changed, 57 insertions(+), 180 deletions(-) diff --git a/packages/dev-env/src/bin-network.ts b/packages/dev-env/src/bin-network.ts index c0fe110fabd..193c7ea968a 100644 --- a/packages/dev-env/src/bin-network.ts +++ b/packages/dev-env/src/bin-network.ts @@ -24,7 +24,6 @@ const run = async () => { }, plc: { port: 2582 }, }) - await enableProxy(network) await generateMockSetup(network) console.log( @@ -40,39 +39,3 @@ const run = async () => { } run() - -// @TODO remove once we remove proxy runtime flags -const enableProxy = async (network: TestNetwork) => { - const flags = [ - 'appview-proxy:app.bsky.feed.getAuthorFeed', - 'appview-proxy:app.bsky.graph.getFollowers', - 'appview-proxy:app.bsky.feed.getPosts', - 'appview-proxy:app.bsky.graph.getFollows', - 'appview-proxy:app.bsky.feed.getLikes', - 'appview-proxy:app.bsky.feed.getRepostedBy', - 'appview-proxy:app.bsky.feed.getPostThread', - 'appview-proxy:app.bsky.actor.getProfile', - 'appview-proxy:app.bsky.actor.getProfiles', - 'appview-proxy:app.bsky.feed.getTimeline', - 'appview-proxy:app.bsky.feed.getSuggestions', - 'appview-proxy:app.bsky.feed.getFeed', - 'appview-proxy:app.bsky.feed.getActorFeeds', - 'appview-proxy:app.bsky.feed.getActorLikes', - 'appview-proxy:app.bsky.feed.getFeedGenerator', - 'appview-proxy:app.bsky.feed.getFeedGenerators', - 'appview-proxy:app.bsky.feed.getBlocks', - 'appview-proxy:app.bsky.feed.getList', - 'appview-proxy:app.bsky.notification.listNotifications', - 'appview-proxy:app.bsky.feed.getLists', - 'appview-proxy:app.bsky.feed.getListMutes', - 'appview-proxy:com.atproto.repo.getRecord', - 'appview-proxy:com.atproto.identity.resolveHandle', - 'appview-proxy:app.bsky.notification.getUnreadCount', - 'appview-proxy:app.bsky.actor.searchActorsTypeahead', - 'appview-proxy:app.bsky.actor.searchActors', - ] - await network.pds.ctx.db.db - .insertInto('runtime_flag') - .values(flags.map((name) => ({ name, value: '10' }))) - .execute() -} diff --git a/packages/pds/package.json b/packages/pds/package.json index 488088942d6..8803b6409ee 100644 --- a/packages/pds/package.json +++ b/packages/pds/package.json @@ -30,10 +30,10 @@ "@atproto/api": "workspace:^", "@atproto/common": "workspace:^", "@atproto/crypto": "workspace:^", - "@atproto/syntax": "workspace:^", "@atproto/identity": "workspace:^", "@atproto/lexicon": "workspace:^", "@atproto/repo": "workspace:^", + "@atproto/syntax": "workspace:^", "@atproto/xrpc": "workspace:^", "@atproto/xrpc-server": "workspace:^", "@did-plc/lib": "^0.0.1", @@ -53,7 +53,6 @@ "iso-datestring-validator": "^2.2.2", "jsonwebtoken": "^8.5.1", "kysely": "^0.22.0", - "lru-cache": "^10.0.1", "multiformats": "^9.9.0", "nodemailer": "^6.8.0", "nodemailer-html-to-text": "^3.2.0", @@ -67,9 +66,9 @@ "zod": "^3.21.4" }, "devDependencies": { + "@atproto/api": "workspace:^", "@atproto/bsky": "workspace:^", "@atproto/dev-env": "workspace:^", - "@atproto/api": "workspace:^", "@atproto/lex-cli": "workspace:^", "@did-plc/server": "^0.0.1", "@types/cors": "^2.8.12", diff --git a/packages/pds/src/api/com/atproto/identity/resolveHandle.ts b/packages/pds/src/api/com/atproto/identity/resolveHandle.ts index a4eead11e22..494287dc096 100644 --- a/packages/pds/src/api/com/atproto/identity/resolveHandle.ts +++ b/packages/pds/src/api/com/atproto/identity/resolveHandle.ts @@ -5,7 +5,7 @@ import { Server } from '../../../../lexicon' import AppContext from '../../../../context' export default function (server: Server, ctx: AppContext) { - server.com.atproto.identity.resolveHandle(async ({ params, req }) => { + server.com.atproto.identity.resolveHandle(async ({ params }) => { let handle: string try { handle = ident.normalizeAndEnsureValidHandle(params.handle) @@ -34,7 +34,7 @@ export default function (server: Server, ctx: AppContext) { // this is not someone on our server, but we help with resolving anyway - if (!did && (await ctx.canProxyRead(req))) { + if (!did && ctx.canProxyRead()) { did = await tryResolveFromAppview(ctx.appviewAgent, handle) } diff --git a/packages/pds/src/api/com/atproto/repo/getRecord.ts b/packages/pds/src/api/com/atproto/repo/getRecord.ts index 2ce83916b32..2d73244b0d9 100644 --- a/packages/pds/src/api/com/atproto/repo/getRecord.ts +++ b/packages/pds/src/api/com/atproto/repo/getRecord.ts @@ -4,7 +4,7 @@ import { Server } from '../../../../lexicon' import AppContext from '../../../../context' export default function (server: Server, ctx: AppContext) { - server.com.atproto.repo.getRecord(async ({ req, params }) => { + server.com.atproto.repo.getRecord(async ({ params }) => { const { repo, collection, rkey, cid } = params const did = await ctx.services.account(ctx.db).getDidForActor(repo) @@ -26,7 +26,7 @@ export default function (server: Server, ctx: AppContext) { } } - if (await ctx.canProxyRead(req)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.com.atproto.repo.getRecord(params) return { encoding: 'application/json', diff --git a/packages/pds/src/app-view/api/app/bsky/actor/getProfile.ts b/packages/pds/src/app-view/api/app/bsky/actor/getProfile.ts index bb4678c36ad..540a8cc3779 100644 --- a/packages/pds/src/app-view/api/app/bsky/actor/getProfile.ts +++ b/packages/pds/src/app-view/api/app/bsky/actor/getProfile.ts @@ -13,7 +13,7 @@ export default function (server: Server, ctx: AppContext) { handler: async ({ req, auth, params }) => { const requester = auth.credentials.type === 'access' ? auth.credentials.did : null - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.actor.getProfile( params, requester diff --git a/packages/pds/src/app-view/api/app/bsky/actor/getProfiles.ts b/packages/pds/src/app-view/api/app/bsky/actor/getProfiles.ts index 966f0b9d10b..0750a6109d7 100644 --- a/packages/pds/src/app-view/api/app/bsky/actor/getProfiles.ts +++ b/packages/pds/src/app-view/api/app/bsky/actor/getProfiles.ts @@ -7,9 +7,9 @@ import { handleReadAfterWrite } from '../util/read-after-write' export default function (server: Server, ctx: AppContext) { server.app.bsky.actor.getProfiles({ auth: ctx.accessVerifier, - handler: async ({ req, auth, params }) => { + handler: async ({ auth, params }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.actor.getProfiles( params, await ctx.serviceAuthHeaders(requester), diff --git a/packages/pds/src/app-view/api/app/bsky/actor/getSuggestions.ts b/packages/pds/src/app-view/api/app/bsky/actor/getSuggestions.ts index 4d58bf4986c..f80110dacb0 100644 --- a/packages/pds/src/app-view/api/app/bsky/actor/getSuggestions.ts +++ b/packages/pds/src/app-view/api/app/bsky/actor/getSuggestions.ts @@ -5,9 +5,9 @@ import { Server } from '../../../../../lexicon' export default function (server: Server, ctx: AppContext) { server.app.bsky.actor.getSuggestions({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.actor.getSuggestions( params, await ctx.serviceAuthHeaders(requester), diff --git a/packages/pds/src/app-view/api/app/bsky/actor/searchActors.ts b/packages/pds/src/app-view/api/app/bsky/actor/searchActors.ts index 7e22848498f..0c1e07c014a 100644 --- a/packages/pds/src/app-view/api/app/bsky/actor/searchActors.ts +++ b/packages/pds/src/app-view/api/app/bsky/actor/searchActors.ts @@ -14,9 +14,9 @@ import { export default function (server: Server, ctx: AppContext) { server.app.bsky.actor.searchActors({ auth: ctx.accessVerifier, - handler: async ({ req, auth, params }) => { + handler: async ({ auth, params }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.actor.searchActors( params, await ctx.serviceAuthHeaders(requester), diff --git a/packages/pds/src/app-view/api/app/bsky/actor/searchActorsTypeahead.ts b/packages/pds/src/app-view/api/app/bsky/actor/searchActorsTypeahead.ts index cc35c5d2a7d..bcc80d6acc3 100644 --- a/packages/pds/src/app-view/api/app/bsky/actor/searchActorsTypeahead.ts +++ b/packages/pds/src/app-view/api/app/bsky/actor/searchActorsTypeahead.ts @@ -12,9 +12,9 @@ import { DidHandle } from '../../../../../db/tables/did-handle' export default function (server: Server, ctx: AppContext) { server.app.bsky.actor.searchActorsTypeahead({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.actor.searchActorsTypeahead( params, diff --git a/packages/pds/src/app-view/api/app/bsky/feed/getActorFeeds.ts b/packages/pds/src/app-view/api/app/bsky/feed/getActorFeeds.ts index 253b31886da..f6ded6d2c0e 100644 --- a/packages/pds/src/app-view/api/app/bsky/feed/getActorFeeds.ts +++ b/packages/pds/src/app-view/api/app/bsky/feed/getActorFeeds.ts @@ -6,9 +6,9 @@ import { InvalidRequestError } from '@atproto/xrpc-server' export default function (server: Server, ctx: AppContext) { server.app.bsky.feed.getActorFeeds({ auth: ctx.accessVerifier, - handler: async ({ req, auth, params }) => { + handler: async ({ auth, params }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.feed.getActorFeeds( params, await ctx.serviceAuthHeaders(requester), diff --git a/packages/pds/src/app-view/api/app/bsky/feed/getActorLikes.ts b/packages/pds/src/app-view/api/app/bsky/feed/getActorLikes.ts index 74f1581db9a..5e67e9c6dcf 100644 --- a/packages/pds/src/app-view/api/app/bsky/feed/getActorLikes.ts +++ b/packages/pds/src/app-view/api/app/bsky/feed/getActorLikes.ts @@ -16,7 +16,7 @@ export default function (server: Server, ctx: AppContext) { const requester = auth.credentials.type === 'access' ? auth.credentials.did : null - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.feed.getActorLikes( params, requester diff --git a/packages/pds/src/app-view/api/app/bsky/feed/getAuthorFeed.ts b/packages/pds/src/app-view/api/app/bsky/feed/getAuthorFeed.ts index 24f511bf99c..7850092dc28 100644 --- a/packages/pds/src/app-view/api/app/bsky/feed/getAuthorFeed.ts +++ b/packages/pds/src/app-view/api/app/bsky/feed/getAuthorFeed.ts @@ -16,7 +16,7 @@ export default function (server: Server, ctx: AppContext) { handler: async ({ req, params, auth }) => { const requester = auth.credentials.type === 'access' ? auth.credentials.did : null - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.feed.getAuthorFeed( params, requester diff --git a/packages/pds/src/app-view/api/app/bsky/feed/getFeed.ts b/packages/pds/src/app-view/api/app/bsky/feed/getFeed.ts index 3ef12fa48c6..5f9eb9d975c 100644 --- a/packages/pds/src/app-view/api/app/bsky/feed/getFeed.ts +++ b/packages/pds/src/app-view/api/app/bsky/feed/getFeed.ts @@ -24,10 +24,10 @@ export default function (server: Server, ctx: AppContext) { server.app.bsky.feed.getFeed({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const { data: feed } = await ctx.appviewAgent.api.app.bsky.feed.getFeedGenerator( { feed: params.feed }, diff --git a/packages/pds/src/app-view/api/app/bsky/feed/getFeedGenerator.ts b/packages/pds/src/app-view/api/app/bsky/feed/getFeedGenerator.ts index b87a2d32e65..66e0cc8fdc5 100644 --- a/packages/pds/src/app-view/api/app/bsky/feed/getFeedGenerator.ts +++ b/packages/pds/src/app-view/api/app/bsky/feed/getFeedGenerator.ts @@ -10,9 +10,9 @@ import AppContext from '../../../../../context' export default function (server: Server, ctx: AppContext) { server.app.bsky.feed.getFeedGenerator({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.feed.getFeedGenerator( params, await ctx.serviceAuthHeaders(requester), diff --git a/packages/pds/src/app-view/api/app/bsky/feed/getFeedGenerators.ts b/packages/pds/src/app-view/api/app/bsky/feed/getFeedGenerators.ts index ed3be795b28..3cf7f8eef11 100644 --- a/packages/pds/src/app-view/api/app/bsky/feed/getFeedGenerators.ts +++ b/packages/pds/src/app-view/api/app/bsky/feed/getFeedGenerators.ts @@ -4,9 +4,9 @@ import AppContext from '../../../../../context' export default function (server: Server, ctx: AppContext) { server.app.bsky.feed.getFeedGenerators({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.feed.getFeedGenerators( params, await ctx.serviceAuthHeaders(requester), diff --git a/packages/pds/src/app-view/api/app/bsky/feed/getLikes.ts b/packages/pds/src/app-view/api/app/bsky/feed/getLikes.ts index ed2a950d866..e6658863bed 100644 --- a/packages/pds/src/app-view/api/app/bsky/feed/getLikes.ts +++ b/packages/pds/src/app-view/api/app/bsky/feed/getLikes.ts @@ -7,9 +7,9 @@ import { notSoftDeletedClause } from '../../../../../db/util' export default function (server: Server, ctx: AppContext) { server.app.bsky.feed.getLikes({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.feed.getLikes( params, await ctx.serviceAuthHeaders(requester), diff --git a/packages/pds/src/app-view/api/app/bsky/feed/getPostThread.ts b/packages/pds/src/app-view/api/app/bsky/feed/getPostThread.ts index 5f570827635..fb5276f2452 100644 --- a/packages/pds/src/app-view/api/app/bsky/feed/getPostThread.ts +++ b/packages/pds/src/app-view/api/app/bsky/feed/getPostThread.ts @@ -49,9 +49,9 @@ export type PostThread = { export default function (server: Server, ctx: AppContext) { server.app.bsky.feed.getPostThread({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { try { const res = await ctx.appviewAgent.api.app.bsky.feed.getPostThread( params, diff --git a/packages/pds/src/app-view/api/app/bsky/feed/getPosts.ts b/packages/pds/src/app-view/api/app/bsky/feed/getPosts.ts index c4265d9c1cd..25bc3d652e4 100644 --- a/packages/pds/src/app-view/api/app/bsky/feed/getPosts.ts +++ b/packages/pds/src/app-view/api/app/bsky/feed/getPosts.ts @@ -6,9 +6,9 @@ import { PostView } from '../../../../../lexicon/types/app/bsky/feed/defs' export default function (server: Server, ctx: AppContext) { server.app.bsky.feed.getPosts({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.feed.getPosts( params, await ctx.serviceAuthHeaders(requester), diff --git a/packages/pds/src/app-view/api/app/bsky/feed/getRepostedBy.ts b/packages/pds/src/app-view/api/app/bsky/feed/getRepostedBy.ts index 7b713e8a8a9..f00f9a1a2b5 100644 --- a/packages/pds/src/app-view/api/app/bsky/feed/getRepostedBy.ts +++ b/packages/pds/src/app-view/api/app/bsky/feed/getRepostedBy.ts @@ -6,9 +6,9 @@ import { notSoftDeletedClause } from '../../../../../db/util' export default function (server: Server, ctx: AppContext) { server.app.bsky.feed.getRepostedBy({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.feed.getRepostedBy( params, await ctx.serviceAuthHeaders(requester), diff --git a/packages/pds/src/app-view/api/app/bsky/feed/getTimeline.ts b/packages/pds/src/app-view/api/app/bsky/feed/getTimeline.ts index 26778c4b4a4..5b1e29168a1 100644 --- a/packages/pds/src/app-view/api/app/bsky/feed/getTimeline.ts +++ b/packages/pds/src/app-view/api/app/bsky/feed/getTimeline.ts @@ -12,14 +12,14 @@ import { LocalRecords } from '../../../../../services/local' export default function (server: Server, ctx: AppContext) { server.app.bsky.feed.getTimeline({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did const { algorithm, limit, cursor } = params if (algorithm && algorithm !== FeedAlgorithm.ReverseChronological) { throw new InvalidRequestError(`Unsupported algorithm: ${algorithm}`) } - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.feed.getTimeline( params, await ctx.serviceAuthHeaders(requester), diff --git a/packages/pds/src/app-view/api/app/bsky/graph/getBlocks.ts b/packages/pds/src/app-view/api/app/bsky/graph/getBlocks.ts index 100331d0226..11acf6352a5 100644 --- a/packages/pds/src/app-view/api/app/bsky/graph/getBlocks.ts +++ b/packages/pds/src/app-view/api/app/bsky/graph/getBlocks.ts @@ -6,9 +6,9 @@ import { notSoftDeletedClause } from '../../../../../db/util' export default function (server: Server, ctx: AppContext) { server.app.bsky.graph.getBlocks({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.graph.getBlocks( params, await ctx.serviceAuthHeaders(requester), diff --git a/packages/pds/src/app-view/api/app/bsky/graph/getFollowers.ts b/packages/pds/src/app-view/api/app/bsky/graph/getFollowers.ts index b14d11c3ac6..73a38e83df2 100644 --- a/packages/pds/src/app-view/api/app/bsky/graph/getFollowers.ts +++ b/packages/pds/src/app-view/api/app/bsky/graph/getFollowers.ts @@ -11,7 +11,7 @@ export default function (server: Server, ctx: AppContext) { handler: async ({ req, params, auth }) => { const requester = auth.credentials.type === 'access' ? auth.credentials.did : null - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.graph.getFollowers( params, requester diff --git a/packages/pds/src/app-view/api/app/bsky/graph/getFollows.ts b/packages/pds/src/app-view/api/app/bsky/graph/getFollows.ts index 82e9acee29f..3ebd47f6210 100644 --- a/packages/pds/src/app-view/api/app/bsky/graph/getFollows.ts +++ b/packages/pds/src/app-view/api/app/bsky/graph/getFollows.ts @@ -11,7 +11,7 @@ export default function (server: Server, ctx: AppContext) { handler: async ({ req, params, auth }) => { const requester = auth.credentials.type === 'access' ? auth.credentials.did : null - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.graph.getFollows( params, requester diff --git a/packages/pds/src/app-view/api/app/bsky/graph/getList.ts b/packages/pds/src/app-view/api/app/bsky/graph/getList.ts index e3a925a2101..a7a1556ec18 100644 --- a/packages/pds/src/app-view/api/app/bsky/graph/getList.ts +++ b/packages/pds/src/app-view/api/app/bsky/graph/getList.ts @@ -6,9 +6,9 @@ import AppContext from '../../../../../context' export default function (server: Server, ctx: AppContext) { server.app.bsky.graph.getList({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.graph.getList( params, await ctx.serviceAuthHeaders(requester), diff --git a/packages/pds/src/app-view/api/app/bsky/graph/getListMutes.ts b/packages/pds/src/app-view/api/app/bsky/graph/getListMutes.ts index b3c7905f32a..673b2c61b38 100644 --- a/packages/pds/src/app-view/api/app/bsky/graph/getListMutes.ts +++ b/packages/pds/src/app-view/api/app/bsky/graph/getListMutes.ts @@ -5,9 +5,9 @@ import AppContext from '../../../../../context' export default function (server: Server, ctx: AppContext) { server.app.bsky.graph.getListMutes({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.graph.getListMutes( params, await ctx.serviceAuthHeaders(requester), diff --git a/packages/pds/src/app-view/api/app/bsky/graph/getLists.ts b/packages/pds/src/app-view/api/app/bsky/graph/getLists.ts index ac27522ead7..c6653726459 100644 --- a/packages/pds/src/app-view/api/app/bsky/graph/getLists.ts +++ b/packages/pds/src/app-view/api/app/bsky/graph/getLists.ts @@ -6,9 +6,9 @@ import AppContext from '../../../../../context' export default function (server: Server, ctx: AppContext) { server.app.bsky.graph.getLists({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.graph.getLists( params, await ctx.serviceAuthHeaders(requester), diff --git a/packages/pds/src/app-view/api/app/bsky/graph/getMutes.ts b/packages/pds/src/app-view/api/app/bsky/graph/getMutes.ts index d8578916811..a082666a968 100644 --- a/packages/pds/src/app-view/api/app/bsky/graph/getMutes.ts +++ b/packages/pds/src/app-view/api/app/bsky/graph/getMutes.ts @@ -6,9 +6,9 @@ import { notSoftDeletedClause } from '../../../../../db/util' export default function (server: Server, ctx: AppContext) { server.app.bsky.graph.getMutes({ auth: ctx.accessVerifier, - handler: async ({ req, auth, params }) => { + handler: async ({ auth, params }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.graph.getMutes( params, await ctx.serviceAuthHeaders(requester), diff --git a/packages/pds/src/app-view/api/app/bsky/notification/getUnreadCount.ts b/packages/pds/src/app-view/api/app/bsky/notification/getUnreadCount.ts index a199f42a299..262cfa06fe0 100644 --- a/packages/pds/src/app-view/api/app/bsky/notification/getUnreadCount.ts +++ b/packages/pds/src/app-view/api/app/bsky/notification/getUnreadCount.ts @@ -6,9 +6,9 @@ import AppContext from '../../../../../context' export default function (server: Server, ctx: AppContext) { server.app.bsky.notification.getUnreadCount({ auth: ctx.accessVerifier, - handler: async ({ req, auth, params }) => { + handler: async ({ auth, params }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.notification.getUnreadCount( params, diff --git a/packages/pds/src/app-view/api/app/bsky/notification/listNotifications.ts b/packages/pds/src/app-view/api/app/bsky/notification/listNotifications.ts index bf688dc25ed..d3e44a90aa2 100644 --- a/packages/pds/src/app-view/api/app/bsky/notification/listNotifications.ts +++ b/packages/pds/src/app-view/api/app/bsky/notification/listNotifications.ts @@ -10,9 +10,9 @@ import { getSelfLabels } from '../../../../services/label' export default function (server: Server, ctx: AppContext) { server.app.bsky.notification.listNotifications({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const res = await ctx.appviewAgent.api.app.bsky.notification.listNotifications( params, diff --git a/packages/pds/src/app-view/api/app/bsky/unspecced.ts b/packages/pds/src/app-view/api/app/bsky/unspecced.ts index e50758dbb7a..c500f2cb6b9 100644 --- a/packages/pds/src/app-view/api/app/bsky/unspecced.ts +++ b/packages/pds/src/app-view/api/app/bsky/unspecced.ts @@ -25,9 +25,9 @@ const NSFW_LABELS = ['porn', 'sexual', 'nudity', 'underwear'] export default function (server: Server, ctx: AppContext) { server.app.bsky.unspecced.getPopular({ auth: ctx.accessVerifier, - handler: async ({ req, params, auth }) => { + handler: async ({ params, auth }) => { const requester = auth.credentials.did - if (await ctx.canProxyRead(req, requester)) { + if (ctx.canProxyRead()) { const hotClassicUri = Object.keys(ctx.algos).find((uri) => uri.endsWith('/hot-classic'), ) diff --git a/packages/pds/src/context.ts b/packages/pds/src/context.ts index ca57730504b..1f414845ea1 100644 --- a/packages/pds/src/context.ts +++ b/packages/pds/src/context.ts @@ -191,24 +191,11 @@ export class AppContext { return this.opts.appviewAgent } - async canProxyRead( - req: express.Request, - did?: string | null, - ): Promise { + canProxyRead(): boolean { if (!this.cfg.bskyAppViewProxy || !this.cfg.bskyAppViewEndpoint) { return false } - if (req.get('x-appview-proxy') !== undefined) { - return true - } - // e.g. /xrpc/a.b.c.d/ -> a.b.c.d/ -> a.b.c.d - const endpoint = req.path.replace('/xrpc/', '').replaceAll('/', '') - if (!did) { - // when no did assigned, only proxy reads if threshold is at max of 10 - const threshold = this.runtimeFlags.appviewProxy.getThreshold(endpoint) - return threshold === 10 - } - return await this.runtimeFlags.appviewProxy.shouldProxy(endpoint, did) + return true } canProxyFeedConstruction(req: express.Request): boolean { diff --git a/packages/pds/src/runtime-flags.ts b/packages/pds/src/runtime-flags.ts index 052ed4973f6..b4c3437d1f9 100644 --- a/packages/pds/src/runtime-flags.ts +++ b/packages/pds/src/runtime-flags.ts @@ -1,18 +1,13 @@ import { BailableWait, bailableWait } from '@atproto/common' -import { randomIntFromSeed } from '@atproto/crypto' -import { LRUCache } from 'lru-cache' import Database from './db' import { dbLogger as log } from './logger' -type AppviewProxyFlagName = `appview-proxy:${string}` - -export type FlagName = AppviewProxyFlagName +export type FlagName = '' export class RuntimeFlags { destroyed = false private flags = new Map() private pollWait: BailableWait | undefined = undefined - public appviewProxy = new AppviewProxyFlags(this) constructor(public db: Database) {} @@ -54,37 +49,3 @@ export class RuntimeFlags { this.poll() } } - -class AppviewProxyFlags { - private partitionCache = new LRUCache({ - max: 50000, - fetchMethod(did: string) { - return randomIntFromSeed(did, 10) - }, - }) - - constructor(private runtimeFlags: RuntimeFlags) {} - - getThreshold(endpoint: string) { - const val = this.runtimeFlags.get(`appview-proxy:${endpoint}`) || '0' - const threshold = parseInt(val, 10) - return appviewFlagIsValid(threshold) ? threshold : 0 - } - - async shouldProxy(endpoint: string, did: string) { - const threshold = this.getThreshold(endpoint) - if (threshold === 0) { - return false - } - if (threshold === 10) { - return true - } - // threshold is 0 to 10 inclusive, partitions are 0 to 9 inclusive. - const partition = await this.partitionCache.fetch(did) - return partition !== undefined && partition < threshold - } -} - -const appviewFlagIsValid = (val: number) => { - return 0 <= val && val <= 10 -} diff --git a/packages/pds/tests/proxied/admin.test.ts b/packages/pds/tests/proxied/admin.test.ts index d02e531203f..127717225a6 100644 --- a/packages/pds/tests/proxied/admin.test.ts +++ b/packages/pds/tests/proxied/admin.test.ts @@ -267,19 +267,12 @@ describe('proxies admin requests', () => { }, ) // check profile and labels - const tryGetProfilePds = agent.api.app.bsky.actor.getProfile( - { actor: sc.dids.alice }, - { headers: sc.getHeaders(sc.dids.carol) }, - ) const tryGetProfileAppview = agent.api.app.bsky.actor.getProfile( { actor: sc.dids.alice }, { headers: { ...sc.getHeaders(sc.dids.carol), 'x-appview-proxy': 'true' }, }, ) - await expect(tryGetProfilePds).rejects.toThrow( - 'Account has been taken down', - ) await expect(tryGetProfileAppview).rejects.toThrow( 'Account has been taken down', ) @@ -296,19 +289,12 @@ describe('proxies admin requests', () => { }, ) // check profile and labels - const { data: profilePds } = await agent.api.app.bsky.actor.getProfile( - { actor: sc.dids.alice }, - { headers: sc.getHeaders(sc.dids.carol) }, - ) const { data: profileAppview } = await agent.api.app.bsky.actor.getProfile( { actor: sc.dids.alice }, { headers: { ...sc.getHeaders(sc.dids.carol), 'x-appview-proxy': 'true' }, }, ) - expect(profilePds).toEqual( - expect.objectContaining({ did: sc.dids.alice, handle: 'alice.test' }), - ) expect(profileAppview).toEqual( expect.objectContaining({ did: sc.dids.alice, handle: 'alice.test' }), ) @@ -342,17 +328,12 @@ describe('proxies admin requests', () => { }, ) // check thread and labels - const tryGetPostPds = agent.api.app.bsky.feed.getPostThread( - { uri: post.ref.uriStr, depth: 0 }, - { headers: sc.getHeaders(sc.dids.carol) }, - ) const tryGetPostAppview = agent.api.app.bsky.feed.getPostThread( { uri: post.ref.uriStr, depth: 0 }, { headers: { ...sc.getHeaders(sc.dids.carol), 'x-appview-proxy': 'true' }, }, ) - await expect(tryGetPostPds).rejects.toThrow(NotFoundError) await expect(tryGetPostAppview).rejects.toThrow(NotFoundError) const labelsA = await services.appView .label(db) @@ -367,19 +348,12 @@ describe('proxies admin requests', () => { }, ) // check thread and labels - const { data: threadPds } = await agent.api.app.bsky.feed.getPostThread( - { uri: post.ref.uriStr, depth: 0 }, - { headers: sc.getHeaders(sc.dids.carol) }, - ) const { data: threadAppview } = await agent.api.app.bsky.feed.getPostThread( { uri: post.ref.uriStr, depth: 0 }, { headers: { ...sc.getHeaders(sc.dids.carol), 'x-appview-proxy': 'true' }, }, ) - expect(threadPds.thread.post).toEqual( - expect.objectContaining({ uri: post.ref.uriStr, cid: post.ref.cidStr }), - ) expect(threadAppview.thread.post).toEqual( expect.objectContaining({ uri: post.ref.uriStr, cid: post.ref.cidStr }), ) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1898a37f098..fb80b8c6a35 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -552,9 +552,6 @@ importers: kysely: specifier: ^0.22.0 version: 0.22.0 - lru-cache: - specifier: ^10.0.1 - version: 10.0.1 multiformats: specifier: ^9.9.0 version: 9.9.0 @@ -8998,11 +8995,6 @@ packages: resolution: {integrity: sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==} dev: false - /lru-cache@10.0.1: - resolution: {integrity: sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g==} - engines: {node: 14 || >=16.14} - dev: false - /lru-cache@4.1.5: resolution: {integrity: sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==} dependencies: @@ -10831,6 +10823,7 @@ packages: /tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} + requiresBuild: true dev: false /tsutils@3.21.0(typescript@4.8.4):