Skip to content

Commit

Permalink
bsky: fix tests, making courier config optional. fix unread count query.
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Oct 4, 2024
1 parent a603380 commit dd5fb01
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
10 changes: 9 additions & 1 deletion packages/bsky/src/api/app/bsky/notification/registerPush.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { InvalidRequestError } from '@atproto/xrpc-server'
import {
InvalidRequestError,
MethodNotImplementedError,
} from '@atproto/xrpc-server'
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'
import { AppPlatform } from '../../../../proto/courier_pb'
Expand All @@ -7,6 +10,11 @@ export default function (server: Server, ctx: AppContext) {
server.app.bsky.notification.registerPush({
auth: ctx.authVerifier.standard,
handler: async ({ auth, input }) => {
if (!ctx.courierClient) {
throw new MethodNotImplementedError(
'This service is not configured to support push token registration.',
)
}
const { token, platform, serviceDid, appId } = input.body
const did = auth.credentials.iss
if (serviceDid !== auth.credentials.aud) {
Expand Down
2 changes: 1 addition & 1 deletion packages/bsky/src/api/app/bsky/notification/updateSeen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function (server: Server, ctx: AppContext) {
timestamp: Timestamp.fromDate(seenAt),
priority: true,
}),
ctx.courierClient.pushNotifications({
ctx.courierClient?.pushNotifications({
notifications: [
{
id: getNotifId(viewer, seenAt),
Expand Down
3 changes: 1 addition & 2 deletions packages/bsky/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface ServerConfigValues {
bsyncApiKey?: string
bsyncHttpVersion?: '1.1' | '2'
bsyncIgnoreBadTls?: boolean
courierUrl: string
courierUrl?: string
courierApiKey?: string
courierHttpVersion?: '1.1' | '2'
courierIgnoreBadTls?: boolean
Expand Down Expand Up @@ -92,7 +92,6 @@ export class ServerConfig {
const bsyncIgnoreBadTls = process.env.BSKY_BSYNC_IGNORE_BAD_TLS === 'true'
assert(bsyncHttpVersion === '1.1' || bsyncHttpVersion === '2')
const courierUrl = process.env.BSKY_COURIER_URL || undefined
assert(courierUrl)
const courierApiKey = process.env.BSKY_COURIER_API_KEY || undefined
const courierHttpVersion = process.env.BSKY_COURIER_HTTP_VERSION || '2'
const courierIgnoreBadTls =
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class AppContext {
signingKey: Keypair
idResolver: IdResolver
bsyncClient: BsyncClient
courierClient: CourierClient
courierClient: CourierClient | undefined
authVerifier: AuthVerifier
featureGates: FeatureGates
},
Expand Down Expand Up @@ -76,7 +76,7 @@ export class AppContext {
return this.opts.bsyncClient
}

get courierClient(): CourierClient {
get courierClient(): CourierClient | undefined {
return this.opts.courierClient
}

Expand Down
2 changes: 1 addition & 1 deletion packages/bsky/src/data-plane/server/routes/notifs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default (db: Database): Partial<ServiceImpl<typeof Service>> => ({
.selectFrom('follow')
.select(sql<boolean>`${true}`.as('val'))
.where('creator', '=', actorDid)
.whereRef('subjectDid', '=', ref('notif.author')),
.whereRef('subjectDid', '=', ref('notification.author')),
),
)
.executeTakeFirst()
Expand Down
18 changes: 10 additions & 8 deletions packages/bsky/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,16 @@ export class BskyAppView {
interceptors: config.bsyncApiKey ? [bsyncAuth(config.bsyncApiKey)] : [],
})

const courierClient = createCourierClient({
baseUrl: config.courierUrl,
httpVersion: config.courierHttpVersion ?? '2',
nodeOptions: { rejectUnauthorized: !config.courierIgnoreBadTls },
interceptors: config.courierApiKey
? [courierAuth(config.courierApiKey)]
: [],
})
const courierClient = config.courierUrl
? createCourierClient({
baseUrl: config.courierUrl,
httpVersion: config.courierHttpVersion ?? '2',
nodeOptions: { rejectUnauthorized: !config.courierIgnoreBadTls },
interceptors: config.courierApiKey
? [courierAuth(config.courierApiKey)]
: [],
})
: undefined

const entrywayJwtPublicKey = config.entrywayJwtPublicKeyHex
? createPublicKeyObject(config.entrywayJwtPublicKeyHex)
Expand Down
1 change: 0 additions & 1 deletion packages/dev-env/src/bsky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class TestBsky {
dataplaneHttpVersion: '1.1',
bsyncUrl: `http://localhost:${bsyncPort}`,
bsyncHttpVersion: '1.1',
courierUrl: 'https://fake.example',
modServiceDid: cfg.modServiceDid ?? 'did:example:invalidMod',
labelsFromIssuerDids: [EXAMPLE_LABELER],
...cfg,
Expand Down

0 comments on commit dd5fb01

Please sign in to comment.