@atproto/api 0.1.3 → 0.2.1

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.
Files changed (208) hide show
  1. package/README.md +179 -25
  2. package/build.js +2 -1
  3. package/dist/agent.d.ts +11 -6
  4. package/dist/bsky-agent.d.ts +43 -0
  5. package/dist/client/index.d.ts +117 -215
  6. package/dist/client/lexicons.d.ts +1447 -1401
  7. package/dist/client/types/app/bsky/actor/defs.d.ts +47 -0
  8. package/dist/client/types/app/bsky/actor/getProfile.d.ts +2 -2
  9. package/dist/client/types/app/bsky/actor/getProfiles.d.ts +2 -2
  10. package/dist/client/types/app/bsky/actor/getSuggestions.d.ts +2 -2
  11. package/dist/client/types/app/bsky/actor/profile.d.ts +4 -60
  12. package/dist/client/types/app/bsky/actor/searchActors.d.ts +22 -0
  13. package/dist/client/types/app/bsky/actor/searchActorsTypeahead.d.ts +20 -0
  14. package/dist/client/types/app/bsky/embed/complexRecord.d.ts +24 -0
  15. package/dist/client/types/app/bsky/embed/external.d.ts +9 -13
  16. package/dist/client/types/app/bsky/embed/images.d.ts +9 -13
  17. package/dist/client/types/app/bsky/embed/post.d.ts +33 -0
  18. package/dist/client/types/app/bsky/embed/record.d.ts +21 -13
  19. package/dist/client/types/app/bsky/embed/recordWithMedia.d.ts +24 -0
  20. package/dist/client/types/app/bsky/feed/defs.d.ts +77 -0
  21. package/dist/client/types/app/bsky/feed/getAuthorFeed.d.ts +4 -4
  22. package/dist/client/types/app/bsky/{graph/getMembers.d.ts → feed/getLikes.d.ts} +12 -14
  23. package/dist/client/types/app/bsky/feed/getPostThread.d.ts +2 -24
  24. package/dist/client/types/app/bsky/feed/getRepostedBy.d.ts +3 -3
  25. package/dist/client/types/app/bsky/feed/getTimeline.d.ts +3 -3
  26. package/dist/client/types/app/bsky/feed/post.d.ts +4 -29
  27. package/dist/client/types/app/bsky/graph/follow.d.ts +1 -2
  28. package/dist/client/types/app/bsky/graph/getFollowers.d.ts +5 -5
  29. package/dist/client/types/app/bsky/graph/getFollows.d.ts +5 -5
  30. package/dist/client/types/app/bsky/graph/getMutes.d.ts +3 -3
  31. package/dist/client/types/app/bsky/{notification/updateSeen.d.ts → graph/muteActor.d.ts} +1 -1
  32. package/dist/client/types/app/bsky/graph/unmuteActor.d.ts +17 -0
  33. package/dist/client/types/app/bsky/notification/getUnreadCount.d.ts +17 -0
  34. package/dist/client/types/app/bsky/{graph/getMemberships.d.ts → notification/listNotifications.d.ts} +13 -14
  35. package/dist/client/types/app/bsky/richtext/facet.d.ts +30 -0
  36. package/dist/client/types/app/bsky/unspecced/getPopular.d.ts +21 -0
  37. package/dist/client/types/com/atproto/admin/defs.d.ts +181 -0
  38. package/dist/client/types/com/atproto/admin/getModerationAction.d.ts +2 -2
  39. package/dist/client/types/com/atproto/admin/getModerationActions.d.ts +3 -3
  40. package/dist/client/types/com/atproto/admin/getModerationReport.d.ts +2 -2
  41. package/dist/client/types/com/atproto/admin/getModerationReports.d.ts +3 -3
  42. package/dist/client/types/com/atproto/admin/getRecord.d.ts +2 -2
  43. package/dist/client/types/com/atproto/admin/getRepo.d.ts +2 -2
  44. package/dist/client/types/com/atproto/admin/resolveModerationReports.d.ts +2 -2
  45. package/dist/client/types/com/atproto/admin/reverseModerationAction.d.ts +2 -2
  46. package/dist/client/types/com/atproto/admin/searchRepos.d.ts +3 -3
  47. package/dist/client/types/com/atproto/admin/takeModerationAction.d.ts +5 -6
  48. package/dist/client/types/com/atproto/{sync/getHead.d.ts → identity/resolveHandle.d.ts} +2 -2
  49. package/dist/client/types/com/atproto/identity/updateHandle.d.ts +17 -0
  50. package/dist/client/types/com/atproto/moderation/createReport.d.ts +38 -0
  51. package/dist/client/types/com/atproto/moderation/defs.d.ts +3 -0
  52. package/dist/client/types/com/atproto/repo/applyWrites.d.ts +47 -0
  53. package/dist/client/types/com/atproto/repo/createRecord.d.ts +7 -2
  54. package/dist/client/types/com/atproto/repo/deleteRecord.d.ts +7 -2
  55. package/dist/client/types/com/atproto/repo/describeRepo.d.ts +22 -0
  56. package/dist/client/types/com/atproto/repo/getRecord.d.ts +1 -1
  57. package/dist/client/types/com/atproto/repo/listRecords.d.ts +3 -3
  58. package/dist/client/types/com/atproto/repo/putRecord.d.ts +7 -2
  59. package/dist/client/types/com/atproto/repo/uploadBlob.d.ts +20 -0
  60. package/dist/client/types/{app/bsky/actor/createScene.d.ts → com/atproto/server/createAccount.d.ts} +14 -2
  61. package/dist/client/types/com/atproto/server/createInviteCode.d.ts +22 -0
  62. package/dist/client/types/com/atproto/server/createSession.d.ts +29 -0
  63. package/dist/client/types/com/atproto/server/deleteAccount.d.ts +25 -0
  64. package/dist/client/types/com/atproto/{sync/getRecord.d.ts → server/deleteSession.d.ts} +1 -5
  65. package/dist/client/types/com/atproto/server/describeServer.d.ts +27 -0
  66. package/dist/client/types/com/atproto/{sync/getRoot.d.ts → server/getSession.d.ts} +2 -2
  67. package/dist/client/types/com/atproto/server/refreshSession.d.ts +24 -0
  68. package/dist/client/types/com/atproto/{sync/updateRepo.d.ts → server/requestAccountDelete.d.ts} +1 -3
  69. package/dist/client/types/com/atproto/server/requestPasswordReset.d.ts +17 -0
  70. package/dist/client/types/com/atproto/server/resetPassword.d.ts +24 -0
  71. package/dist/client/types/com/atproto/sync/{getCheckout.d.ts → getBlob.d.ts} +1 -1
  72. package/dist/client/types/com/atproto/sync/{getCommitPath.d.ts → listBlobs.d.ts} +1 -1
  73. package/dist/client/types/com/atproto/sync/notifyOfUpdate.d.ts +1 -0
  74. package/dist/client/types/com/atproto/sync/requestCrawl.d.ts +1 -1
  75. package/dist/client/types/com/atproto/sync/subscribeAllRepos.d.ts +9 -1
  76. package/dist/client/types/com/atproto/sync/subscribeRepos.d.ts +58 -0
  77. package/dist/index.d.ts +6 -0
  78. package/dist/index.js +8055 -3651
  79. package/dist/index.js.map +4 -4
  80. package/dist/rich-text/detection.d.ts +4 -0
  81. package/dist/rich-text/rich-text.d.ts +39 -0
  82. package/dist/rich-text/sanitization.d.ts +4 -0
  83. package/dist/rich-text/unicode.d.ts +11 -0
  84. package/dist/types.d.ts +2 -2
  85. package/docs/rn-fetch-handler.ts +88 -0
  86. package/package.json +4 -1
  87. package/src/agent.ts +51 -15
  88. package/src/bsky-agent.ts +228 -0
  89. package/src/client/index.ts +330 -581
  90. package/src/client/lexicons.ts +1833 -1779
  91. package/src/client/types/app/bsky/actor/defs.ts +97 -0
  92. package/src/client/types/app/bsky/actor/getProfile.ts +4 -3
  93. package/src/client/types/app/bsky/actor/getProfiles.ts +4 -3
  94. package/src/client/types/app/bsky/actor/getSuggestions.ts +4 -3
  95. package/src/client/types/app/bsky/actor/profile.ts +5 -95
  96. package/src/client/types/app/bsky/actor/{searchTypeahead.ts → searchActors.ts} +6 -3
  97. package/src/client/types/app/bsky/actor/{search.ts → searchActorsTypeahead.ts} +4 -5
  98. package/src/client/types/app/bsky/embed/external.ts +14 -13
  99. package/src/client/types/app/bsky/embed/images.ts +14 -15
  100. package/src/client/types/app/bsky/embed/record.ts +32 -25
  101. package/src/client/types/app/bsky/embed/recordWithMedia.ts +53 -0
  102. package/src/client/types/app/bsky/feed/defs.ts +156 -0
  103. package/src/client/types/app/bsky/feed/getAuthorFeed.ts +6 -5
  104. package/src/client/types/app/bsky/feed/{getVotes.ts → getLikes.ts} +11 -12
  105. package/src/client/types/app/bsky/feed/getPostThread.ts +5 -48
  106. package/src/client/types/app/bsky/feed/getRepostedBy.ts +5 -4
  107. package/src/client/types/app/bsky/feed/getTimeline.ts +5 -4
  108. package/src/client/types/app/bsky/feed/{vote.ts → like.ts} +4 -4
  109. package/src/client/types/app/bsky/feed/post.ts +10 -52
  110. package/src/client/types/app/bsky/feed/repost.ts +2 -1
  111. package/src/client/types/app/bsky/graph/follow.ts +3 -3
  112. package/src/client/types/app/bsky/graph/getFollowers.ts +7 -6
  113. package/src/client/types/app/bsky/graph/getFollows.ts +7 -6
  114. package/src/client/types/app/bsky/graph/getMutes.ts +5 -4
  115. package/src/client/types/app/bsky/graph/{mute.ts → muteActor.ts} +3 -2
  116. package/src/client/types/app/bsky/graph/{unmute.ts → unmuteActor.ts} +3 -2
  117. package/src/client/types/app/bsky/notification/{getCount.ts → getUnreadCount.ts} +2 -1
  118. package/src/client/types/app/bsky/notification/{list.ts → listNotifications.ts} +13 -9
  119. package/src/client/types/app/bsky/notification/updateSeen.ts +2 -1
  120. package/src/client/types/app/bsky/richtext/facet.ts +81 -0
  121. package/src/client/types/app/bsky/unspecced/getPopular.ts +38 -0
  122. package/src/client/types/com/atproto/admin/defs.ts +366 -0
  123. package/src/client/types/com/atproto/admin/getModerationAction.ts +4 -3
  124. package/src/client/types/com/atproto/admin/getModerationActions.ts +5 -4
  125. package/src/client/types/com/atproto/admin/getModerationReport.ts +4 -3
  126. package/src/client/types/com/atproto/admin/getModerationReports.ts +5 -4
  127. package/src/client/types/com/atproto/admin/getRecord.ts +4 -3
  128. package/src/client/types/com/atproto/admin/getRepo.ts +4 -3
  129. package/src/client/types/com/atproto/admin/resolveModerationReports.ts +4 -3
  130. package/src/client/types/com/atproto/admin/reverseModerationAction.ts +4 -3
  131. package/src/client/types/com/atproto/admin/searchRepos.ts +5 -4
  132. package/src/client/types/com/atproto/admin/takeModerationAction.ts +10 -10
  133. package/src/client/types/com/atproto/{handle/resolve.ts → identity/resolveHandle.ts} +2 -1
  134. package/src/client/types/com/atproto/{handle/update.ts → identity/updateHandle.ts} +2 -1
  135. package/src/client/types/com/atproto/{report/create.ts → moderation/createReport.ts} +10 -10
  136. package/src/client/types/com/atproto/moderation/defs.ts +17 -0
  137. package/src/client/types/com/atproto/repo/{batchWrite.ts → applyWrites.ts} +21 -12
  138. package/src/client/types/com/atproto/repo/createRecord.ts +15 -3
  139. package/src/client/types/com/atproto/repo/deleteRecord.ts +15 -3
  140. package/src/client/types/com/atproto/repo/{describe.ts → describeRepo.ts} +3 -2
  141. package/src/client/types/com/atproto/repo/getRecord.ts +4 -3
  142. package/src/client/types/com/atproto/repo/listRecords.ts +7 -6
  143. package/src/client/types/com/atproto/repo/putRecord.ts +18 -6
  144. package/src/client/types/com/atproto/repo/strongRef.ts +2 -1
  145. package/src/client/types/com/atproto/{blob/upload.ts → repo/uploadBlob.ts} +3 -2
  146. package/src/client/types/com/atproto/{account/create.ts → server/createAccount.ts} +9 -1
  147. package/src/client/types/com/atproto/{account → server}/createInviteCode.ts +2 -1
  148. package/src/client/types/com/atproto/{session/create.ts → server/createSession.ts} +2 -1
  149. package/src/client/types/com/atproto/{account/delete.ts → server/deleteAccount.ts} +2 -1
  150. package/src/client/types/com/atproto/{account/requestDelete.ts → server/deleteSession.ts} +2 -1
  151. package/src/client/types/com/atproto/server/{getAccountsConfig.ts → describeServer.ts} +4 -3
  152. package/src/client/types/com/atproto/{session/get.ts → server/getSession.ts} +2 -1
  153. package/src/client/types/com/atproto/{session/refresh.ts → server/refreshSession.ts} +2 -1
  154. package/src/client/types/com/atproto/{session/delete.ts → server/requestAccountDelete.ts} +2 -1
  155. package/src/client/types/com/atproto/{account → server}/requestPasswordReset.ts +2 -1
  156. package/src/client/types/com/atproto/{account → server}/resetPassword.ts +2 -1
  157. package/src/client/types/com/atproto/sync/getBlob.ts +33 -0
  158. package/src/client/types/com/atproto/sync/getBlocks.ts +2 -1
  159. package/src/client/types/com/atproto/sync/getCheckout.ts +2 -1
  160. package/src/client/types/com/atproto/sync/getCommitPath.ts +2 -1
  161. package/src/client/types/com/atproto/sync/getHead.ts +2 -1
  162. package/src/client/types/com/atproto/sync/getRecord.ts +2 -1
  163. package/src/client/types/com/atproto/sync/getRepo.ts +2 -1
  164. package/src/client/types/com/atproto/sync/listBlobs.ts +40 -0
  165. package/src/client/types/com/atproto/sync/notifyOfUpdate.ts +6 -2
  166. package/src/client/types/com/atproto/sync/requestCrawl.ts +3 -2
  167. package/src/client/types/com/atproto/sync/subscribeRepos.ts +131 -0
  168. package/src/index.ts +12 -0
  169. package/src/rich-text/detection.ts +83 -0
  170. package/src/rich-text/rich-text.ts +401 -0
  171. package/src/rich-text/sanitization.ts +40 -0
  172. package/src/rich-text/unicode.ts +47 -0
  173. package/src/types.ts +2 -2
  174. package/tests/agent.test.ts +10 -6
  175. package/tests/bsky-agent.test.ts +140 -0
  176. package/tests/errors.test.ts +4 -4
  177. package/tests/rich-text-detection.test.ts +229 -0
  178. package/tests/rich-text-sanitization.test.ts +211 -0
  179. package/tests/rich-text.test.ts +661 -0
  180. package/tsconfig.build.tsbuildinfo +1 -1
  181. package/dist/client/types/app/bsky/feed/trend.d.ts +0 -9
  182. package/dist/client/types/app/bsky/graph/getAssertions.d.ts +0 -48
  183. package/dist/client/types/app/bsky/system/actorScene.d.ts +0 -1
  184. package/dist/client/types/com/atproto/repo/strongRef.d.ts +0 -8
  185. package/dist/client/util.d.ts +0 -2
  186. package/src/client/types/app/bsky/actor/ref.ts +0 -64
  187. package/src/client/types/app/bsky/actor/updateProfile.ts +0 -71
  188. package/src/client/types/app/bsky/feed/feedViewPost.ts +0 -64
  189. package/src/client/types/app/bsky/feed/setVote.ts +0 -40
  190. package/src/client/types/app/bsky/graph/assertCreator.ts +0 -9
  191. package/src/client/types/app/bsky/graph/assertMember.ts +0 -9
  192. package/src/client/types/app/bsky/graph/assertion.ts +0 -27
  193. package/src/client/types/app/bsky/graph/confirmation.ts +0 -28
  194. package/src/client/types/app/bsky/system/actorUser.ts +0 -9
  195. package/src/client/types/app/bsky/system/declRef.ts +0 -26
  196. package/src/client/types/app/bsky/system/declaration.ts +0 -24
  197. package/src/client/types/com/atproto/account/get.ts +0 -26
  198. package/src/client/types/com/atproto/admin/blob.ts +0 -84
  199. package/src/client/types/com/atproto/admin/moderationAction.ts +0 -118
  200. package/src/client/types/com/atproto/admin/moderationReport.ts +0 -64
  201. package/src/client/types/com/atproto/admin/record.ts +0 -92
  202. package/src/client/types/com/atproto/admin/repo.ts +0 -103
  203. package/src/client/types/com/atproto/repo/recordRef.ts +0 -25
  204. package/src/client/types/com/atproto/repo/repoRef.ts +0 -24
  205. package/src/client/types/com/atproto/report/reasonType.ts +0 -16
  206. package/src/client/types/com/atproto/report/subject.ts +0 -66
  207. package/src/client/types/com/atproto/sync/subscribeAllRepos.ts +0 -7
  208. /package/dist/client/types/app/bsky/feed/{repost.d.ts → like.d.ts} +0 -0
