@atproto/api 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +179 -25
- package/build.js +2 -1
- package/dist/agent.d.ts +11 -6
- package/dist/bsky-agent.d.ts +43 -0
- package/dist/client/index.d.ts +117 -215
- package/dist/client/lexicons.d.ts +1440 -1401
- package/dist/client/types/app/bsky/actor/defs.d.ts +47 -0
- package/dist/client/types/app/bsky/actor/getProfile.d.ts +2 -2
- package/dist/client/types/app/bsky/actor/getProfiles.d.ts +2 -2
- package/dist/client/types/app/bsky/actor/getSuggestions.d.ts +2 -2
- package/dist/client/types/app/bsky/actor/profile.d.ts +4 -60
- package/dist/client/types/app/bsky/actor/searchActors.d.ts +22 -0
- package/dist/client/types/app/bsky/actor/searchActorsTypeahead.d.ts +20 -0
- package/dist/client/types/app/bsky/actor/updateProfile.d.ts +3 -10
- package/dist/client/types/app/bsky/embed/external.d.ts +9 -13
- package/dist/client/types/app/bsky/embed/images.d.ts +9 -13
- package/dist/client/types/app/bsky/embed/record.d.ts +21 -13
- package/dist/client/types/app/bsky/embed/recordWithMedia.d.ts +24 -0
- package/dist/client/types/app/bsky/feed/defs.d.ts +77 -0
- package/dist/client/types/app/bsky/feed/getAuthorFeed.d.ts +4 -4
- package/dist/client/types/app/bsky/feed/getLikes.d.ts +34 -0
- package/dist/client/types/app/bsky/feed/getPostThread.d.ts +2 -24
- package/dist/client/types/app/bsky/feed/getRepostedBy.d.ts +3 -3
- package/dist/client/types/app/bsky/feed/getTimeline.d.ts +3 -3
- package/dist/client/types/app/bsky/feed/like.d.ts +9 -0
- package/dist/client/types/app/bsky/feed/post.d.ts +4 -29
- package/dist/client/types/app/bsky/graph/follow.d.ts +1 -2
- package/dist/client/types/app/bsky/graph/getFollowers.d.ts +5 -5
- package/dist/client/types/app/bsky/graph/getFollows.d.ts +5 -5
- package/dist/client/types/app/bsky/graph/getMutes.d.ts +3 -3
- package/dist/client/types/app/bsky/graph/muteActor.d.ts +17 -0
- package/dist/client/types/app/bsky/graph/unmuteActor.d.ts +17 -0
- package/dist/client/types/app/bsky/notification/getUnreadCount.d.ts +17 -0
- package/dist/client/types/app/bsky/notification/listNotifications.d.ts +35 -0
- package/dist/client/types/app/bsky/richtext/facet.d.ts +30 -0
- package/dist/client/types/app/bsky/unspecced/getPopular.d.ts +21 -0
- package/dist/client/types/com/atproto/admin/defs.d.ts +181 -0
- package/dist/client/types/com/atproto/admin/getModerationAction.d.ts +2 -2
- package/dist/client/types/com/atproto/admin/getModerationActions.d.ts +3 -3
- package/dist/client/types/com/atproto/admin/getModerationReport.d.ts +2 -2
- package/dist/client/types/com/atproto/admin/getModerationReports.d.ts +3 -3
- package/dist/client/types/com/atproto/admin/getRecord.d.ts +2 -2
- package/dist/client/types/com/atproto/admin/getRepo.d.ts +2 -2
- package/dist/client/types/com/atproto/admin/resolveModerationReports.d.ts +2 -2
- package/dist/client/types/com/atproto/admin/reverseModerationAction.d.ts +2 -2
- package/dist/client/types/com/atproto/admin/searchRepos.d.ts +3 -3
- package/dist/client/types/com/atproto/admin/takeModerationAction.d.ts +5 -6
- package/dist/client/types/com/atproto/identity/resolveHandle.d.ts +18 -0
- package/dist/client/types/com/atproto/identity/updateHandle.d.ts +17 -0
- package/dist/client/types/com/atproto/moderation/createReport.d.ts +38 -0
- package/dist/client/types/com/atproto/moderation/defs.d.ts +3 -0
- package/dist/client/types/com/atproto/repo/applyWrites.d.ts +47 -0
- package/dist/client/types/com/atproto/repo/createRecord.d.ts +7 -2
- package/dist/client/types/com/atproto/repo/deleteRecord.d.ts +7 -2
- package/dist/client/types/com/atproto/repo/describeRepo.d.ts +22 -0
- package/dist/client/types/com/atproto/repo/getRecord.d.ts +1 -1
- package/dist/client/types/com/atproto/repo/listRecords.d.ts +3 -3
- package/dist/client/types/com/atproto/repo/putRecord.d.ts +7 -2
- package/dist/client/types/com/atproto/repo/uploadBlob.d.ts +20 -0
- package/dist/client/types/com/atproto/server/createAccount.d.ts +44 -0
- package/dist/client/types/com/atproto/server/createInviteCode.d.ts +22 -0
- package/dist/client/types/com/atproto/server/createSession.d.ts +29 -0
- package/dist/client/types/com/atproto/server/deleteAccount.d.ts +25 -0
- package/dist/client/types/com/atproto/server/deleteSession.d.ts +13 -0
- package/dist/client/types/com/atproto/server/describeServer.d.ts +27 -0
- package/dist/client/types/com/atproto/server/getSession.d.ts +18 -0
- package/dist/client/types/com/atproto/server/refreshSession.d.ts +24 -0
- package/dist/client/types/com/atproto/server/requestAccountDelete.d.ts +13 -0
- package/dist/client/types/com/atproto/server/requestPasswordReset.d.ts +17 -0
- package/dist/client/types/com/atproto/server/resetPassword.d.ts +24 -0
- package/dist/client/types/com/atproto/sync/getBlob.d.ts +15 -0
- package/dist/client/types/com/atproto/sync/listBlobs.d.ts +20 -0
- package/dist/client/types/com/atproto/sync/notifyOfUpdate.d.ts +1 -0
- package/dist/client/types/com/atproto/sync/requestCrawl.d.ts +1 -1
- package/dist/client/types/com/atproto/sync/subscribeAllRepos.d.ts +9 -1
- package/dist/client/types/com/atproto/sync/subscribeRepos.d.ts +58 -0
- package/dist/helpers/bsky.d.ts +20 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8046 -3649
- package/dist/index.js.map +4 -4
- package/dist/mixins/bsky.d.ts +23 -0
- package/dist/rich-text/detection.d.ts +4 -0
- package/dist/rich-text/rich-text.d.ts +39 -0
- package/dist/rich-text/sanitization.d.ts +4 -0
- package/dist/rich-text/sanitize.d.ts +4 -0
- package/dist/rich-text/unicode.d.ts +11 -0
- package/dist/types.d.ts +2 -2
- package/docs/rn-fetch-handler.ts +88 -0
- package/package.json +4 -1
- package/src/agent.ts +51 -15
- package/src/bsky-agent.ts +228 -0
- package/src/client/index.ts +330 -581
- package/src/client/lexicons.ts +1824 -1777
- package/src/client/types/app/bsky/actor/defs.ts +97 -0
- package/src/client/types/app/bsky/actor/getProfile.ts +4 -3
- package/src/client/types/app/bsky/actor/getProfiles.ts +4 -3
- package/src/client/types/app/bsky/actor/getSuggestions.ts +4 -3
- package/src/client/types/app/bsky/actor/profile.ts +5 -95
- package/src/client/types/app/bsky/actor/{searchTypeahead.ts → searchActors.ts} +6 -3
- package/src/client/types/app/bsky/actor/{search.ts → searchActorsTypeahead.ts} +4 -5
- package/src/client/types/app/bsky/embed/external.ts +14 -13
- package/src/client/types/app/bsky/embed/images.ts +14 -15
- package/src/client/types/app/bsky/embed/record.ts +32 -25
- package/src/client/types/app/bsky/embed/recordWithMedia.ts +53 -0
- package/src/client/types/app/bsky/feed/defs.ts +156 -0
- package/src/client/types/app/bsky/feed/getAuthorFeed.ts +6 -5
- package/src/client/types/app/bsky/feed/{getVotes.ts → getLikes.ts} +11 -12
- package/src/client/types/app/bsky/feed/getPostThread.ts +5 -48
- package/src/client/types/app/bsky/feed/getRepostedBy.ts +5 -4
- package/src/client/types/app/bsky/feed/getTimeline.ts +5 -4
- package/src/client/types/app/bsky/feed/{vote.ts → like.ts} +4 -4
- package/src/client/types/app/bsky/feed/post.ts +10 -52
- package/src/client/types/app/bsky/feed/repost.ts +2 -1
- package/src/client/types/app/bsky/graph/follow.ts +3 -3
- package/src/client/types/app/bsky/graph/getFollowers.ts +7 -6
- package/src/client/types/app/bsky/graph/getFollows.ts +7 -6
- package/src/client/types/app/bsky/graph/getMutes.ts +5 -4
- package/src/client/types/app/bsky/graph/{mute.ts → muteActor.ts} +3 -2
- package/src/client/types/app/bsky/graph/{unmute.ts → unmuteActor.ts} +3 -2
- package/src/client/types/app/bsky/notification/{getCount.ts → getUnreadCount.ts} +2 -1
- package/src/client/types/app/bsky/notification/{list.ts → listNotifications.ts} +13 -9
- package/src/client/types/app/bsky/notification/updateSeen.ts +2 -1
- package/src/client/types/app/bsky/richtext/facet.ts +81 -0
- package/src/client/types/app/bsky/unspecced/getPopular.ts +38 -0
- package/src/client/types/com/atproto/admin/defs.ts +366 -0
- package/src/client/types/com/atproto/admin/getModerationAction.ts +4 -3
- package/src/client/types/com/atproto/admin/getModerationActions.ts +5 -4
- package/src/client/types/com/atproto/admin/getModerationReport.ts +4 -3
- package/src/client/types/com/atproto/admin/getModerationReports.ts +5 -4
- package/src/client/types/com/atproto/admin/getRecord.ts +4 -3
- package/src/client/types/com/atproto/admin/getRepo.ts +4 -3
- package/src/client/types/com/atproto/admin/resolveModerationReports.ts +4 -3
- package/src/client/types/com/atproto/admin/reverseModerationAction.ts +4 -3
- package/src/client/types/com/atproto/admin/searchRepos.ts +5 -4
- package/src/client/types/com/atproto/admin/takeModerationAction.ts +10 -10
- package/src/client/types/com/atproto/{handle/resolve.ts → identity/resolveHandle.ts} +2 -1
- package/src/client/types/com/atproto/{handle/update.ts → identity/updateHandle.ts} +2 -1
- package/src/client/types/com/atproto/{report/create.ts → moderation/createReport.ts} +10 -10
- package/src/client/types/com/atproto/moderation/defs.ts +17 -0
- package/src/client/types/com/atproto/repo/{batchWrite.ts → applyWrites.ts} +21 -12
- package/src/client/types/com/atproto/repo/createRecord.ts +15 -3
- package/src/client/types/com/atproto/repo/deleteRecord.ts +15 -3
- package/src/client/types/com/atproto/repo/{describe.ts → describeRepo.ts} +3 -2
- package/src/client/types/com/atproto/repo/getRecord.ts +4 -3
- package/src/client/types/com/atproto/repo/listRecords.ts +7 -6
- package/src/client/types/com/atproto/repo/putRecord.ts +18 -6
- package/src/client/types/com/atproto/repo/strongRef.ts +2 -1
- package/src/client/types/com/atproto/{blob/upload.ts → repo/uploadBlob.ts} +3 -2
- package/src/client/types/com/atproto/{account/create.ts → server/createAccount.ts} +9 -1
- package/src/client/types/com/atproto/{account → server}/createInviteCode.ts +2 -1
- package/src/client/types/com/atproto/{session/create.ts → server/createSession.ts} +2 -1
- package/src/client/types/com/atproto/{account/delete.ts → server/deleteAccount.ts} +2 -1
- package/src/client/types/com/atproto/{account/requestDelete.ts → server/deleteSession.ts} +2 -1
- package/src/client/types/com/atproto/server/{getAccountsConfig.ts → describeServer.ts} +4 -3
- package/src/client/types/com/atproto/{session/get.ts → server/getSession.ts} +2 -1
- package/src/client/types/com/atproto/{session/refresh.ts → server/refreshSession.ts} +2 -1
- package/src/client/types/com/atproto/{session/delete.ts → server/requestAccountDelete.ts} +2 -1
- package/src/client/types/com/atproto/{account → server}/requestPasswordReset.ts +2 -1
- package/src/client/types/com/atproto/{account → server}/resetPassword.ts +2 -1
- package/src/client/types/com/atproto/sync/getBlob.ts +33 -0
- package/src/client/types/com/atproto/sync/getBlocks.ts +2 -1
- package/src/client/types/com/atproto/sync/getCheckout.ts +2 -1
- package/src/client/types/com/atproto/sync/getCommitPath.ts +2 -1
- package/src/client/types/com/atproto/sync/getHead.ts +2 -1
- package/src/client/types/com/atproto/sync/getRecord.ts +2 -1
- package/src/client/types/com/atproto/sync/getRepo.ts +2 -1
- package/src/client/types/com/atproto/sync/listBlobs.ts +40 -0
- package/src/client/types/com/atproto/sync/notifyOfUpdate.ts +6 -2
- package/src/client/types/com/atproto/sync/requestCrawl.ts +3 -2
- package/src/client/types/com/atproto/sync/subscribeRepos.ts +131 -0
- package/src/index.ts +12 -0
- package/src/rich-text/detection.ts +83 -0
- package/src/rich-text/rich-text.ts +401 -0
- package/src/rich-text/sanitization.ts +40 -0
- package/src/rich-text/unicode.ts +47 -0
- package/src/types.ts +2 -2
- package/tests/agent.test.ts +10 -6
- package/tests/bsky-agent.test.ts +140 -0
- package/tests/errors.test.ts +4 -4
- package/tests/rich-text-detection.test.ts +229 -0
- package/tests/rich-text-sanitization.test.ts +211 -0
- package/tests/rich-text.test.ts +661 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/src/client/types/app/bsky/actor/ref.ts +0 -64
- package/src/client/types/app/bsky/actor/updateProfile.ts +0 -71
- package/src/client/types/app/bsky/feed/feedViewPost.ts +0 -64
- package/src/client/types/app/bsky/feed/setVote.ts +0 -40
- package/src/client/types/app/bsky/graph/assertCreator.ts +0 -9
- package/src/client/types/app/bsky/graph/assertMember.ts +0 -9
- package/src/client/types/app/bsky/graph/assertion.ts +0 -27
- package/src/client/types/app/bsky/graph/confirmation.ts +0 -28
- package/src/client/types/app/bsky/system/actorUser.ts +0 -9
- package/src/client/types/app/bsky/system/declRef.ts +0 -26
- package/src/client/types/app/bsky/system/declaration.ts +0 -24
- package/src/client/types/com/atproto/account/get.ts +0 -26
- package/src/client/types/com/atproto/admin/blob.ts +0 -84
- package/src/client/types/com/atproto/admin/moderationAction.ts +0 -118
- package/src/client/types/com/atproto/admin/moderationReport.ts +0 -64
- package/src/client/types/com/atproto/admin/record.ts +0 -92
- package/src/client/types/com/atproto/admin/repo.ts +0 -103
- package/src/client/types/com/atproto/repo/recordRef.ts +0 -25
- package/src/client/types/com/atproto/repo/repoRef.ts +0 -24
- package/src/client/types/com/atproto/report/reasonType.ts +0 -16
- package/src/client/types/com/atproto/report/subject.ts +0 -66
- package/src/client/types/com/atproto/sync/subscribeAllRepos.ts +0 -7
package/README.md
CHANGED
|
@@ -1,32 +1,37 @@
|
|
|
1
1
|
# ATP API
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This API is a client for ATProtocol servers. It communicates using HTTP. It includes:
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
- ✔️ APIs for ATProto and Bluesky.
|
|
6
|
+
- ✔️ Validation and complete typescript types.
|
|
7
|
+
- ✔️ Session management.
|
|
8
|
+
- ✔️ A RichText library.
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
## Getting started
|
|
11
|
+
|
|
12
|
+
First install the package:
|
|
9
13
|
|
|
10
|
-
// provide a custom fetch implementation (shouldnt be needed in node or the browser)
|
|
11
|
-
import {AtpAgentFetchHeaders, AtpAgentFetchHandlerResponse} from '@atproto/api'
|
|
12
|
-
AtpAgent.configure({
|
|
13
|
-
async fetch(
|
|
14
|
-
httpUri: string,
|
|
15
|
-
httpMethod: string,
|
|
16
|
-
httpHeaders: AtpAgentFetchHeaders,
|
|
17
|
-
httpReqBody: any,
|
|
18
|
-
): Promise<AtpAgentFetchHandlerResponse> {
|
|
19
|
-
// insert definition here...
|
|
20
|
-
return {status: 200, /*...*/}
|
|
21
|
-
}
|
|
22
|
-
})
|
|
23
14
|
```
|
|
15
|
+
yarn add @atproto/api
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Then in your application:
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { BskyAgent } from '@atproto/api'
|
|
22
|
+
|
|
23
|
+
const agent = new BskyAgent({ service: 'https://example.com' })
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
24
27
|
|
|
25
28
|
### Session management
|
|
26
29
|
|
|
30
|
+
Log into a server or create accounts using these APIs. You'll need an active session for most methods.
|
|
31
|
+
|
|
27
32
|
```typescript
|
|
28
|
-
import
|
|
29
|
-
const agent = new
|
|
33
|
+
import { BskyAgent, AtpSessionEvent, AtpSessionData } from '@atproto/api'
|
|
34
|
+
const agent = new BskyAgent({
|
|
30
35
|
service: 'https://example.com',
|
|
31
36
|
persistSession: (evt: AtpSessionEvent, sess?: AtpSessionData) {
|
|
32
37
|
// store the session-data for reuse
|
|
@@ -44,9 +49,125 @@ await agent.createAccount({
|
|
|
44
49
|
|
|
45
50
|
### API calls
|
|
46
51
|
|
|
52
|
+
The agent includes methods for many common operations, including:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
// Feeds and content
|
|
56
|
+
await agent.getTimeline(params, opts)
|
|
57
|
+
await agent.getAuthorFeed(params, opts)
|
|
58
|
+
await agent.getPostThread(params, opts)
|
|
59
|
+
await agent.getPost(params)
|
|
60
|
+
await agent.getLikes(params, opts)
|
|
61
|
+
await agent.getRepostedBy(params, opts)
|
|
62
|
+
await agent.post(record)
|
|
63
|
+
await agent.deletePost(postUri)
|
|
64
|
+
await agent.like(uri, cid)
|
|
65
|
+
await agent.deleteLike(likeUri)
|
|
66
|
+
await agent.repost(uri, cid)
|
|
67
|
+
await agent.deleteRepost(repostUri)
|
|
68
|
+
await agent.uploadBlob(data, opts)
|
|
69
|
+
|
|
70
|
+
// Social graph
|
|
71
|
+
await agent.getFollows(params, opts)
|
|
72
|
+
await agent.getFollowers(params, opts)
|
|
73
|
+
await agent.follow(did)
|
|
74
|
+
await agent.deleteFollow(followUri)
|
|
75
|
+
|
|
76
|
+
// Actors
|
|
77
|
+
await agent.getProfile(params, opts)
|
|
78
|
+
await agent.upsertProfile(updateFn)
|
|
79
|
+
await agent.getProfiles(params, opts)
|
|
80
|
+
await agent.searchActors(params, opts)
|
|
81
|
+
await agent.searchActorsTypeahead(params, opts)
|
|
82
|
+
await agent.mute(did)
|
|
83
|
+
await agent.unmute(did)
|
|
84
|
+
|
|
85
|
+
// Notifications
|
|
86
|
+
await agent.listNotifications(params, opts)
|
|
87
|
+
await agent.countUnreadNotifications(params, opts)
|
|
88
|
+
await agent.updateSeenNotifications()
|
|
89
|
+
|
|
90
|
+
// Identity
|
|
91
|
+
await agent.resolveHandle(params, opts)
|
|
92
|
+
await agent.updateHandle(params, opts)
|
|
93
|
+
|
|
94
|
+
// Session management
|
|
95
|
+
await agent.createAccount(params)
|
|
96
|
+
await agent.login(params)
|
|
97
|
+
await agent.resumeSession(session)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Validation and types
|
|
101
|
+
|
|
102
|
+
The package includes a complete types system which includes validation and type-guards. For example, to validate a post record:
|
|
103
|
+
|
|
47
104
|
```typescript
|
|
48
|
-
|
|
49
|
-
|
|
105
|
+
import { AppBskyFeedPost } from '@atproto/api'
|
|
106
|
+
|
|
107
|
+
const post = {...}
|
|
108
|
+
if (AppBskyFeedPost.isRecord(post)) {
|
|
109
|
+
// typescript now recognizes `post` as a AppBskyFeedPost.Record
|
|
110
|
+
// however -- we still need to validate it
|
|
111
|
+
const res = AppBskyFeedPost.validateRecord(post)
|
|
112
|
+
if (res.success) {
|
|
113
|
+
// a valid record
|
|
114
|
+
} else {
|
|
115
|
+
// something is wrong
|
|
116
|
+
console.log(res.error)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Rich text
|
|
122
|
+
|
|
123
|
+
Some records (ie posts) use the `app.bsky.richtext` lexicon. At the moment richtext is only used for links and mentions, but it will be extended over time to include bold, italic, and so on.
|
|
124
|
+
|
|
125
|
+
ℹ️ It is **strongly** recommended to use this package's `RichText` library. Javascript encodes strings in utf16 while the protocol (and most other programming environments) use utf8. Converting between the two is challenging, but `RichText` handles that for you.
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import {RichText} from '@atproto/api'
|
|
129
|
+
|
|
130
|
+
// creating richtext
|
|
131
|
+
const rt = new RichText({text: 'Hello @alice.com, check out this link: https://example.com'})
|
|
132
|
+
await rt.detectFacets(agent) // automatically detects mentions and links
|
|
133
|
+
const postRecord = {
|
|
134
|
+
$type: 'app.bsky.feed.post',
|
|
135
|
+
text: rt.text,
|
|
136
|
+
facets: rt.facets,
|
|
137
|
+
createdAt: new Date().toISOString()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// rendering as markdown
|
|
141
|
+
let markdown = ''
|
|
142
|
+
for (const segment of rt.segments()) {
|
|
143
|
+
if (segment.isLink()) {
|
|
144
|
+
markdown += `[${segment.text}](${segment.link?.uri})`
|
|
145
|
+
} else if (segment.isMention()) {
|
|
146
|
+
markdown += `[${segment.text}](https://my-bsky-app.com/user/${segment.mention?.did})`
|
|
147
|
+
} else {
|
|
148
|
+
markdown += segment.text
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// calculating string lengths
|
|
153
|
+
const rt2 = new RichText({text: 'Hello'})
|
|
154
|
+
console.log(rt2.length) // => 5
|
|
155
|
+
console.log(rt2.graphemeLength) // => 5
|
|
156
|
+
const rt3 = new RichText({text: '👨👩👧👧'})
|
|
157
|
+
console.log(rt3.length) // => 25
|
|
158
|
+
console.log(rt3.graphemeLength) // => 1
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Advanced
|
|
162
|
+
|
|
163
|
+
### Advanced API calls
|
|
164
|
+
|
|
165
|
+
The methods above are convenience wrappers. It covers most but not all available methods.
|
|
166
|
+
|
|
167
|
+
The AT Protocol identifies methods and records with reverse-DNS names. You can use them on the agent as well:
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
const res1 = await agent.com.atproto.repo.createRecord(
|
|
50
171
|
{
|
|
51
172
|
did: alice.did,
|
|
52
173
|
collection: 'app.bsky.feed.post',
|
|
@@ -57,14 +178,47 @@ const res1 = await agent.api.com.atproto.repo.createRecord(
|
|
|
57
178
|
}
|
|
58
179
|
}
|
|
59
180
|
)
|
|
60
|
-
const res2 = await agent.
|
|
181
|
+
const res2 = await agent.com.atproto.repo.listRecords({user: alice.did, collection: 'app.bsky.feed.post'})
|
|
61
182
|
|
|
62
|
-
|
|
63
|
-
const res3 = await agent.api.app.bsky.feed.post.create({did: alice.did}, {
|
|
183
|
+
const res3 = await agent.app.bsky.feed.post.create({did: alice.did}, {
|
|
64
184
|
text: 'Hello, world!',
|
|
65
185
|
createdAt: (new Date()).toISOString()
|
|
66
186
|
})
|
|
67
|
-
const res4 = await agent.
|
|
187
|
+
const res4 = await agent.app.bsky.feed.post.list({did: alice.did})
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Generic agent
|
|
191
|
+
|
|
192
|
+
If you want a generic AT Protocol agent without methods related to the Bluesky social lexicon, use the `AtpAgent` instead of the `BskyAgent`.
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
import { AtpAgent } from '@atproto/api'
|
|
196
|
+
|
|
197
|
+
const agent = new AtpAgent({service: 'https://example.com'})
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Non-browser configuration
|
|
201
|
+
|
|
202
|
+
In non-browser environments you'll need to specify a fetch polyfill. [See the example react-native polyfill here.](./docs/rn-fetch-handler.ts)
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import { BskyAgent } from '@atproto/api'
|
|
206
|
+
|
|
207
|
+
const agent = new BskyAgent({service: 'https://example.com'})
|
|
208
|
+
|
|
209
|
+
// provide a custom fetch implementation (shouldnt be needed in node or the browser)
|
|
210
|
+
import {AtpAgentFetchHeaders, AtpAgentFetchHandlerResponse} from '@atproto/api'
|
|
211
|
+
BskyAgent.configure({
|
|
212
|
+
async fetch(
|
|
213
|
+
httpUri: string,
|
|
214
|
+
httpMethod: string,
|
|
215
|
+
httpHeaders: AtpAgentFetchHeaders,
|
|
216
|
+
httpReqBody: any,
|
|
217
|
+
): Promise<AtpAgentFetchHandlerResponse> {
|
|
218
|
+
// insert definition here...
|
|
219
|
+
return {status: 200, /*...*/}
|
|
220
|
+
}
|
|
221
|
+
})
|
|
68
222
|
```
|
|
69
223
|
|
|
70
224
|
## License
|
package/build.js
CHANGED
package/dist/agent.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AtpServiceClient,
|
|
2
|
-
import { AtpSessionData, AtpAgentCreateAccountOpts, AtpAgentLoginOpts,
|
|
1
|
+
import { AtpServiceClient, ComAtprotoServerCreateAccount, ComAtprotoServerCreateSession, ComAtprotoServerGetSession } from './client';
|
|
2
|
+
import { AtpSessionData, AtpAgentCreateAccountOpts, AtpAgentLoginOpts, AtpAgentFetchHandler, AtpAgentGlobalOpts, AtpPersistSessionHandler, AtpAgentOpts } from './types';
|
|
3
3
|
export declare class AtpAgent {
|
|
4
4
|
service: URL;
|
|
5
5
|
api: AtpServiceClient;
|
|
@@ -7,16 +7,21 @@ export declare class AtpAgent {
|
|
|
7
7
|
private _baseClient;
|
|
8
8
|
private _persistSession?;
|
|
9
9
|
private _refreshSessionPromise;
|
|
10
|
-
|
|
10
|
+
get com(): import("./client").ComNS;
|
|
11
|
+
static fetch: AtpAgentFetchHandler | undefined;
|
|
11
12
|
static configure(opts: AtpAgentGlobalOpts): void;
|
|
12
13
|
constructor(opts: AtpAgentOpts);
|
|
13
14
|
get hasSession(): boolean;
|
|
14
15
|
setPersistSessionHandler(handler?: AtpPersistSessionHandler): void;
|
|
15
|
-
createAccount(opts: AtpAgentCreateAccountOpts): Promise<
|
|
16
|
-
login(opts: AtpAgentLoginOpts): Promise<
|
|
17
|
-
resumeSession(session: AtpSessionData): Promise<
|
|
16
|
+
createAccount(opts: AtpAgentCreateAccountOpts): Promise<ComAtprotoServerCreateAccount.Response>;
|
|
17
|
+
login(opts: AtpAgentLoginOpts): Promise<ComAtprotoServerCreateSession.Response>;
|
|
18
|
+
resumeSession(session: AtpSessionData): Promise<ComAtprotoServerGetSession.Response>;
|
|
18
19
|
private _addAuthHeader;
|
|
19
20
|
private _fetch;
|
|
20
21
|
private _refreshSession;
|
|
21
22
|
private _refreshSessionInner;
|
|
23
|
+
uploadBlob: typeof this.api.com.atproto.repo.uploadBlob;
|
|
24
|
+
resolveHandle: typeof this.api.com.atproto.identity.resolveHandle;
|
|
25
|
+
updateHandle: typeof this.api.com.atproto.identity.updateHandle;
|
|
26
|
+
createModerationReport: typeof this.api.com.atproto.moderation.createReport;
|
|
22
27
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AtpAgent } from './agent';
|
|
2
|
+
import { AppBskyFeedPost, AppBskyActorProfile } from './client';
|
|
3
|
+
export declare class BskyAgent extends AtpAgent {
|
|
4
|
+
get app(): import("./client").AppNS;
|
|
5
|
+
getTimeline: typeof this.api.app.bsky.feed.getTimeline;
|
|
6
|
+
getAuthorFeed: typeof this.api.app.bsky.feed.getAuthorFeed;
|
|
7
|
+
getPostThread: typeof this.api.app.bsky.feed.getPostThread;
|
|
8
|
+
getPost: typeof this.api.app.bsky.feed.post.get;
|
|
9
|
+
getLikes: typeof this.api.app.bsky.feed.getLikes;
|
|
10
|
+
getRepostedBy: typeof this.api.app.bsky.feed.getRepostedBy;
|
|
11
|
+
getFollows: typeof this.api.app.bsky.graph.getFollows;
|
|
12
|
+
getFollowers: typeof this.api.app.bsky.graph.getFollowers;
|
|
13
|
+
getProfile: typeof this.api.app.bsky.actor.getProfile;
|
|
14
|
+
getProfiles: typeof this.api.app.bsky.actor.getProfiles;
|
|
15
|
+
searchActors: typeof this.api.app.bsky.actor.searchActors;
|
|
16
|
+
searchActorsTypeahead: typeof this.api.app.bsky.actor.searchActorsTypeahead;
|
|
17
|
+
listNotifications: typeof this.api.app.bsky.notification.listNotifications;
|
|
18
|
+
countUnreadNotifications: typeof this.api.app.bsky.notification.getUnreadCount;
|
|
19
|
+
post(record: Partial<AppBskyFeedPost.Record> & Omit<AppBskyFeedPost.Record, 'createdAt'>): Promise<{
|
|
20
|
+
uri: string;
|
|
21
|
+
cid: string;
|
|
22
|
+
}>;
|
|
23
|
+
deletePost(postUri: string): Promise<void>;
|
|
24
|
+
like(uri: string, cid: string): Promise<{
|
|
25
|
+
uri: string;
|
|
26
|
+
cid: string;
|
|
27
|
+
}>;
|
|
28
|
+
deleteLike(likeUri: string): Promise<void>;
|
|
29
|
+
repost(uri: string, cid: string): Promise<{
|
|
30
|
+
uri: string;
|
|
31
|
+
cid: string;
|
|
32
|
+
}>;
|
|
33
|
+
deleteRepost(repostUri: string): Promise<void>;
|
|
34
|
+
follow(subjectDid: string): Promise<{
|
|
35
|
+
uri: string;
|
|
36
|
+
cid: string;
|
|
37
|
+
}>;
|
|
38
|
+
deleteFollow(followUri: string): Promise<void>;
|
|
39
|
+
upsertProfile(updateFn: (existing: AppBskyActorProfile.Record | undefined) => AppBskyActorProfile.Record | Promise<AppBskyActorProfile.Record>): Promise<void>;
|
|
40
|
+
mute(actor: string): Promise<import("./client/types/app/bsky/graph/muteActor").Response>;
|
|
41
|
+
unmute(actor: string): Promise<import("./client/types/app/bsky/graph/unmuteActor").Response>;
|
|
42
|
+
updateSeenNotifications(seenAt?: string): Promise<import("./client/types/app/bsky/notification/updateSeen").Response>;
|
|
43
|
+
}
|