repoint the last AtpAgent statics and drop the dead conversions
Five sites read `AtpAgent.appLabelers`, which the previous commit stopped populating - a silent regression, since an empty static reads as "no authorities" rather than failing. All now read `Client.appLabelers`, the static that is actually configured: - `lib/moderation.ts`'s `isAppLabeler`, which decides whether a labeler is non-removable in the UI; - `preferences/moderation.ts`'s `useMyLabelersQuery`, which seeds the labeler list with the app authorities; - `feed/custom.ts`'s hand-rolled logged-out `getFeed`, which reproduces the header lex would have emitted because the request bypasses the client. `sessionAccountToSession` (the `AtpSessionData` conversion) had no callers left once the bridge agent went, and the age assurance config read - the one standalone `new AtpAgent` the age assurance slice deliberately left behind - moves to the public appview client, which is what it was approximating. That is the last `AtpAgent` in src. What remains of `@atproto/api` in the session layer is types and `BSKY_LABELER_DID`, which S4d owns. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,6 @@ import {
|
|||||||
type AppBskyAgeassuranceDefs,
|
type AppBskyAgeassuranceDefs,
|
||||||
type AppBskyAgeassuranceGetConfig,
|
type AppBskyAgeassuranceGetConfig,
|
||||||
type AppBskyAgeassuranceGetState,
|
type AppBskyAgeassuranceGetState,
|
||||||
AtpAgent,
|
|
||||||
type ChatBskyActorDeclaration,
|
type ChatBskyActorDeclaration,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {type Client} from '@atproto/lex'
|
import {type Client} from '@atproto/lex'
|
||||||
@@ -15,7 +14,6 @@ import {persistQueryClient} from '@tanstack/react-query-persist-client'
|
|||||||
import debounce from 'lodash.debounce'
|
import debounce from 'lodash.debounce'
|
||||||
|
|
||||||
import {networkRetry} from '#/lib/async/retry'
|
import {networkRetry} from '#/lib/async/retry'
|
||||||
import {PUBLIC_BSKY_SERVICE} from '#/lib/constants'
|
|
||||||
import {createPersistedQueryStorage} from '#/lib/persisted-query-storage'
|
import {createPersistedQueryStorage} from '#/lib/persisted-query-storage'
|
||||||
import {getAge} from '#/lib/strings/time'
|
import {getAge} from '#/lib/strings/time'
|
||||||
import {
|
import {
|
||||||
@@ -24,6 +22,7 @@ import {
|
|||||||
} from '#/state/birthdate'
|
} from '#/state/birthdate'
|
||||||
import {fetchActorDeclarationRecord} from '#/state/queries/messages/actor-declaration'
|
import {fetchActorDeclarationRecord} from '#/state/queries/messages/actor-declaration'
|
||||||
import {useAppviewClient, usePdsClient, useSession} from '#/state/session'
|
import {useAppviewClient, usePdsClient, useSession} from '#/state/session'
|
||||||
|
import {getPublicAppviewClient} from '#/state/session/clients'
|
||||||
import {DEVICE_SIGNALS_SUPPORTED} from '#/ageAssurance/const'
|
import {DEVICE_SIGNALS_SUPPORTED} from '#/ageAssurance/const'
|
||||||
import * as debug from '#/ageAssurance/debug'
|
import * as debug from '#/ageAssurance/debug'
|
||||||
import {logger} from '#/ageAssurance/logger'
|
import {logger} from '#/ageAssurance/logger'
|
||||||
@@ -98,11 +97,14 @@ export function setBirthdateForDid({
|
|||||||
export const configQueryKey = ['config']
|
export const configQueryKey = ['config']
|
||||||
export async function getConfig() {
|
export async function getConfig() {
|
||||||
if (debug.enabled) return debug.resolve(debug.config)
|
if (debug.enabled) return debug.resolve(debug.config)
|
||||||
const agent = new AtpAgent({
|
/*
|
||||||
service: PUBLIC_BSKY_SERVICE,
|
* An unauthenticated read against the public appview: the config is fetched
|
||||||
})
|
* before there is any session (and while logged out), so it goes through the
|
||||||
const res = await agent.app.bsky.ageassurance.getConfig()
|
* process-wide public client rather than a bundle one.
|
||||||
return res.data
|
*/
|
||||||
|
return (await getPublicAppviewClient().call(
|
||||||
|
app.bsky.ageassurance.getConfig,
|
||||||
|
)) as AppBskyAgeassuranceGetConfig.OutputSchema
|
||||||
}
|
}
|
||||||
export function getConfigFromCache():
|
export function getConfigFromCache():
|
||||||
| AppBskyAgeassuranceGetConfig.OutputSchema
|
| AppBskyAgeassuranceGetConfig.OutputSchema
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {type AppBskyFeedDefs, AtpAgent, jsonStringToLex} from '@atproto/api'
|
import {type AppBskyFeedDefs, jsonStringToLex} from '@atproto/api'
|
||||||
import {type Client, type XrpcRequestParams} from '@atproto/lex'
|
import {Client, type XrpcRequestParams} from '@atproto/lex'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getAppLanguageAsContentLanguage,
|
getAppLanguageAsContentLanguage,
|
||||||
@@ -115,12 +115,12 @@ async function loggedOutFetch({
|
|||||||
}): Promise<app.bsky.feed.getFeed.$OutputBody | null> {
|
}): Promise<app.bsky.feed.getFeed.$OutputBody | null> {
|
||||||
let contentLangs = getAppLanguageAsContentLanguage()
|
let contentLangs = getAppLanguageAsContentLanguage()
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Copied from our root `Agent` class
|
* This request is hand-rolled rather than issued through a client, so it has
|
||||||
* @see https://github.com/bluesky-social/atproto/blob/60df3fc652b00cdff71dd9235d98a7a4bb828f05/packages/api/src/agent.ts#L120
|
* to reproduce the header lex would have emitted from the global static.
|
||||||
*/
|
*/
|
||||||
const labelersHeader = {
|
const labelersHeader = {
|
||||||
'atproto-accept-labelers': AtpAgent.appLabelers
|
'atproto-accept-labelers': Client.appLabelers
|
||||||
.map(l => `${l};redact`)
|
.map(l => `${l};redact`)
|
||||||
.join(', '),
|
.join(', '),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import {useMemo} from 'react'
|
import {useMemo} from 'react'
|
||||||
import {AtpAgent, type ComAtprotoLabelDefs} from '@atproto/api'
|
import {type ComAtprotoLabelDefs} from '@atproto/api'
|
||||||
|
import {Client} from '@atproto/lex'
|
||||||
|
import {type DidString} from '@atproto/syntax'
|
||||||
import {
|
import {
|
||||||
type InterpretedLabelValueDefinition,
|
type InterpretedLabelValueDefinition,
|
||||||
LABELS,
|
LABELS,
|
||||||
@@ -105,9 +107,9 @@ export function isAppLabeler(
|
|||||||
| app.bsky.labeler.defs.LabelerViewDetailed,
|
| app.bsky.labeler.defs.LabelerViewDetailed,
|
||||||
): boolean {
|
): boolean {
|
||||||
if (typeof labeler === 'string') {
|
if (typeof labeler === 'string') {
|
||||||
return AtpAgent.appLabelers.includes(labeler)
|
return Client.appLabelers.includes(labeler as DidString)
|
||||||
}
|
}
|
||||||
return AtpAgent.appLabelers.includes(labeler.creator.did)
|
return Client.appLabelers.includes(labeler.creator.did)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isLabelerSubscribed(
|
export function isLabelerSubscribed(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {useMemo} from 'react'
|
import {useMemo} from 'react'
|
||||||
import {AtpAgent} from '@atproto/api'
|
import {Client} from '@atproto/lex'
|
||||||
import {interpretLabelValueDefinitions} from '@bsky.app/sdk/moderation'
|
import {interpretLabelValueDefinitions} from '@bsky.app/sdk/moderation'
|
||||||
|
|
||||||
import {isNonConfigurableModerationAuthority} from '#/state/session/additional-moderation-authorities'
|
import {isNonConfigurableModerationAuthority} from '#/state/session/additional-moderation-authorities'
|
||||||
@@ -14,7 +14,7 @@ export function useMyLabelersQuery({
|
|||||||
const prefs = usePreferencesQuery()
|
const prefs = usePreferencesQuery()
|
||||||
let dids = Array.from(
|
let dids = Array.from(
|
||||||
new Set(
|
new Set(
|
||||||
AtpAgent.appLabelers.concat(
|
(Client.appLabelers as readonly string[]).concat(
|
||||||
prefs.data?.moderationPrefs.labelers.map(l => l.did) || [],
|
prefs.data?.moderationPrefs.labelers.map(l => l.did) || [],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import {type AtpSessionData} from '@atproto/api'
|
|
||||||
import {getPdsEndpoint, isValidDidDoc} from '@atproto/common-web'
|
import {getPdsEndpoint, isValidDidDoc} from '@atproto/common-web'
|
||||||
import {type SessionData} from '@atproto/lex-password-session'
|
import {type SessionData} from '@atproto/lex-password-session'
|
||||||
import {jwtDecode} from 'jwt-decode'
|
import {jwtDecode} from 'jwt-decode'
|
||||||
@@ -81,27 +80,6 @@ export function sessionAccountToSessionData(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert a persisted account into data suitable for `AtpAgent`. */
|
|
||||||
export function sessionAccountToSession(
|
|
||||||
account: SessionAccount,
|
|
||||||
): AtpSessionData {
|
|
||||||
return {
|
|
||||||
// Sorted in the same property order as when returned by BskyAgent (alphabetical).
|
|
||||||
accessJwt: account.accessJwt ?? '',
|
|
||||||
did: account.did,
|
|
||||||
email: account.email,
|
|
||||||
emailAuthFactor: account.emailAuthFactor,
|
|
||||||
emailConfirmed: account.emailConfirmed,
|
|
||||||
handle: account.handle,
|
|
||||||
refreshJwt: account.refreshJwt ?? '',
|
|
||||||
/**
|
|
||||||
* @see https://github.com/bluesky-social/atproto/blob/c5d36d5ba2a2c2a5c4f366a5621c06a5608e361e/packages/api/src/agent.ts#L188
|
|
||||||
*/
|
|
||||||
active: account.active ?? true,
|
|
||||||
status: account.status,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isSessionExpired(account: SessionAccount) {
|
export function isSessionExpired(account: SessionAccount) {
|
||||||
return account.accessJwt ? isJwtExpired(account.accessJwt) : true
|
return account.accessJwt ? isJwtExpired(account.accessJwt) : true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user