Run codemod for replacing BskyAgent with AtpAgent (#10862)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {BskyAgent} from '@atproto/api'
|
||||
import {AtpAgent} from '@atproto/api'
|
||||
import {describe, expect, it, jest} from '@jest/globals'
|
||||
|
||||
import {agentToSessionAccountOrThrow} from '../agent'
|
||||
@@ -16,7 +16,7 @@ jest.mock('../../../ageAssurance/state', () => ({
|
||||
unsafeGetAndComputeAgeAssurance: () => ({state: {}}),
|
||||
}))
|
||||
jest.mock('#/lib/notifications/notifications', () => ({
|
||||
unregisterPushToken(_agents: BskyAgent[]) {
|
||||
unregisterPushToken(_agents: AtpAgent[]) {
|
||||
return Promise.resolve()
|
||||
},
|
||||
}))
|
||||
@@ -37,7 +37,7 @@ describe('session', () => {
|
||||
}
|
||||
`)
|
||||
|
||||
const agent = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent = new AtpAgent({service: 'https://alice.com'})
|
||||
agent.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -130,7 +130,7 @@ describe('session', () => {
|
||||
it('switches to the latest account, stores all of them', () => {
|
||||
let state = getInitialState([])
|
||||
|
||||
const agent1 = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent1 = new AtpAgent({service: 'https://alice.com'})
|
||||
agent1.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -179,7 +179,7 @@ describe('session', () => {
|
||||
}
|
||||
`)
|
||||
|
||||
const agent2 = new BskyAgent({service: 'https://bob.com'})
|
||||
const agent2 = new AtpAgent({service: 'https://bob.com'})
|
||||
agent2.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'bob-did',
|
||||
@@ -245,7 +245,7 @@ describe('session', () => {
|
||||
}
|
||||
`)
|
||||
|
||||
const agent3 = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent3 = new AtpAgent({service: 'https://alice.com'})
|
||||
agent3.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -311,7 +311,7 @@ describe('session', () => {
|
||||
}
|
||||
`)
|
||||
|
||||
const agent4 = new BskyAgent({service: 'https://jay.com'})
|
||||
const agent4 = new AtpAgent({service: 'https://jay.com'})
|
||||
agent4.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'jay-did',
|
||||
@@ -468,7 +468,7 @@ describe('session', () => {
|
||||
it('can log back in after logging out', () => {
|
||||
let state = getInitialState([])
|
||||
|
||||
const agent1 = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent1 = new AtpAgent({service: 'https://alice.com'})
|
||||
agent1.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -526,7 +526,7 @@ describe('session', () => {
|
||||
}
|
||||
`)
|
||||
|
||||
const agent2 = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent2 = new AtpAgent({service: 'https://alice.com'})
|
||||
agent2.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -578,7 +578,7 @@ describe('session', () => {
|
||||
it('can remove active account', () => {
|
||||
let state = getInitialState([])
|
||||
|
||||
const agent1 = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent1 = new AtpAgent({service: 'https://alice.com'})
|
||||
agent1.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -623,7 +623,7 @@ describe('session', () => {
|
||||
it('can remove inactive account', () => {
|
||||
let state = getInitialState([])
|
||||
|
||||
const agent1 = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent1 = new AtpAgent({service: 'https://alice.com'})
|
||||
agent1.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -631,7 +631,7 @@ describe('session', () => {
|
||||
accessJwt: 'alice-access-jwt-1',
|
||||
refreshJwt: 'alice-refresh-jwt-1',
|
||||
}
|
||||
const agent2 = new BskyAgent({service: 'https://bob.com'})
|
||||
const agent2 = new AtpAgent({service: 'https://bob.com'})
|
||||
agent2.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'bob-did',
|
||||
@@ -704,7 +704,7 @@ describe('session', () => {
|
||||
it('can log out of the current account', () => {
|
||||
let state = getInitialState([])
|
||||
|
||||
const agent1 = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent1 = new AtpAgent({service: 'https://alice.com'})
|
||||
agent1.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -724,7 +724,7 @@ describe('session', () => {
|
||||
expect(state.accounts[0].refreshJwt).toBe('alice-refresh-jwt-1')
|
||||
expect(state.currentAgentState.did).toBe('alice-did')
|
||||
|
||||
const agent2 = new BskyAgent({service: 'https://bob.com'})
|
||||
const agent2 = new AtpAgent({service: 'https://bob.com'})
|
||||
agent2.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'bob-did',
|
||||
@@ -803,7 +803,7 @@ describe('session', () => {
|
||||
it('updates stored account with refreshed tokens', () => {
|
||||
let state = getInitialState([])
|
||||
|
||||
const agent1 = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent1 = new AtpAgent({service: 'https://alice.com'})
|
||||
agent1.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -987,7 +987,7 @@ describe('session', () => {
|
||||
it('bails out of update on identical objects', () => {
|
||||
let state = getInitialState([])
|
||||
|
||||
const agent1 = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent1 = new AtpAgent({service: 'https://alice.com'})
|
||||
agent1.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -1059,7 +1059,7 @@ describe('session', () => {
|
||||
it('accepts updates from a stale agent', () => {
|
||||
let state = getInitialState([])
|
||||
|
||||
const agent1 = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent1 = new AtpAgent({service: 'https://alice.com'})
|
||||
agent1.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -1068,7 +1068,7 @@ describe('session', () => {
|
||||
refreshJwt: 'alice-refresh-jwt-1',
|
||||
}
|
||||
|
||||
const agent2 = new BskyAgent({service: 'https://bob.com'})
|
||||
const agent2 = new AtpAgent({service: 'https://bob.com'})
|
||||
agent2.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'bob-did',
|
||||
@@ -1258,7 +1258,7 @@ describe('session', () => {
|
||||
it('ignores updates from a removed agent', () => {
|
||||
let state = getInitialState([])
|
||||
|
||||
const agent1 = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent1 = new AtpAgent({service: 'https://alice.com'})
|
||||
agent1.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -1267,7 +1267,7 @@ describe('session', () => {
|
||||
refreshJwt: 'alice-refresh-jwt-1',
|
||||
}
|
||||
|
||||
const agent2 = new BskyAgent({service: 'https://bob.com'})
|
||||
const agent2 = new AtpAgent({service: 'https://bob.com'})
|
||||
agent2.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'bob-did',
|
||||
@@ -1320,7 +1320,7 @@ describe('session', () => {
|
||||
it('ignores network errors', () => {
|
||||
let state = getInitialState([])
|
||||
|
||||
const agent1 = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent1 = new AtpAgent({service: 'https://alice.com'})
|
||||
agent1.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -1386,7 +1386,7 @@ describe('session', () => {
|
||||
it('resets tokens on expired event', () => {
|
||||
let state = getInitialState([])
|
||||
|
||||
const agent1 = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent1 = new AtpAgent({service: 'https://alice.com'})
|
||||
agent1.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -1452,7 +1452,7 @@ describe('session', () => {
|
||||
it('resets tokens on created-failed event', () => {
|
||||
let state = getInitialState([])
|
||||
|
||||
const agent1 = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent1 = new AtpAgent({service: 'https://alice.com'})
|
||||
agent1.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -1518,7 +1518,7 @@ describe('session', () => {
|
||||
it('replaces local accounts with synced accounts', () => {
|
||||
let state = getInitialState([])
|
||||
|
||||
const agent1 = new BskyAgent({service: 'https://alice.com'})
|
||||
const agent1 = new AtpAgent({service: 'https://alice.com'})
|
||||
agent1.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'alice-did',
|
||||
@@ -1526,7 +1526,7 @@ describe('session', () => {
|
||||
accessJwt: 'alice-access-jwt-1',
|
||||
refreshJwt: 'alice-refresh-jwt-1',
|
||||
}
|
||||
const agent2 = new BskyAgent({service: 'https://bob.com'})
|
||||
const agent2 = new AtpAgent({service: 'https://bob.com'})
|
||||
agent2.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'bob-did',
|
||||
@@ -1549,7 +1549,7 @@ describe('session', () => {
|
||||
expect(state.accounts.length).toBe(2)
|
||||
expect(state.currentAgentState.did).toBe('bob-did')
|
||||
|
||||
const anotherTabAgent1 = new BskyAgent({service: 'https://jay.com'})
|
||||
const anotherTabAgent1 = new AtpAgent({service: 'https://jay.com'})
|
||||
anotherTabAgent1.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'jay-did',
|
||||
@@ -1557,7 +1557,7 @@ describe('session', () => {
|
||||
accessJwt: 'jay-access-jwt-1',
|
||||
refreshJwt: 'jay-refresh-jwt-1',
|
||||
}
|
||||
const anotherTabAgent2 = new BskyAgent({service: 'https://alice.com'})
|
||||
const anotherTabAgent2 = new AtpAgent({service: 'https://alice.com'})
|
||||
anotherTabAgent2.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'bob-did',
|
||||
@@ -1627,7 +1627,7 @@ describe('session', () => {
|
||||
}
|
||||
`)
|
||||
|
||||
const anotherTabAgent3 = new BskyAgent({service: 'https://clarence.com'})
|
||||
const anotherTabAgent3 = new AtpAgent({service: 'https://clarence.com'})
|
||||
anotherTabAgent3.sessionManager.session = {
|
||||
active: true,
|
||||
did: 'clarence-did',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {BskyAgent} from '@atproto/api'
|
||||
import {AtpAgent} from '@atproto/api'
|
||||
|
||||
import {device} from '#/storage'
|
||||
|
||||
@@ -83,8 +83,8 @@ export function configureAdditionalModerationAuthorities() {
|
||||
}
|
||||
|
||||
const appLabelers = Array.from(
|
||||
new Set([...BskyAgent.appLabelers, ...additionalLabelers]),
|
||||
new Set([...AtpAgent.appLabelers, ...additionalLabelers]),
|
||||
)
|
||||
|
||||
BskyAgent.configure({appLabelers})
|
||||
AtpAgent.configure({appLabelers})
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import {
|
||||
Agent as BaseAgent,
|
||||
type AppBskyActorProfile,
|
||||
AtpAgent,
|
||||
type AtprotoServiceType,
|
||||
type AtpSessionData,
|
||||
type AtpSessionEvent,
|
||||
BskyAgent,
|
||||
type Did,
|
||||
type Un$Typed,
|
||||
} from '@atproto/api'
|
||||
@@ -52,7 +52,7 @@ export function createPublicAgent() {
|
||||
export async function createAgentAndResume(
|
||||
storedAccount: SessionAccount,
|
||||
onSessionChange: (
|
||||
agent: BskyAgent,
|
||||
agent: AtpAgent,
|
||||
did: string,
|
||||
event: AtpSessionEvent,
|
||||
) => void,
|
||||
@@ -96,7 +96,7 @@ export async function createAgentAndLogin(
|
||||
authFactorToken?: string
|
||||
},
|
||||
onSessionChange: (
|
||||
agent: BskyAgent,
|
||||
agent: AtpAgent,
|
||||
did: string,
|
||||
event: AtpSessionEvent,
|
||||
) => void,
|
||||
@@ -143,7 +143,7 @@ export async function createAgentAndCreateAccount(
|
||||
verificationCode?: string
|
||||
},
|
||||
onSessionChange: (
|
||||
agent: BskyAgent,
|
||||
agent: AtpAgent,
|
||||
did: string,
|
||||
event: AtpSessionEvent,
|
||||
) => void,
|
||||
@@ -282,7 +282,7 @@ export async function createAgentAndCreateAccount(
|
||||
})
|
||||
}
|
||||
|
||||
export function agentToSessionAccountOrThrow(agent: BskyAgent): SessionAccount {
|
||||
export function agentToSessionAccountOrThrow(agent: AtpAgent): SessionAccount {
|
||||
const account = agentToSessionAccount(agent)
|
||||
if (!account) {
|
||||
throw Error('Expected an active session')
|
||||
@@ -291,7 +291,7 @@ export function agentToSessionAccountOrThrow(agent: BskyAgent): SessionAccount {
|
||||
}
|
||||
|
||||
export function agentToSessionAccount(
|
||||
agent: BskyAgent,
|
||||
agent: AtpAgent,
|
||||
): SessionAccount | undefined {
|
||||
if (!agent.session) {
|
||||
return undefined
|
||||
@@ -350,7 +350,7 @@ export class Agent extends BaseAgent {
|
||||
// Ideally, we wouldn't be doing this. However, since there is so much logic that requires making calls to the PDS right now, it
|
||||
// feels safer to just let those run as-is and set the header afterward.
|
||||
let realFetch = globalThis.fetch
|
||||
class BskyAppAgent extends BskyAgent {
|
||||
class BskyAppAgent extends AtpAgent {
|
||||
persistSessionHandler: ((event: AtpSessionEvent) => void) | undefined =
|
||||
undefined
|
||||
|
||||
@@ -389,7 +389,7 @@ class BskyAppAgent extends BskyAgent {
|
||||
// Not awaited in the calling code so we can delay blocking on them.
|
||||
resolvers: Promise<unknown>[]
|
||||
onSessionChange: (
|
||||
agent: BskyAgent,
|
||||
agent: AtpAgent,
|
||||
did: string,
|
||||
event: AtpSessionEvent,
|
||||
) => void
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {BSKY_LABELER_DID, BskyAgent} from '@atproto/api'
|
||||
import {AtpAgent, BSKY_LABELER_DID} from '@atproto/api'
|
||||
|
||||
import {IS_TEST_USER} from '#/lib/constants'
|
||||
import {configureAdditionalModerationAuthorities} from './additional-moderation-authorities'
|
||||
@@ -13,7 +13,7 @@ export function configureModerationForGuest() {
|
||||
}
|
||||
|
||||
export async function configureModerationForAccount(
|
||||
agent: BskyAgent,
|
||||
agent: AtpAgent,
|
||||
account: SessionAccount,
|
||||
) {
|
||||
// This global mutation is *only* OK because this code is only relevant for testing.
|
||||
@@ -38,10 +38,10 @@ export async function configureModerationForAccount(
|
||||
}
|
||||
|
||||
function switchToBskyAppLabeler() {
|
||||
BskyAgent.configure({appLabelers: [BSKY_LABELER_DID]})
|
||||
AtpAgent.configure({appLabelers: [BSKY_LABELER_DID]})
|
||||
}
|
||||
|
||||
async function trySwitchToTestAppLabeler(agent: BskyAgent) {
|
||||
async function trySwitchToTestAppLabeler(agent: AtpAgent) {
|
||||
const did = (
|
||||
await agent
|
||||
.resolveHandle({handle: 'mod-authority.test'})
|
||||
@@ -49,6 +49,6 @@ async function trySwitchToTestAppLabeler(agent: BskyAgent) {
|
||||
)?.data.did
|
||||
if (did) {
|
||||
console.warn('USING TEST ENV MODERATION')
|
||||
BskyAgent.configure({appLabelers: [did]})
|
||||
AtpAgent.configure({appLabelers: [did]})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user