Skip to content

Commit

Permalink
Optional service config in pds distribution (#2211)
Browse files Browse the repository at this point in the history
* make appview and mod services optional on pds

* pds: allow configuring a reporting service optionally separate from an administrative mod service

* tidy
  • Loading branch information
devinivy authored Feb 22, 2024
1 parent 4e0271b commit 9f90203
Show file tree
Hide file tree
Showing 60 changed files with 280 additions and 103 deletions.
1 change: 1 addition & 0 deletions packages/pds/src/api/app/bsky/actor/getPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import AppContext from '../../../../context'
import { AuthScope } from '../../../../auth-verifier'

export default function (server: Server, ctx: AppContext) {
if (!ctx.cfg.bskyAppView) return
server.app.bsky.actor.getPreferences({
auth: ctx.authVerifier.access,
handler: async ({ auth }) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/actor/getProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import { pipethrough } from '../../../../pipethrough'
const METHOD_NSID = 'app.bsky.actor.getProfile'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.actor.getProfile({
auth: ctx.authVerifier.accessOrRole,
handler: async ({ req, auth, params }) => {
const requester =
auth.credentials.type === 'access' ? auth.credentials.did : null
const res = await pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
METHOD_NSID,
params,
requester ? await ctx.appviewAuthHeaders(requester) : authPassthru(req),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/actor/getProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import {
const METHOD_NSID = 'app.bsky.actor.getProfiles'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.actor.getProfiles({
auth: ctx.authVerifier.access,
handler: async ({ auth, params }) => {
const requester = auth.credentials.did

const res = await pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
METHOD_NSID,
params,
await ctx.appviewAuthHeaders(requester),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/actor/getSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import AppContext from '../../../../context'
import { pipethrough } from '../../../../pipethrough'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.actor.getSuggestions({
auth: ctx.authVerifier.access,
handler: async ({ params, auth }) => {
const requester = auth.credentials.did
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
'app.bsky.actor.getSuggestions',
params,
await ctx.appviewAuthHeaders(requester),
Expand Down
1 change: 1 addition & 0 deletions packages/pds/src/api/app/bsky/actor/putPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AppContext from '../../../../context'
import { AccountPreference } from '../../../../actor-store/preference/reader'

export default function (server: Server, ctx: AppContext) {
if (!ctx.cfg.bskyAppView) return
server.app.bsky.actor.putPreferences({
auth: ctx.authVerifier.accessCheckTakedown,
handler: async ({ auth, input }) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/actor/searchActors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import AppContext from '../../../../context'
import { pipethrough } from '../../../../pipethrough'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.actor.searchActors({
auth: ctx.authVerifier.access,
handler: async ({ params, auth }) => {
const requester = auth.credentials.did
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
'app.bsky.actor.searchActors',
params,
await ctx.appviewAuthHeaders(requester),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/actor/searchActorsTypeahead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import AppContext from '../../../../context'
import { pipethrough } from '../../../../pipethrough'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.actor.searchActorsTypeahead({
auth: ctx.authVerifier.access,
handler: async ({ params, auth }) => {
const requester = auth.credentials.did
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
'app.bsky.actor.searchActorsTypeahead',
params,
await ctx.appviewAuthHeaders(requester),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/feed/getActorFeeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import AppContext from '../../../../context'
import { pipethrough } from '../../../../pipethrough'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.getActorFeeds({
auth: ctx.authVerifier.access,
handler: async ({ auth, params }) => {
const requester = auth.credentials.did
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
'app.bsky.feed.getActorFeeds',
params,
await ctx.appviewAuthHeaders(requester),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/feed/getActorLikes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import { pipethrough } from '../../../../pipethrough'
const METHOD_NSID = 'app.bsky.feed.getActorLikes'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.getActorLikes({
auth: ctx.authVerifier.accessOrRole,
handler: async ({ req, params, auth }) => {
const requester =
auth.credentials.type === 'access' ? auth.credentials.did : null
const res = await pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
METHOD_NSID,
params,
requester ? await ctx.appviewAuthHeaders(requester) : authPassthru(req),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/feed/getAuthorFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import { pipethrough } from '../../../../pipethrough'
const METHOD_NSID = 'app.bsky.feed.getAuthorFeed'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.getAuthorFeed({
auth: ctx.authVerifier.accessOrRole,
handler: async ({ req, params, auth }) => {
const requester =
auth.credentials.type === 'access' ? auth.credentials.did : null
const res = await pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
METHOD_NSID,
params,
requester ? await ctx.appviewAuthHeaders(requester) : authPassthru(req),
Expand Down
7 changes: 5 additions & 2 deletions packages/pds/src/api/app/bsky/feed/getFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import AppContext from '../../../../context'
import { pipethrough } from '../../../../pipethrough'

export default function (server: Server, ctx: AppContext) {
const { appViewAgent } = ctx
const { bskyAppView } = ctx.cfg
if (!appViewAgent || !bskyAppView) return
server.app.bsky.feed.getFeed({
auth: ctx.authVerifier.access,
handler: async ({ req, params, auth }) => {
const requester = auth.credentials.did

const { data: feed } =
await ctx.appViewAgent.api.app.bsky.feed.getFeedGenerator(
await appViewAgent.api.app.bsky.feed.getFeedGenerator(
{ feed: params.feed },
await ctx.appviewAuthHeaders(requester),
)
Expand All @@ -21,7 +24,7 @@ export default function (server: Server, ctx: AppContext) {
serviceAuthHeaders.headers['accept-language'] =
req.headers['accept-language']
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
'app.bsky.feed.getFeed',
params,
serviceAuthHeaders,
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/feed/getFeedGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import AppContext from '../../../../context'
import { pipethrough } from '../../../../pipethrough'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.getFeedGenerator({
auth: ctx.authVerifier.access,
handler: async ({ params, auth }) => {
const requester = auth.credentials.did
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
'app.bsky.feed.getFeedGenerator',
params,
await ctx.appviewAuthHeaders(requester),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/feed/getFeedGenerators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import AppContext from '../../../../context'
import { pipethrough } from '../../../../pipethrough'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.getFeedGenerators({
auth: ctx.authVerifier.access,
handler: async ({ params, auth }) => {
const requester = auth.credentials.did
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
'app.bsky.feed.getFeedGenerators',
params,
await ctx.appviewAuthHeaders(requester),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/feed/getLikes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import AppContext from '../../../../context'
import { pipethrough } from '../../../../pipethrough'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.getLikes({
auth: ctx.authVerifier.access,
handler: async ({ params, auth }) => {
const requester = auth.credentials.did
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
'app.bsky.feed.getLikes',
params,
await ctx.appviewAuthHeaders(requester),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/feed/getListFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import AppContext from '../../../../context'
import { pipethrough } from '../../../../pipethrough'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.getListFeed({
auth: ctx.authVerifier.access,
handler: async ({ auth, params }) => {
const requester = auth.credentials.did
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
'app.bsky.feed.getListFeed',
params,
await ctx.appviewAuthHeaders(requester),
Expand Down
8 changes: 6 additions & 2 deletions packages/pds/src/api/app/bsky/feed/getPostThread.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from 'node:assert'
import { AtUri } from '@atproto/syntax'
import { Headers, XRPCError } from '@atproto/xrpc'
import { Server } from '../../../../lexicon'
Expand Down Expand Up @@ -26,6 +27,8 @@ import { pipethrough } from '../../../../pipethrough'
const METHOD_NSID = 'app.bsky.feed.getPostThread'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.getPostThread({
auth: ctx.authVerifier.accessOrRole,
handler: async ({ req, params, auth }) => {
Expand All @@ -34,7 +37,7 @@ export default function (server: Server, ctx: AppContext) {

if (!requester) {
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
METHOD_NSID,
params,
authPassthru(req),
Expand All @@ -43,7 +46,7 @@ export default function (server: Server, ctx: AppContext) {

try {
const res = await pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
METHOD_NSID,
params,
await ctx.appviewAuthHeaders(requester),
Expand Down Expand Up @@ -200,6 +203,7 @@ const readAfterWriteNotFound = async (
const highestParent = getHighestParent(thread)
if (highestParent) {
try {
assert(ctx.appViewAgent)
const parentsRes = await ctx.appViewAgent.api.app.bsky.feed.getPostThread(
{ uri: highestParent, parentHeight: params.parentHeight, depth: 0 },
await ctx.appviewAuthHeaders(requester),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/feed/getPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import AppContext from '../../../../context'
import { pipethrough } from '../../../../pipethrough'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.getPosts({
auth: ctx.authVerifier.access,
handler: async ({ params, auth }) => {
const requester = auth.credentials.did
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
'app.bsky.feed.getPosts',
params,
await ctx.appviewAuthHeaders(requester),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/feed/getRepostedBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import AppContext from '../../../../context'
import { pipethrough } from '../../../../pipethrough'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.getRepostedBy({
auth: ctx.authVerifier.access,
handler: async ({ params, auth }) => {
const requester = auth.credentials.did
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
'app.bsky.feed.getRepostedBy',
params,
await ctx.appviewAuthHeaders(requester),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/feed/getSuggestedFeeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import AppContext from '../../../../context'
import { pipethrough } from '../../../../pipethrough'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.getSuggestedFeeds({
auth: ctx.authVerifier.access,
handler: async ({ auth, params }) => {
const requester = auth.credentials.did
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
'app.bsky.feed.getSuggestedFeeds',
params,
await ctx.appviewAuthHeaders(requester),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/feed/getTimeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import { pipethrough } from '../../../../pipethrough'
const METHOD_NSID = 'app.bsky.feed.getTimeline'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.getTimeline({
auth: ctx.authVerifier.access,
handler: async ({ params, auth }) => {
const requester = auth.credentials.did
const res = await pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
METHOD_NSID,
params,
await ctx.appviewAuthHeaders(requester),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/feed/searchPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import AppContext from '../../../../context'
import { pipethrough } from '../../../../pipethrough'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.searchPosts({
auth: ctx.authVerifier.access,
handler: async ({ params, auth }) => {
const requester = auth.credentials.did
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
'app.bsky.feed.searchPosts',
params,
await ctx.appviewAuthHeaders(requester),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/graph/getBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import AppContext from '../../../../context'
import { pipethrough } from '../../../../pipethrough'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.graph.getBlocks({
auth: ctx.authVerifier.access,
handler: async ({ params, auth }) => {
const requester = auth.credentials.did
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
'app.bsky.graph.getBlocks',
params,
await ctx.appviewAuthHeaders(requester),
Expand Down
4 changes: 3 additions & 1 deletion packages/pds/src/api/app/bsky/graph/getFollowers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { authPassthru } from '../../../proxy'
import { pipethrough } from '../../../../pipethrough'

export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.graph.getFollowers({
auth: ctx.authVerifier.accessOrRole,
handler: async ({ req, params, auth }) => {
const requester =
auth.credentials.type === 'access' ? auth.credentials.did : null
return pipethrough(
ctx.cfg.bskyAppView.url,
bskyAppView.url,
'app.bsky.graph.getFollowers',
params,
requester ? await ctx.appviewAuthHeaders(requester) : authPassthru(req),
Expand Down
Loading

0 comments on commit 9f90203

Please sign in to comment.