package/README.md CHANGED
@@ -1,32 +1,37 @@
1
1
  # ATP API
2
2
 
3
- ## Usage
3
+ This API is a client for ATProtocol servers. It communicates using HTTP. It includes:
4
4
 
5
- ```typescript
6
- import AtpAgent from '@atproto/api'
5
+ - ✔️ APIs for ATProto and Bluesky.
6
+ - ✔️ Validation and complete typescript types.
7
+ - ✔️ Session management.
8
+ - ✔️ A RichText library.
7
9
 
8
- const agent = new AtpAgent({service: 'https://example.com'})
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 AtpAgent, {AtpSessionEvent, AtpSessionData} from '@atproto/api'
29
- const agent = new AtpAgent({
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
- // xrpc methods
49
- const res1 = await agent.api.com.atproto.repo.createRecord(
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.api.com.atproto.repo.listRecords({did: alice.did, type: 'app.bsky.feed.post'})
181
+ const res2 = await agent.com.atproto.repo.listRecords({user: alice.did, collection: 'app.bsky.feed.post'})
61
182
 
62
- // repo record methods
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.api.app.bsky.feed.post.list({did: alice.did})
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
@@ -17,6 +17,7 @@ require('esbuild').build({
17
17
  bundle: true,
18
18
  sourcemap: true,
19
19
  outdir: 'dist',
20
- platform: 'node',
20
+ platform: 'browser',
21
+ format: 'cjs',
21
22
  plugins: buildShallow ? [nodeExternalsPlugin()] : [],
22
23
  })
package/dist/agent.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { AtpServiceClient, ComAtprotoAccountCreate, ComAtprotoSessionCreate, ComAtprotoSessionGet } from './client';
2
- import { AtpSessionData, AtpAgentCreateAccountOpts, AtpAgentLoginOpts, AptAgentFetchHandler, AtpAgentGlobalOpts, AtpPersistSessionHandler, AtpAgentOpts } from './types';
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
- static fetch: AptAgentFetchHandler | undefined;
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<ComAtprotoAccountCreate.Response>;
16
- login(opts: AtpAgentLoginOpts): Promise<ComAtprotoSessionCreate.Response>;
17
- resumeSession(session: AtpSessionData): Promise<ComAtprotoSessionGet.Response>;
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
+ }