diff --git a/.jscodeshift/repo/bsky-agent.js b/.jscodeshift/repo/bsky-agent.js new file mode 100644 index 0000000000..57e501959d --- /dev/null +++ b/.jscodeshift/repo/bsky-agent.js @@ -0,0 +1,62 @@ +/** + * Codemod to replace BskyAgent with AtpAgent + * + * Before: + * import {BskyAgent} from '@atproto/api` + * BskyAgent.appLabelers.includes(labeler) + * + * After: + * import {AtpAgent} from '@atproto/api` + * AtpAgent.appLabelers.includes(labeler) + * + * Handles import specifiers, type annotations, static member access + * (BskyAgent.configure), `extends BskyAgent`, and `new BskyAgent()`. Whole + * identifiers only, so names like `OpaqueBskyAgent` are left untouched. + * + * Usage: jscodeshift -t .jscodeshift/repo/bsky-agent.js + * Example: jscodeshift -t .jscodeshift/repo/bsky-agent.js src/lib/moderation.ts + */ + +/* eslint-disable */ + +export const parser = 'tsx' + +export default function transformer(file, api) { + const j = api.jscodeshift + const root = j(file.source) + + // Replace every standalone `BskyAgent` identifier with `AtpAgent`. This + // covers imports, type references, member expressions, `extends`, and `new`. + root + .find(j.Identifier, {name: 'BskyAgent'}) + .replaceWith(() => j.identifier('AtpAgent')) + + // Renaming can leave a duplicate `AtpAgent` specifier on the @atproto/api + // import if the file already imported it. Dedupe by imported name, keeping + // the type-only modifier only if every duplicate was type-only. + root + .find(j.ImportDeclaration, {source: {value: '@atproto/api'}}) + .forEach(path => { + const seen = new Map() + for (const spec of path.value.specifiers) { + if (spec.type !== 'ImportSpecifier') { + seen.set(Symbol(), spec) + continue + } + const name = spec.imported.name + const existing = seen.get(name) + if (!existing) { + seen.set(name, spec) + } else if ( + existing.importKind === 'type' && + spec.importKind !== 'type' + ) { + // Prefer the value (non-type) import if either usage needs it. + seen.set(name, spec) + } + } + path.value.specifiers = Array.from(seen.values()) + }) + + return root.toSource() +} diff --git a/src/components/forms/DateField/index.android.tsx b/src/components/forms/DateField/index.android.tsx index 2a89be7d3c..d8d95aac79 100644 --- a/src/components/forms/DateField/index.android.tsx +++ b/src/components/forms/DateField/index.android.tsx @@ -67,7 +67,6 @@ export function DateField({ isInvalid={isInvalid} accessibilityHint={accessibilityHint} /> - {open && ( // Android implementation of DatePicker currently does not change default button colors according to theme and only takes hex values for buttonColor // Can remove the buttonColor setting if/when this PR is merged: https://github.com/henninghall/react-native-date-picker/pull/871 diff --git a/src/lib/api/feed/author.ts b/src/lib/api/feed/author.ts index cc19f0f7a1..3b97b8ef73 100644 --- a/src/lib/api/feed/author.ts +++ b/src/lib/api/feed/author.ts @@ -1,20 +1,20 @@ import { AppBskyFeedDefs, type AppBskyFeedGetAuthorFeed as GetAuthorFeed, - type BskyAgent, + type AtpAgent, } from '@atproto/api' import {type FeedAPI, type FeedAPIResponse} from './types' export class AuthorFeedAPI implements FeedAPI { - agent: BskyAgent + agent: AtpAgent _params: GetAuthorFeed.QueryParams constructor({ agent, feedParams, }: { - agent: BskyAgent + agent: AtpAgent feedParams: GetAuthorFeed.QueryParams }) { this.agent = agent diff --git a/src/lib/api/feed/custom.ts b/src/lib/api/feed/custom.ts index 18bb8c8f07..54d9dc9067 100644 --- a/src/lib/api/feed/custom.ts +++ b/src/lib/api/feed/custom.ts @@ -1,7 +1,7 @@ import { type AppBskyFeedDefs, type AppBskyFeedGetFeed as GetCustomFeed, - BskyAgent, + AtpAgent, jsonStringToLex, } from '@atproto/api' @@ -13,7 +13,7 @@ import {type FeedAPI, type FeedAPIResponse} from './types' import {createBskyTopicsHeader, isBlueskyOwnedFeed} from './utils' export class CustomFeedAPI implements FeedAPI { - agent: BskyAgent + agent: AtpAgent params: GetCustomFeed.QueryParams userInterests?: string @@ -22,7 +22,7 @@ export class CustomFeedAPI implements FeedAPI { feedParams, userInterests, }: { - agent: BskyAgent + agent: AtpAgent feedParams: GetCustomFeed.QueryParams userInterests?: string }) { @@ -113,7 +113,7 @@ async function loggedOutFetch({ * @see https://github.com/bluesky-social/atproto/blob/60df3fc652b00cdff71dd9235d98a7a4bb828f05/packages/api/src/agent.ts#L120 */ const labelersHeader = { - 'atproto-accept-labelers': BskyAgent.appLabelers + 'atproto-accept-labelers': AtpAgent.appLabelers .map(l => `${l};redact`) .join(', '), } diff --git a/src/lib/api/feed/demo.ts b/src/lib/api/feed/demo.ts index 049e0f116e..42d1046bdc 100644 --- a/src/lib/api/feed/demo.ts +++ b/src/lib/api/feed/demo.ts @@ -1,12 +1,12 @@ -import {type AppBskyFeedDefs, type BskyAgent} from '@atproto/api' +import {type AppBskyFeedDefs, type AtpAgent} from '@atproto/api' import {DEMO_FEED} from '#/lib/demo' import {type FeedAPI, type FeedAPIResponse} from './types' export class DemoFeedAPI implements FeedAPI { - agent: BskyAgent + agent: AtpAgent - constructor({agent}: {agent: BskyAgent}) { + constructor({agent}: {agent: AtpAgent}) { this.agent = agent } diff --git a/src/lib/api/feed/following.ts b/src/lib/api/feed/following.ts index 26de7f8a07..17e96d8e1b 100644 --- a/src/lib/api/feed/following.ts +++ b/src/lib/api/feed/following.ts @@ -1,11 +1,11 @@ -import {type AppBskyFeedDefs, type BskyAgent} from '@atproto/api' +import {type AppBskyFeedDefs, type AtpAgent} from '@atproto/api' import {type FeedAPI, type FeedAPIResponse} from './types' export class FollowingFeedAPI implements FeedAPI { - agent: BskyAgent + agent: AtpAgent - constructor({agent}: {agent: BskyAgent}) { + constructor({agent}: {agent: AtpAgent}) { this.agent = agent } diff --git a/src/lib/api/feed/home.ts b/src/lib/api/feed/home.ts index 7a0d72d915..aa13c70bf0 100644 --- a/src/lib/api/feed/home.ts +++ b/src/lib/api/feed/home.ts @@ -1,4 +1,4 @@ -import {type AppBskyFeedDefs, type BskyAgent} from '@atproto/api' +import {type AppBskyFeedDefs, type AtpAgent} from '@atproto/api' import {PROD_DEFAULT_FEED} from '#/lib/constants' import {CustomFeedAPI} from './custom' @@ -27,7 +27,7 @@ export const FALLBACK_MARKER_POST: AppBskyFeedDefs.FeedViewPost = { } export class HomeFeedAPI implements FeedAPI { - agent: BskyAgent + agent: AtpAgent following: FollowingFeedAPI discover: CustomFeedAPI usingDiscover = false @@ -39,7 +39,7 @@ export class HomeFeedAPI implements FeedAPI { agent, }: { userInterests?: string - agent: BskyAgent + agent: AtpAgent }) { this.agent = agent this.following = new FollowingFeedAPI({agent}) diff --git a/src/lib/api/feed/likes.ts b/src/lib/api/feed/likes.ts index c970fa72fb..1511dc833a 100644 --- a/src/lib/api/feed/likes.ts +++ b/src/lib/api/feed/likes.ts @@ -1,20 +1,20 @@ import { type AppBskyFeedDefs, type AppBskyFeedGetActorLikes as GetActorLikes, - type BskyAgent, + type AtpAgent, } from '@atproto/api' import {type FeedAPI, type FeedAPIResponse} from './types' export class LikesFeedAPI implements FeedAPI { - agent: BskyAgent + agent: AtpAgent params: GetActorLikes.QueryParams constructor({ agent, feedParams, }: { - agent: BskyAgent + agent: AtpAgent feedParams: GetActorLikes.QueryParams }) { this.agent = agent diff --git a/src/lib/api/feed/merge.ts b/src/lib/api/feed/merge.ts index b3f9575dee..c341dd53a0 100644 --- a/src/lib/api/feed/merge.ts +++ b/src/lib/api/feed/merge.ts @@ -1,7 +1,7 @@ import { type AppBskyFeedDefs, type AppBskyFeedGetTimeline, - type BskyAgent, + type AtpAgent, } from '@atproto/api' import shuffle from 'lodash.shuffle' @@ -24,7 +24,7 @@ const POST_AGE_CUTOFF = 60e3 * 60 * 24 // 24hours export class MergeFeedAPI implements FeedAPI { userInterests?: string - agent: BskyAgent + agent: AtpAgent params: FeedParams feedTuners: FeedTunerFn[] following: MergeFeedSource_Following @@ -39,7 +39,7 @@ export class MergeFeedAPI implements FeedAPI { feedTuners, userInterests, }: { - agent: BskyAgent + agent: AtpAgent feedParams: FeedParams feedTuners: FeedTunerFn[] userInterests?: string @@ -175,7 +175,7 @@ export class MergeFeedAPI implements FeedAPI { } class MergeFeedSource { - agent: BskyAgent + agent: AtpAgent feedTuners: FeedTunerFn[] sourceInfo: ReasonFeedSource | undefined cursor: string | undefined = undefined @@ -186,7 +186,7 @@ class MergeFeedSource { agent, feedTuners, }: { - agent: BskyAgent + agent: AtpAgent feedTuners: FeedTunerFn[] }) { this.agent = agent @@ -253,7 +253,7 @@ class MergeFeedSource_Following extends MergeFeedSource { } class MergeFeedSource_Custom extends MergeFeedSource { - agent: BskyAgent + agent: AtpAgent minDate: Date feedUri: string userInterests?: string @@ -264,7 +264,7 @@ class MergeFeedSource_Custom extends MergeFeedSource { feedTuners, userInterests, }: { - agent: BskyAgent + agent: AtpAgent feedUri: string feedTuners: FeedTunerFn[] userInterests?: string diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index 40e6743b9a..5a278aeba4 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -7,8 +7,8 @@ import { type AppBskyEmbedRecordWithMedia, type AppBskyEmbedVideo, AppBskyFeedPost, + type AtpAgent, BlobRef, - type BskyAgent, ChatBskyGroupDefs, type ComAtprotoLabelDefs, type ComAtprotoRepoApplyWrites, @@ -55,7 +55,7 @@ interface PostOpts { } export async function post( - agent: BskyAgent, + agent: AtpAgent, queryClient: QueryClient, opts: PostOpts, ) { @@ -197,7 +197,7 @@ export async function post( return {uris} } -async function resolveRT(agent: BskyAgent, richtext: RichText) { +async function resolveRT(agent: AtpAgent, richtext: RichText) { const trimmedText = richtext.text // Trim leading whitespace-only lines (but don't break ASCII art). .replace(/^(\s*\n)+/, '') @@ -217,7 +217,7 @@ export class ReplyDeletedError extends Error { } } -async function resolveReply(agent: BskyAgent, replyTo: string) { +async function resolveReply(agent: AtpAgent, replyTo: string) { const {data} = await agent.app.bsky.feed.getPosts({ uris: [replyTo], }) @@ -250,7 +250,7 @@ async function resolveReply(agent: BskyAgent, replyTo: string) { } async function resolveEmbed( - agent: BskyAgent, + agent: AtpAgent, queryClient: QueryClient, draft: PostDraft, onStateChange: ((state: string) => void) | undefined, @@ -309,7 +309,7 @@ async function resolveEmbed( } async function resolveMedia( - agent: BskyAgent, + agent: AtpAgent, queryClient: QueryClient, embedDraft: EmbedDraft, onStateChange: ((state: string) => void) | undefined, @@ -482,7 +482,7 @@ async function resolveMedia( } async function resolveRecord( - agent: BskyAgent, + agent: AtpAgent, queryClient: QueryClient, uri: string, ): Promise { diff --git a/src/lib/api/upload-blob.ts b/src/lib/api/upload-blob.ts index 260ba770b8..0bee39b9b1 100644 --- a/src/lib/api/upload-blob.ts +++ b/src/lib/api/upload-blob.ts @@ -1,5 +1,5 @@ import {copyAsync} from 'expo-file-system/legacy' -import {type BskyAgent, type ComAtprotoRepoUploadBlob} from '@atproto/api' +import {type AtpAgent, type ComAtprotoRepoUploadBlob} from '@atproto/api' import {safeDeleteAsync} from '#/lib/media/manip' @@ -7,7 +7,7 @@ import {safeDeleteAsync} from '#/lib/media/manip' * @param encoding Allows overriding the blob's type */ export async function uploadBlob( - agent: BskyAgent, + agent: AtpAgent, input: string | Blob, encoding?: string, ): Promise { diff --git a/src/lib/api/upload-blob.web.ts b/src/lib/api/upload-blob.web.ts index 9f21be5670..d74e834647 100644 --- a/src/lib/api/upload-blob.web.ts +++ b/src/lib/api/upload-blob.web.ts @@ -1,4 +1,4 @@ -import {type BskyAgent, type ComAtprotoRepoUploadBlob} from '@atproto/api' +import {type AtpAgent, type ComAtprotoRepoUploadBlob} from '@atproto/api' /** * @note It is recommended, on web, to use the `file` instance of the file @@ -7,7 +7,7 @@ import {type BskyAgent, type ComAtprotoRepoUploadBlob} from '@atproto/api' * be passed directly to this function. */ export async function uploadBlob( - agent: BskyAgent, + agent: AtpAgent, input: string | Blob, encoding?: string, ): Promise { diff --git a/src/lib/generate-starterpack.ts b/src/lib/generate-starterpack.ts index 1f4265a17e..a53e95a6a3 100644 --- a/src/lib/generate-starterpack.ts +++ b/src/lib/generate-starterpack.ts @@ -2,7 +2,7 @@ import { type $Typed, type AppBskyActorDefs, type AppBskyGraphGetStarterPack, - type BskyAgent, + type AtpAgent, type ComAtprotoRepoApplyWrites, type Facet, } from '@atproto/api' @@ -28,7 +28,7 @@ export const createStarterPackList = async ({ description?: string descriptionFacets?: Facet[] profiles: bsky.profile.AnyProfileView[] - agent: BskyAgent + agent: AtpAgent }): Promise<{uri: string; cid: string}> => { if (profiles.length === 0) throw new Error('No profiles given') @@ -152,7 +152,7 @@ function createListItem({ } async function whenAppViewReady( - agent: BskyAgent, + agent: AtpAgent, uri: string, fn: (res?: AppBskyGraphGetStarterPack.Response) => boolean, ) { diff --git a/src/lib/link-meta/link-meta.ts b/src/lib/link-meta/link-meta.ts index e72bab9f01..c282a0c4c3 100644 --- a/src/lib/link-meta/link-meta.ts +++ b/src/lib/link-meta/link-meta.ts @@ -1,4 +1,4 @@ -import {type AppBskyEmbedExternal, type BskyAgent} from '@atproto/api' +import {type AppBskyEmbedExternal, type AtpAgent} from '@atproto/api' import {LINK_META_PROXY} from '#/lib/constants' import {getGiphyMetaUri} from '#/lib/strings/embed-player' @@ -31,7 +31,7 @@ export interface LinkMeta { } export async function getLinkMeta( - agent: BskyAgent, + agent: AtpAgent, url: string, timeout = 15e3, ): Promise { diff --git a/src/lib/media/video/upload.shared.ts b/src/lib/media/video/upload.shared.ts index fd46e27868..f8aaa1249b 100644 --- a/src/lib/media/video/upload.shared.ts +++ b/src/lib/media/video/upload.shared.ts @@ -1,4 +1,4 @@ -import {type BskyAgent} from '@atproto/api' +import {type AtpAgent} from '@atproto/api' import {type I18n} from '@lingui/core' import {msg} from '@lingui/core/macro' @@ -13,7 +13,7 @@ export async function getServiceAuthToken({ lxm, exp, }: { - agent: BskyAgent + agent: AtpAgent aud?: string lxm: string exp?: number @@ -30,7 +30,7 @@ export async function getServiceAuthToken({ return serviceAuth.token } -export async function getVideoUploadLimits(agent: BskyAgent, i18n: I18n) { +export async function getVideoUploadLimits(agent: AtpAgent, i18n: I18n) { const token = await getServiceAuthToken({ agent, lxm: 'app.bsky.video.getUploadLimits', diff --git a/src/lib/media/video/upload.ts b/src/lib/media/video/upload.ts index 503577a76a..721ee7f94f 100644 --- a/src/lib/media/video/upload.ts +++ b/src/lib/media/video/upload.ts @@ -1,5 +1,5 @@ import {createUploadTask, FileSystemUploadType} from 'expo-file-system/legacy' -import {type AppBskyVideoDefs, type BskyAgent} from '@atproto/api' +import {type AppBskyVideoDefs, type AtpAgent} from '@atproto/api' import {type I18n} from '@lingui/core' import {msg} from '@lingui/core/macro' import {nanoid} from 'nanoid/non-secure' @@ -19,7 +19,7 @@ export async function uploadVideo({ i18n, }: { video: CompressedVideo - agent: BskyAgent + agent: AtpAgent did: string setProgress: (progress: number) => void signal: AbortSignal diff --git a/src/lib/media/video/upload.web.ts b/src/lib/media/video/upload.web.ts index 98d329a709..e88a04707c 100644 --- a/src/lib/media/video/upload.web.ts +++ b/src/lib/media/video/upload.web.ts @@ -1,4 +1,4 @@ -import {type AppBskyVideoDefs, type BskyAgent} from '@atproto/api' +import {type AppBskyVideoDefs, type AtpAgent} from '@atproto/api' import {type I18n} from '@lingui/core' import {msg} from '@lingui/core/macro' import {nanoid} from 'nanoid/non-secure' @@ -18,7 +18,7 @@ export async function uploadVideo({ i18n, }: { video: CompressedVideo - agent: BskyAgent + agent: AtpAgent did: string setProgress: (progress: number) => void signal: AbortSignal diff --git a/src/lib/moderation.ts b/src/lib/moderation.ts index 9b0ac0ea5f..2fb37009e2 100644 --- a/src/lib/moderation.ts +++ b/src/lib/moderation.ts @@ -1,7 +1,7 @@ import {useMemo} from 'react' import { type AppBskyLabelerDefs, - BskyAgent, + AtpAgent, type ComAtprotoLabelDefs, type InterpretedLabelValueDefinition, LABELS, @@ -91,9 +91,9 @@ export function isAppLabeler( | AppBskyLabelerDefs.LabelerViewDetailed, ): boolean { if (typeof labeler === 'string') { - return BskyAgent.appLabelers.includes(labeler) + return AtpAgent.appLabelers.includes(labeler) } - return BskyAgent.appLabelers.includes(labeler.creator.did) + return AtpAgent.appLabelers.includes(labeler.creator.did) } export function isLabelerSubscribed( diff --git a/src/screens/Onboarding/util.ts b/src/screens/Onboarding/util.ts index acb96ee914..f4ecde3c5d 100644 --- a/src/screens/Onboarding/util.ts +++ b/src/screens/Onboarding/util.ts @@ -2,7 +2,7 @@ import { type $Typed, type AppBskyGraphFollow, type AppBskyGraphGetFollows, - type BskyAgent, + type AtpAgent, type ComAtprotoRepoApplyWrites, type ComAtprotoRepoStrongRef, } from '@atproto/api' @@ -12,7 +12,7 @@ import chunk from 'lodash.chunk' import {until} from '#/lib/async/until' export async function bulkWriteFollows( - agent: BskyAgent, + agent: AtpAgent, dids: string[], via?: ComAtprotoRepoStrongRef.Main, ) { @@ -59,7 +59,7 @@ export async function bulkWriteFollows( } async function whenFollowsIndexed( - agent: BskyAgent, + agent: AtpAgent, actor: string, fn: (res: AppBskyGraphGetFollows.Response) => boolean, ) { diff --git a/src/state/messages/convo/types.ts b/src/state/messages/convo/types.ts index 269f32c515..c83fbfb813 100644 --- a/src/state/messages/convo/types.ts +++ b/src/state/messages/convo/types.ts @@ -1,7 +1,7 @@ import { type $Typed, type AppBskyEmbedRecord, - type BskyAgent, + type AtpAgent, type ChatBskyActorDefs, type ChatBskyConvoDefs, type ChatBskyConvoSendMessage, @@ -13,7 +13,7 @@ import {type ConvoWithDetails} from '#/components/dms/util' export type ConvoParams = { convoId: string - agent: BskyAgent + agent: AtpAgent events: MessagesEventBus placeholderData?: { convo: ChatBskyConvoDefs.ConvoView diff --git a/src/state/messages/events/agent.ts b/src/state/messages/events/agent.ts index ce9518212b..636261bd27 100644 --- a/src/state/messages/events/agent.ts +++ b/src/state/messages/events/agent.ts @@ -1,4 +1,4 @@ -import {type BskyAgent, type ChatBskyConvoGetLog} from '@atproto/api' +import {type AtpAgent, type ChatBskyConvoGetLog} from '@atproto/api' import {EventEmitter} from 'eventemitter3' import {nanoid} from 'nanoid/non-secure' @@ -27,7 +27,7 @@ const logger = Logger.create(Logger.Context.DMsAgent) export class MessagesEventBus { private id: string - private agent: BskyAgent + private agent: AtpAgent private emitter = new EventEmitter<{event: [MessagesEventBusEvent]}>() private status: MessagesEventBusStatus = MessagesEventBusStatus.Initializing diff --git a/src/state/messages/events/types.ts b/src/state/messages/events/types.ts index 038684319a..67d6bdd452 100644 --- a/src/state/messages/events/types.ts +++ b/src/state/messages/events/types.ts @@ -1,7 +1,7 @@ -import {type BskyAgent, type ChatBskyConvoGetLog} from '@atproto/api' +import {type AtpAgent, type ChatBskyConvoGetLog} from '@atproto/api' export type MessagesEventBusParams = { - agent: BskyAgent + agent: AtpAgent } export enum MessagesEventBusStatus { diff --git a/src/state/queries/list-members.ts b/src/state/queries/list-members.ts index 152c7a5be8..c43c7bb983 100644 --- a/src/state/queries/list-members.ts +++ b/src/state/queries/list-members.ts @@ -2,7 +2,7 @@ import { type AppBskyActorDefs, type AppBskyGraphDefs, type AppBskyGraphGetList, - type BskyAgent, + type AtpAgent, } from '@atproto/api' import { type InfiniteData, @@ -60,7 +60,7 @@ export function useAllListMembersQuery(uri?: string) { }) } -export async function getAllListMembers(agent: BskyAgent, uri: string) { +export async function getAllListMembers(agent: AtpAgent, uri: string) { let hasMore = true let cursor: string | undefined const listItems: AppBskyGraphDefs.ListItemView[] = [] diff --git a/src/state/queries/list.ts b/src/state/queries/list.ts index 462cc4919a..b5deb087c3 100644 --- a/src/state/queries/list.ts +++ b/src/state/queries/list.ts @@ -3,8 +3,8 @@ import { type AppBskyGraphDefs, type AppBskyGraphGetList, type AppBskyGraphList, + type AtpAgent, AtUri, - type BskyAgent, type ComAtprotoRepoApplyWrites, type Facet, type Un$Typed, @@ -305,7 +305,7 @@ export function useListBlockMutation() { } async function whenAppViewReady( - agent: BskyAgent, + agent: AtpAgent, uri: string, fn: (res: AppBskyGraphGetList.Response) => boolean, ) { diff --git a/src/state/queries/notifications/util.ts b/src/state/queries/notifications/util.ts index a8c15e82c0..ded66fb62e 100644 --- a/src/state/queries/notifications/util.ts +++ b/src/state/queries/notifications/util.ts @@ -6,7 +6,7 @@ import { type AppBskyGraphDefs, AppBskyGraphStarterpack, type AppBskyNotificationListNotifications, - type BskyAgent, + type AtpAgent, hasMutedWord, moderateNotification, type ModerationOpts, @@ -46,7 +46,7 @@ export async function fetchPage({ fetchAdditionalData, reasons, }: { - agent: BskyAgent + agent: AtpAgent cursor: string | undefined limit: number queryClient: QueryClient @@ -204,7 +204,7 @@ export function groupNotifications( } async function fetchSubjects( - agent: BskyAgent, + agent: AtpAgent, groupedNotifs: FeedNotification[], ): Promise<{ posts: Map diff --git a/src/state/queries/post-feed.ts b/src/state/queries/post-feed.ts index 2fbb9e7cbe..959ed81c28 100644 --- a/src/state/queries/post-feed.ts +++ b/src/state/queries/post-feed.ts @@ -4,8 +4,8 @@ import { type AppBskyActorDefs, AppBskyFeedDefs, type AppBskyFeedPost, + type AtpAgent, AtUri, - type BskyAgent, moderatePost, type ModerationDecision, type ModerationPrefs, @@ -450,7 +450,7 @@ function createApi({ feedParams: FeedParams feedTuners: FeedTunerFn[] userInterests?: string - agent: BskyAgent + agent: AtpAgent enableFollowingToDiscoverFallback: boolean }) { if (feedDesc === 'following') { diff --git a/src/state/queries/postgate/index.ts b/src/state/queries/postgate/index.ts index 926bb0ba0c..82a52730bc 100644 --- a/src/state/queries/postgate/index.ts +++ b/src/state/queries/postgate/index.ts @@ -4,8 +4,8 @@ import { AppBskyEmbedRecordWithMedia, type AppBskyFeedDefs, AppBskyFeedPostgate, + type AtpAgent, AtUri, - type BskyAgent, } from '@atproto/api' import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query' @@ -27,7 +27,7 @@ export async function getPostgateRecord({ agent, postUri, }: { - agent: BskyAgent + agent: AtpAgent postUri: string }): Promise { const urip = new AtUri(postUri) @@ -89,7 +89,7 @@ export async function writePostgateRecord({ postUri, postgate, }: { - agent: BskyAgent + agent: AtpAgent postUri: string postgate: AppBskyFeedPostgate.Record }) { @@ -110,7 +110,7 @@ export async function upsertPostgate( agent, postUri, }: { - agent: BskyAgent + agent: AtpAgent postUri: string }, callback: ( diff --git a/src/state/queries/preferences/moderation.ts b/src/state/queries/preferences/moderation.ts index c23e995e41..55c155dc5b 100644 --- a/src/state/queries/preferences/moderation.ts +++ b/src/state/queries/preferences/moderation.ts @@ -1,5 +1,5 @@ import {useMemo} from 'react' -import {BskyAgent, interpretLabelValueDefinitions} from '@atproto/api' +import {AtpAgent, interpretLabelValueDefinitions} from '@atproto/api' import {isNonConfigurableModerationAuthority} from '#/state/session/additional-moderation-authorities' import {useLabelersDetailedInfoQuery} from '../labeler' @@ -13,7 +13,7 @@ export function useMyLabelersQuery({ const prefs = usePreferencesQuery() let dids = Array.from( new Set( - BskyAgent.appLabelers.concat( + AtpAgent.appLabelers.concat( prefs.data?.moderationPrefs.labelers.map(l => l.did) || [], ), ), diff --git a/src/state/queries/resolve-uri.ts b/src/state/queries/resolve-uri.ts index a6ca192be3..45ef4e2288 100644 --- a/src/state/queries/resolve-uri.ts +++ b/src/state/queries/resolve-uri.ts @@ -1,4 +1,4 @@ -import {AtUri, type BskyAgent} from '@atproto/api' +import {type AtpAgent, AtUri} from '@atproto/api' import {type QueryClient, queryOptions, useQuery} from '@tanstack/react-query' import {STALE} from '#/state/queries' @@ -9,7 +9,7 @@ const RQKEY_ROOT = 'resolved-did' export const RQKEY = (didOrHandle: string) => [RQKEY_ROOT, didOrHandle] const resolvedDidQueryOptions = ( - agent: BskyAgent, + agent: AtpAgent, getUnstableProfile: (did: string) => {did: string} | undefined, didOrHandle: string | undefined, ) => diff --git a/src/state/queries/starter-packs.ts b/src/state/queries/starter-packs.ts index 53d668d89a..ddf8365dda 100644 --- a/src/state/queries/starter-packs.ts +++ b/src/state/queries/starter-packs.ts @@ -4,8 +4,8 @@ import { type AppBskyGraphGetStarterPack, AppBskyGraphStarterpack, type AppBskyRichtextFacet, + type AtpAgent, AtUri, - type BskyAgent, RichText, } from '@atproto/api' import { @@ -340,7 +340,7 @@ export function useDeleteStarterPackMutation({ } async function whenAppViewReady( - agent: BskyAgent, + agent: AtpAgent, uri: string, fn: (res?: AppBskyGraphGetStarterPack.Response) => boolean, ) { diff --git a/src/state/queries/threadgate/index.ts b/src/state/queries/threadgate/index.ts index e760873fb2..561275ca66 100644 --- a/src/state/queries/threadgate/index.ts +++ b/src/state/queries/threadgate/index.ts @@ -1,8 +1,8 @@ import { type AppBskyFeedDefs, AppBskyFeedThreadgate, + type AtpAgent, AtUri, - type BskyAgent, } from '@atproto/api' import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query' @@ -88,7 +88,7 @@ export async function getThreadgateRecord({ agent, postUri, }: { - agent: BskyAgent + agent: AtpAgent postUri: string }): Promise { const urip = new AtUri(postUri) @@ -150,7 +150,7 @@ export async function writeThreadgateRecord({ postUri, threadgate, }: { - agent: BskyAgent + agent: AtpAgent postUri: string threadgate: AppBskyFeedThreadgate.Record }) { @@ -176,7 +176,7 @@ export async function upsertThreadgate( agent, postUri, }: { - agent: BskyAgent + agent: AtpAgent postUri: string }, callback: ( @@ -205,7 +205,7 @@ export async function updateThreadgateAllow({ postUri, allow, }: { - agent: BskyAgent + agent: AtpAgent postUri: string allow: ThreadgateAllowUISetting[] }) { diff --git a/src/state/session/__tests__/session-test.ts b/src/state/session/__tests__/session-test.ts index 4398a90a0b..eebcfcf8d2 100644 --- a/src/state/session/__tests__/session-test.ts +++ b/src/state/session/__tests__/session-test.ts @@ -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', diff --git a/src/state/session/additional-moderation-authorities.ts b/src/state/session/additional-moderation-authorities.ts index 8088db88e1..63ada2cdd8 100644 --- a/src/state/session/additional-moderation-authorities.ts +++ b/src/state/session/additional-moderation-authorities.ts @@ -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}) } diff --git a/src/state/session/agent.ts b/src/state/session/agent.ts index fe669dfe8b..78e9f79610 100644 --- a/src/state/session/agent.ts +++ b/src/state/session/agent.ts @@ -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[] onSessionChange: ( - agent: BskyAgent, + agent: AtpAgent, did: string, event: AtpSessionEvent, ) => void diff --git a/src/state/session/moderation.ts b/src/state/session/moderation.ts index 64e36da9d4..8fc234d732 100644 --- a/src/state/session/moderation.ts +++ b/src/state/session/moderation.ts @@ -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]}) } } diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 39c4292892..3ddaf41ed7 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -50,8 +50,8 @@ import { AppBskyDraftCreateDraft, AppBskyUnspeccedDefs, type AppBskyUnspeccedGetPostThreadV2, + type AtpAgent, AtUri, - type BskyAgent, ChatBskyGroupDefs, type RichText, } from '@atproto/api' @@ -2358,7 +2358,7 @@ function useKeyboardVerticalOffset() { } async function whenAppViewReady( - agent: BskyAgent, + agent: AtpAgent, uri: string, fn: (res: AppBskyUnspeccedGetPostThreadV2.Response) => boolean, ) { diff --git a/src/view/com/composer/state/video.ts b/src/view/com/composer/state/video.ts index 6d73e846e6..54bfcd67af 100644 --- a/src/view/com/composer/state/video.ts +++ b/src/view/com/composer/state/video.ts @@ -1,5 +1,5 @@ import {type ImagePickerAsset} from 'expo-image-picker' -import {type AppBskyVideoDefs, type BlobRef, type BskyAgent} from '@atproto/api' +import {type AppBskyVideoDefs, type AtpAgent, type BlobRef} from '@atproto/api' import {type I18n} from '@lingui/core' import {msg} from '@lingui/core/macro' @@ -261,7 +261,7 @@ function trunc2dp(num: number) { export async function processVideo( asset: ImagePickerAsset, dispatch: (action: VideoAction) => void, - agent: BskyAgent, + agent: AtpAgent, did: string, signal: AbortSignal, i18n: I18n,