@atproto/bsky 0.0.11 → 0.0.13
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/CHANGELOG.md +29 -0
- package/LICENSE.txt +7 -0
- package/README.md +6 -1
- package/dist/api/com/atproto/admin/util.d.ts +5 -0
- package/dist/context.d.ts +6 -1
- package/dist/db/index.js +51 -2
- package/dist/db/index.js.map +3 -3
- package/dist/db/migrations/20230929T192920807Z-record-cursor-indexes.d.ts +3 -0
- package/dist/db/migrations/index.d.ts +1 -0
- package/dist/did-cache.d.ts +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1630 -755
- package/dist/index.js.map +3 -3
- package/dist/lexicon/index.d.ts +8 -0
- package/dist/lexicon/lexicons.d.ts +243 -3
- package/dist/lexicon/types/app/bsky/actor/defs.d.ts +1 -0
- package/dist/lexicon/types/com/atproto/admin/defs.d.ts +28 -0
- package/dist/lexicon/types/com/atproto/admin/getAccountInfo.d.ts +29 -0
- package/dist/lexicon/types/com/atproto/admin/getSubjectStatus.d.ts +39 -0
- package/dist/lexicon/types/com/atproto/admin/searchRepos.d.ts +0 -1
- package/dist/lexicon/types/com/atproto/admin/updateSubjectStatus.d.ts +46 -0
- package/dist/lexicon/types/com/atproto/server/createAccount.d.ts +4 -2
- package/dist/lexicon/types/com/atproto/server/createSession.d.ts +1 -0
- package/dist/lexicon/types/com/atproto/server/refreshSession.d.ts +1 -0
- package/dist/lexicon/types/com/atproto/server/reserveSigningKey.d.ts +36 -0
- package/dist/lexicon/types/com/atproto/sync/listRepos.d.ts +1 -0
- package/dist/services/actor/types.d.ts +1 -0
- package/dist/services/graph/index.d.ts +2 -0
- package/dist/services/moderation/index.d.ts +13 -3
- package/package.json +14 -15
- package/src/api/app/bsky/feed/getAuthorFeed.ts +2 -2
- package/src/api/app/bsky/feed/getPostThread.ts +2 -2
- package/src/api/app/bsky/notification/listNotifications.ts +33 -22
- package/src/api/com/atproto/admin/getModerationAction.ts +28 -2
- package/src/api/com/atproto/admin/getModerationReport.ts +27 -2
- package/src/api/com/atproto/admin/getRecord.ts +14 -2
- package/src/api/com/atproto/admin/getRepo.ts +13 -2
- package/src/api/com/atproto/admin/reverseModerationAction.ts +31 -5
- package/src/api/com/atproto/admin/searchRepos.ts +2 -5
- package/src/api/com/atproto/admin/takeModerationAction.ts +41 -7
- package/src/api/com/atproto/admin/util.ts +50 -0
- package/src/api/well-known.ts +8 -0
- package/src/auth.ts +12 -5
- package/src/auto-moderator/index.ts +1 -0
- package/src/context.ts +25 -1
- package/src/db/migrations/20230929T192920807Z-record-cursor-indexes.ts +40 -0
- package/src/db/migrations/index.ts +1 -0
- package/src/did-cache.ts +29 -14
- package/src/feed-gen/with-friends.ts +2 -2
- package/src/index.ts +4 -1
- package/src/indexer/subscription.ts +1 -21
- package/src/lexicon/index.ts +48 -0
- package/src/lexicon/lexicons.ts +259 -5
- package/src/lexicon/types/app/bsky/actor/defs.ts +1 -0
- package/src/lexicon/types/com/atproto/admin/defs.ts +61 -0
- package/src/lexicon/types/com/atproto/admin/getAccountInfo.ts +41 -0
- package/src/lexicon/types/com/atproto/admin/getSubjectStatus.ts +54 -0
- package/src/lexicon/types/com/atproto/admin/searchRepos.ts +0 -1
- package/src/lexicon/types/com/atproto/admin/updateSubjectStatus.ts +61 -0
- package/src/lexicon/types/com/atproto/server/createAccount.ts +4 -2
- package/src/lexicon/types/com/atproto/server/createSession.ts +1 -0
- package/src/lexicon/types/com/atproto/server/refreshSession.ts +1 -0
- package/src/lexicon/types/com/atproto/server/reserveSigningKey.ts +51 -0
- package/src/lexicon/types/com/atproto/sync/listRepos.ts +1 -0
- package/src/logger.ts +8 -0
- package/src/services/actor/index.ts +7 -1
- package/src/services/actor/types.ts +1 -0
- package/src/services/actor/views.ts +26 -8
- package/src/services/graph/index.ts +26 -7
- package/src/services/indexing/index.ts +15 -17
- package/src/services/moderation/index.ts +94 -14
- package/src/services/moderation/views.ts +1 -0
- package/tests/__snapshots__/feed-generation.test.ts.snap +12 -12
- package/tests/__snapshots__/indexing.test.ts.snap +4 -4
- package/tests/admin/__snapshots__/get-moderation-action.test.ts.snap +172 -0
- package/tests/admin/__snapshots__/get-moderation-actions.test.ts.snap +178 -0
- package/tests/admin/__snapshots__/get-moderation-report.test.ts.snap +177 -0
- package/tests/admin/__snapshots__/get-moderation-reports.test.ts.snap +307 -0
- package/tests/admin/__snapshots__/get-record.test.ts.snap +275 -0
- package/tests/admin/__snapshots__/get-repo.test.ts.snap +103 -0
- package/tests/admin/get-moderation-action.test.ts +100 -0
- package/tests/admin/get-moderation-actions.test.ts +164 -0
- package/tests/admin/get-moderation-report.test.ts +100 -0
- package/tests/admin/get-moderation-reports.test.ts +332 -0
- package/tests/admin/get-record.test.ts +115 -0
- package/tests/admin/get-repo.test.ts +101 -0
- package/tests/{moderation.test.ts → admin/moderation.test.ts} +107 -9
- package/tests/admin/repo-search.test.ts +124 -0
- package/tests/algos/hot-classic.test.ts +3 -5
- package/tests/algos/whats-hot.test.ts +3 -5
- package/tests/algos/with-friends.test.ts +2 -4
- package/tests/auth.test.ts +64 -0
- package/tests/auto-moderator/fuzzy-matcher.test.ts +2 -3
- package/tests/auto-moderator/labeler.test.ts +5 -7
- package/tests/auto-moderator/takedowns.test.ts +11 -12
- package/tests/blob-resolver.test.ts +1 -3
- package/tests/did-cache.test.ts +2 -5
- package/tests/feed-generation.test.ts +8 -6
- package/tests/handle-invalidation.test.ts +2 -3
- package/tests/image/server.test.ts +1 -4
- package/tests/image/sharp.test.ts +1 -1
- package/tests/indexing.test.ts +4 -4
- package/tests/notification-server.test.ts +2 -3
- package/tests/pipeline/backpressure.test.ts +2 -3
- package/tests/pipeline/reingest.test.ts +7 -4
- package/tests/pipeline/repartition.test.ts +2 -3
- package/tests/reprocessing.test.ts +2 -6
- package/tests/seeds/basic.ts +4 -4
- package/tests/seeds/follows.ts +1 -1
- package/tests/seeds/likes.ts +1 -1
- package/tests/seeds/reposts.ts +1 -1
- package/tests/seeds/users-bulk.ts +1 -1
- package/tests/seeds/users.ts +1 -1
- package/tests/server.test.ts +1 -3
- package/tests/subscription/repo.test.ts +2 -4
- package/tests/views/__snapshots__/author-feed.test.ts.snap +24 -24
- package/tests/views/__snapshots__/block-lists.test.ts.snap +42 -7
- package/tests/views/__snapshots__/blocks.test.ts.snap +2 -2
- package/tests/views/__snapshots__/list-feed.test.ts.snap +6 -6
- package/tests/views/__snapshots__/mute-lists.test.ts.snap +15 -4
- package/tests/views/__snapshots__/mutes.test.ts.snap +2 -2
- package/tests/views/__snapshots__/notifications.test.ts.snap +2 -2
- package/tests/views/__snapshots__/posts.test.ts.snap +8 -8
- package/tests/views/__snapshots__/thread.test.ts.snap +10 -10
- package/tests/views/__snapshots__/timeline.test.ts.snap +58 -58
- package/tests/views/actor-likes.test.ts +2 -3
- package/tests/views/actor-search.test.ts +5 -5
- package/tests/views/admin/repo-search.test.ts +2 -4
- package/tests/views/author-feed.test.ts +2 -4
- package/tests/views/block-lists.test.ts +34 -7
- package/tests/views/blocks.test.ts +6 -3
- package/tests/views/follows.test.ts +2 -4
- package/tests/views/likes.test.ts +2 -5
- package/tests/views/list-feed.test.ts +2 -4
- package/tests/views/mute-lists.test.ts +23 -5
- package/tests/views/mutes.test.ts +2 -5
- package/tests/views/notifications.test.ts +2 -4
- package/tests/views/posts.test.ts +2 -5
- package/tests/views/profile.test.ts +4 -5
- package/tests/views/reposts.test.ts +2 -4
- package/tests/views/suggested-follows.test.ts +2 -3
- package/tests/views/suggestions.test.ts +2 -4
- package/tests/views/thread.test.ts +2 -4
- package/tests/views/threadgating.test.ts +2 -3
- package/tests/views/timeline.test.ts +2 -4
- package/LICENSE +0 -21
- package/dist/env.d.ts +0 -1
- package/example.dev.env +0 -5
- package/src/env.ts +0 -9
- package/tests/seeds/client.ts +0 -466
- /package/tests/{__snapshots__ → admin/__snapshots__}/moderation.test.ts.snap +0 -0
- /package/tests/{image/fixtures → sample-img}/at.png +0 -0
- /package/tests/{image/fixtures → sample-img}/hd-key.jpg +0 -0
- /package/tests/{image/fixtures → sample-img}/key-alt.jpg +0 -0
- /package/tests/{image/fixtures → sample-img}/key-landscape-large.jpg +0 -0
- /package/tests/{image/fixtures → sample-img}/key-landscape-small.jpg +0 -0
- /package/tests/{image/fixtures → sample-img}/key-portrait-large.jpg +0 -0
- /package/tests/{image/fixtures → sample-img}/key-portrait-small.jpg +0 -0
package/tests/seeds/client.ts
DELETED
|
@@ -1,466 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises'
|
|
2
|
-
import { CID } from 'multiformats/cid'
|
|
3
|
-
import AtpAgent from '@atproto/api'
|
|
4
|
-
import { AtUri } from '@atproto/syntax'
|
|
5
|
-
import { BlobRef } from '@atproto/lexicon'
|
|
6
|
-
import { Main as Facet } from '@atproto/api/src/client/types/app/bsky/richtext/facet'
|
|
7
|
-
import { InputSchema as TakeActionInput } from '@atproto/api/src/client/types/com/atproto/admin/takeModerationAction'
|
|
8
|
-
import { InputSchema as CreateReportInput } from '@atproto/api/src/client/types/com/atproto/moderation/createReport'
|
|
9
|
-
import { Record as PostRecord } from '@atproto/api/src/client/types/app/bsky/feed/post'
|
|
10
|
-
import { Record as LikeRecord } from '@atproto/api/src/client/types/app/bsky/feed/like'
|
|
11
|
-
import { Record as FollowRecord } from '@atproto/api/src/client/types/app/bsky/graph/follow'
|
|
12
|
-
|
|
13
|
-
// Makes it simple to create data via the XRPC client,
|
|
14
|
-
// and keeps track of all created data in memory for convenience.
|
|
15
|
-
|
|
16
|
-
let AVATAR_IMG: Uint8Array | undefined
|
|
17
|
-
|
|
18
|
-
export type ImageRef = {
|
|
19
|
-
image: BlobRef
|
|
20
|
-
alt: string
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class RecordRef {
|
|
24
|
-
uri: AtUri
|
|
25
|
-
cid: CID
|
|
26
|
-
|
|
27
|
-
constructor(uri: AtUri | string, cid: CID | string) {
|
|
28
|
-
this.uri = new AtUri(uri.toString())
|
|
29
|
-
this.cid = CID.parse(cid.toString())
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get raw(): { uri: string; cid: string } {
|
|
33
|
-
return {
|
|
34
|
-
uri: this.uri.toString(),
|
|
35
|
-
cid: this.cid.toString(),
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
get uriStr(): string {
|
|
40
|
-
return this.uri.toString()
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get cidStr(): string {
|
|
44
|
-
return this.cid.toString()
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export class SeedClient {
|
|
49
|
-
accounts: Record<
|
|
50
|
-
string,
|
|
51
|
-
{
|
|
52
|
-
did: string
|
|
53
|
-
accessJwt: string
|
|
54
|
-
refreshJwt: string
|
|
55
|
-
handle: string
|
|
56
|
-
email: string
|
|
57
|
-
password: string
|
|
58
|
-
}
|
|
59
|
-
>
|
|
60
|
-
profiles: Record<
|
|
61
|
-
string,
|
|
62
|
-
{
|
|
63
|
-
displayName: string
|
|
64
|
-
description: string
|
|
65
|
-
avatar: { cid: string; mimeType: string }
|
|
66
|
-
ref: RecordRef
|
|
67
|
-
}
|
|
68
|
-
>
|
|
69
|
-
follows: Record<string, Record<string, RecordRef>>
|
|
70
|
-
posts: Record<
|
|
71
|
-
string,
|
|
72
|
-
{ text: string; ref: RecordRef; images: ImageRef[]; quote?: RecordRef }[]
|
|
73
|
-
>
|
|
74
|
-
likes: Record<string, Record<string, AtUri>>
|
|
75
|
-
replies: Record<string, { text: string; ref: RecordRef }[]>
|
|
76
|
-
reposts: Record<string, RecordRef[]>
|
|
77
|
-
lists: Record<
|
|
78
|
-
string,
|
|
79
|
-
Record<string, { ref: RecordRef; items: Record<string, RecordRef> }>
|
|
80
|
-
>
|
|
81
|
-
dids: Record<string, string>
|
|
82
|
-
|
|
83
|
-
constructor(public agent: AtpAgent, public adminAuth?: string) {
|
|
84
|
-
this.accounts = {}
|
|
85
|
-
this.profiles = {}
|
|
86
|
-
this.follows = {}
|
|
87
|
-
this.posts = {}
|
|
88
|
-
this.likes = {}
|
|
89
|
-
this.replies = {}
|
|
90
|
-
this.reposts = {}
|
|
91
|
-
this.lists = {}
|
|
92
|
-
this.dids = {}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async createAccount(
|
|
96
|
-
shortName: string,
|
|
97
|
-
params: {
|
|
98
|
-
handle: string
|
|
99
|
-
email: string
|
|
100
|
-
password: string
|
|
101
|
-
},
|
|
102
|
-
) {
|
|
103
|
-
const { data: account } =
|
|
104
|
-
await this.agent.api.com.atproto.server.createAccount(params)
|
|
105
|
-
this.dids[shortName] = account.did
|
|
106
|
-
this.accounts[account.did] = {
|
|
107
|
-
...account,
|
|
108
|
-
email: params.email,
|
|
109
|
-
password: params.password,
|
|
110
|
-
}
|
|
111
|
-
return this.accounts[account.did]
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async updateHandle(by: string, handle: string) {
|
|
115
|
-
await this.agent.api.com.atproto.identity.updateHandle(
|
|
116
|
-
{ handle },
|
|
117
|
-
{ encoding: 'application/json', headers: this.getHeaders(by) },
|
|
118
|
-
)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async createProfile(
|
|
122
|
-
by: string,
|
|
123
|
-
displayName: string,
|
|
124
|
-
description: string,
|
|
125
|
-
selfLabels?: string[],
|
|
126
|
-
) {
|
|
127
|
-
AVATAR_IMG ??= await fs.readFile(
|
|
128
|
-
'tests/image/fixtures/key-portrait-small.jpg',
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
let avatarBlob
|
|
132
|
-
{
|
|
133
|
-
const res = await this.agent.api.com.atproto.repo.uploadBlob(AVATAR_IMG, {
|
|
134
|
-
encoding: 'image/jpeg',
|
|
135
|
-
headers: this.getHeaders(by),
|
|
136
|
-
} as any)
|
|
137
|
-
avatarBlob = res.data.blob
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
{
|
|
141
|
-
const res = await this.agent.api.app.bsky.actor.profile.create(
|
|
142
|
-
{ repo: by },
|
|
143
|
-
{
|
|
144
|
-
displayName,
|
|
145
|
-
description,
|
|
146
|
-
avatar: avatarBlob,
|
|
147
|
-
labels: selfLabels
|
|
148
|
-
? {
|
|
149
|
-
$type: 'com.atproto.label.defs#selfLabels',
|
|
150
|
-
values: selfLabels.map((val) => ({ val })),
|
|
151
|
-
}
|
|
152
|
-
: undefined,
|
|
153
|
-
},
|
|
154
|
-
this.getHeaders(by),
|
|
155
|
-
)
|
|
156
|
-
this.profiles[by] = {
|
|
157
|
-
displayName,
|
|
158
|
-
description,
|
|
159
|
-
avatar: avatarBlob,
|
|
160
|
-
ref: new RecordRef(res.uri, res.cid),
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return this.profiles[by]
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async follow(from: string, to: string, overrides?: Partial<FollowRecord>) {
|
|
167
|
-
const res = await this.agent.api.app.bsky.graph.follow.create(
|
|
168
|
-
{ repo: from },
|
|
169
|
-
{
|
|
170
|
-
subject: to,
|
|
171
|
-
createdAt: new Date().toISOString(),
|
|
172
|
-
...overrides,
|
|
173
|
-
},
|
|
174
|
-
this.getHeaders(from),
|
|
175
|
-
)
|
|
176
|
-
this.follows[from] ??= {}
|
|
177
|
-
this.follows[from][to] = new RecordRef(res.uri, res.cid)
|
|
178
|
-
return this.follows[from][to]
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
async unfollow(from: string, to: string) {
|
|
182
|
-
const follow = this.follows[from][to]
|
|
183
|
-
if (!follow) {
|
|
184
|
-
throw new Error('follow does not exist')
|
|
185
|
-
}
|
|
186
|
-
await this.agent.api.app.bsky.graph.follow.delete(
|
|
187
|
-
{ repo: from, rkey: follow.uri.rkey },
|
|
188
|
-
this.getHeaders(from),
|
|
189
|
-
)
|
|
190
|
-
delete this.follows[from][to]
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async post(
|
|
194
|
-
by: string,
|
|
195
|
-
text: string,
|
|
196
|
-
facets?: Facet[],
|
|
197
|
-
images?: ImageRef[],
|
|
198
|
-
quote?: RecordRef,
|
|
199
|
-
overrides?: Partial<PostRecord>,
|
|
200
|
-
) {
|
|
201
|
-
const imageEmbed = images && {
|
|
202
|
-
$type: 'app.bsky.embed.images',
|
|
203
|
-
images,
|
|
204
|
-
}
|
|
205
|
-
const recordEmbed = quote && {
|
|
206
|
-
record: { uri: quote.uriStr, cid: quote.cidStr },
|
|
207
|
-
}
|
|
208
|
-
const embed =
|
|
209
|
-
imageEmbed && recordEmbed
|
|
210
|
-
? {
|
|
211
|
-
$type: 'app.bsky.embed.recordWithMedia',
|
|
212
|
-
record: recordEmbed,
|
|
213
|
-
media: imageEmbed,
|
|
214
|
-
}
|
|
215
|
-
: recordEmbed
|
|
216
|
-
? { $type: 'app.bsky.embed.record', ...recordEmbed }
|
|
217
|
-
: imageEmbed
|
|
218
|
-
const res = await this.agent.api.app.bsky.feed.post.create(
|
|
219
|
-
{ repo: by },
|
|
220
|
-
{
|
|
221
|
-
text: text,
|
|
222
|
-
facets,
|
|
223
|
-
embed,
|
|
224
|
-
createdAt: new Date().toISOString(),
|
|
225
|
-
...overrides,
|
|
226
|
-
},
|
|
227
|
-
this.getHeaders(by),
|
|
228
|
-
)
|
|
229
|
-
this.posts[by] ??= []
|
|
230
|
-
const post = {
|
|
231
|
-
text,
|
|
232
|
-
ref: new RecordRef(res.uri, res.cid),
|
|
233
|
-
images: images ?? [],
|
|
234
|
-
quote,
|
|
235
|
-
}
|
|
236
|
-
this.posts[by].push(post)
|
|
237
|
-
return post
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
async deletePost(by: string, uri: AtUri) {
|
|
241
|
-
await this.agent.api.app.bsky.feed.post.delete(
|
|
242
|
-
{
|
|
243
|
-
repo: by,
|
|
244
|
-
rkey: uri.rkey,
|
|
245
|
-
},
|
|
246
|
-
this.getHeaders(by),
|
|
247
|
-
)
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
async uploadFile(
|
|
251
|
-
by: string,
|
|
252
|
-
filePath: string,
|
|
253
|
-
encoding: string,
|
|
254
|
-
): Promise<ImageRef> {
|
|
255
|
-
const file = await fs.readFile(filePath)
|
|
256
|
-
const res = await this.agent.api.com.atproto.repo.uploadBlob(file, {
|
|
257
|
-
headers: this.getHeaders(by),
|
|
258
|
-
encoding,
|
|
259
|
-
} as any)
|
|
260
|
-
return { image: res.data.blob, alt: filePath }
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
async like(by: string, subject: RecordRef, overrides?: Partial<LikeRecord>) {
|
|
264
|
-
const res = await this.agent.api.app.bsky.feed.like.create(
|
|
265
|
-
{ repo: by },
|
|
266
|
-
{
|
|
267
|
-
subject: subject.raw,
|
|
268
|
-
createdAt: new Date().toISOString(),
|
|
269
|
-
...overrides,
|
|
270
|
-
},
|
|
271
|
-
this.getHeaders(by),
|
|
272
|
-
)
|
|
273
|
-
this.likes[by] ??= {}
|
|
274
|
-
this.likes[by][subject.uriStr] = new AtUri(res.uri)
|
|
275
|
-
return this.likes[by][subject.uriStr]
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
async reply(
|
|
279
|
-
by: string,
|
|
280
|
-
root: RecordRef,
|
|
281
|
-
parent: RecordRef,
|
|
282
|
-
text: string,
|
|
283
|
-
facets?: Facet[],
|
|
284
|
-
images?: ImageRef[],
|
|
285
|
-
) {
|
|
286
|
-
const embed = images
|
|
287
|
-
? {
|
|
288
|
-
$type: 'app.bsky.embed.images',
|
|
289
|
-
images,
|
|
290
|
-
}
|
|
291
|
-
: undefined
|
|
292
|
-
const res = await this.agent.api.app.bsky.feed.post.create(
|
|
293
|
-
{ repo: by },
|
|
294
|
-
{
|
|
295
|
-
text: text,
|
|
296
|
-
reply: {
|
|
297
|
-
root: root.raw,
|
|
298
|
-
parent: parent.raw,
|
|
299
|
-
},
|
|
300
|
-
facets,
|
|
301
|
-
embed,
|
|
302
|
-
createdAt: new Date().toISOString(),
|
|
303
|
-
},
|
|
304
|
-
this.getHeaders(by),
|
|
305
|
-
)
|
|
306
|
-
this.replies[by] ??= []
|
|
307
|
-
const reply = {
|
|
308
|
-
text,
|
|
309
|
-
ref: new RecordRef(res.uri, res.cid),
|
|
310
|
-
}
|
|
311
|
-
this.replies[by].push(reply)
|
|
312
|
-
return reply
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
async repost(by: string, subject: RecordRef) {
|
|
316
|
-
const res = await this.agent.api.app.bsky.feed.repost.create(
|
|
317
|
-
{ repo: by },
|
|
318
|
-
{ subject: subject.raw, createdAt: new Date().toISOString() },
|
|
319
|
-
this.getHeaders(by),
|
|
320
|
-
)
|
|
321
|
-
this.reposts[by] ??= []
|
|
322
|
-
const repost = new RecordRef(res.uri, res.cid)
|
|
323
|
-
this.reposts[by].push(repost)
|
|
324
|
-
return repost
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
async createList(by: string, name: string, purpose: 'mod' | 'curate') {
|
|
328
|
-
const res = await this.agent.api.app.bsky.graph.list.create(
|
|
329
|
-
{ repo: by },
|
|
330
|
-
{
|
|
331
|
-
name,
|
|
332
|
-
purpose:
|
|
333
|
-
purpose === 'mod'
|
|
334
|
-
? 'app.bsky.graph.defs#modlist'
|
|
335
|
-
: 'app.bsky.graph.defs#curatelist',
|
|
336
|
-
createdAt: new Date().toISOString(),
|
|
337
|
-
},
|
|
338
|
-
this.getHeaders(by),
|
|
339
|
-
)
|
|
340
|
-
this.lists[by] ??= {}
|
|
341
|
-
const ref = new RecordRef(res.uri, res.cid)
|
|
342
|
-
this.lists[by][ref.uriStr] = {
|
|
343
|
-
ref: ref,
|
|
344
|
-
items: {},
|
|
345
|
-
}
|
|
346
|
-
return ref
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
async addToList(by: string, subject: string, list: RecordRef) {
|
|
350
|
-
const res = await this.agent.api.app.bsky.graph.listitem.create(
|
|
351
|
-
{ repo: by },
|
|
352
|
-
{ subject, list: list.uriStr, createdAt: new Date().toISOString() },
|
|
353
|
-
this.getHeaders(by),
|
|
354
|
-
)
|
|
355
|
-
const ref = new RecordRef(res.uri, res.cid)
|
|
356
|
-
const found = (this.lists[by] ?? {})[list.uriStr]
|
|
357
|
-
if (found) {
|
|
358
|
-
found.items[subject] = ref
|
|
359
|
-
}
|
|
360
|
-
return ref
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
async rmFromList(by: string, subject: string, list: RecordRef) {
|
|
364
|
-
const foundList = (this.lists[by] ?? {})[list.uriStr] ?? {}
|
|
365
|
-
if (!foundList) return
|
|
366
|
-
const foundItem = foundList.items[subject]
|
|
367
|
-
if (!foundItem) return
|
|
368
|
-
await this.agent.api.app.bsky.graph.listitem.delete(
|
|
369
|
-
{ repo: by, rkey: foundItem.uri.rkey },
|
|
370
|
-
this.getHeaders(by),
|
|
371
|
-
)
|
|
372
|
-
delete foundList.items[subject]
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
async takeModerationAction(opts: {
|
|
376
|
-
action: TakeActionInput['action']
|
|
377
|
-
subject: TakeActionInput['subject']
|
|
378
|
-
reason?: string
|
|
379
|
-
createdBy?: string
|
|
380
|
-
}) {
|
|
381
|
-
if (!this.adminAuth) {
|
|
382
|
-
throw new Error('No admin auth provided to seed client')
|
|
383
|
-
}
|
|
384
|
-
const {
|
|
385
|
-
action,
|
|
386
|
-
subject,
|
|
387
|
-
reason = 'X',
|
|
388
|
-
createdBy = 'did:example:admin',
|
|
389
|
-
} = opts
|
|
390
|
-
const result = await this.agent.api.com.atproto.admin.takeModerationAction(
|
|
391
|
-
{ action, subject, createdBy, reason },
|
|
392
|
-
{
|
|
393
|
-
encoding: 'application/json',
|
|
394
|
-
headers: { authorization: this.adminAuth },
|
|
395
|
-
},
|
|
396
|
-
)
|
|
397
|
-
return result.data
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
async reverseModerationAction(opts: {
|
|
401
|
-
id: number
|
|
402
|
-
reason?: string
|
|
403
|
-
createdBy?: string
|
|
404
|
-
}) {
|
|
405
|
-
if (!this.adminAuth) {
|
|
406
|
-
throw new Error('No admin auth provided to seed client')
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
const { id, reason = 'X', createdBy = 'did:example:admin' } = opts
|
|
410
|
-
const result =
|
|
411
|
-
await this.agent.api.com.atproto.admin.reverseModerationAction(
|
|
412
|
-
{ id, reason, createdBy },
|
|
413
|
-
{
|
|
414
|
-
encoding: 'application/json',
|
|
415
|
-
headers: { authorization: this.adminAuth },
|
|
416
|
-
},
|
|
417
|
-
)
|
|
418
|
-
return result.data
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
async resolveReports(opts: {
|
|
422
|
-
actionId: number
|
|
423
|
-
reportIds: number[]
|
|
424
|
-
createdBy?: string
|
|
425
|
-
}) {
|
|
426
|
-
if (!this.adminAuth) {
|
|
427
|
-
throw new Error('No admin auth provided to seed client')
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
const { actionId, reportIds, createdBy = 'did:example:admin' } = opts
|
|
431
|
-
const result =
|
|
432
|
-
await this.agent.api.com.atproto.admin.resolveModerationReports(
|
|
433
|
-
{ actionId, createdBy, reportIds },
|
|
434
|
-
{
|
|
435
|
-
encoding: 'application/json',
|
|
436
|
-
headers: { authorization: this.adminAuth },
|
|
437
|
-
},
|
|
438
|
-
)
|
|
439
|
-
return result.data
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
async createReport(opts: {
|
|
443
|
-
reasonType: CreateReportInput['reasonType']
|
|
444
|
-
subject: CreateReportInput['subject']
|
|
445
|
-
reason?: string
|
|
446
|
-
reportedBy: string
|
|
447
|
-
}) {
|
|
448
|
-
const { reasonType, subject, reason, reportedBy } = opts
|
|
449
|
-
const result = await this.agent.api.com.atproto.moderation.createReport(
|
|
450
|
-
{ reasonType, subject, reason },
|
|
451
|
-
{
|
|
452
|
-
encoding: 'application/json',
|
|
453
|
-
headers: this.getHeaders(reportedBy),
|
|
454
|
-
},
|
|
455
|
-
)
|
|
456
|
-
return result.data
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
getHeaders(did: string) {
|
|
460
|
-
return SeedClient.getHeaders(this.accounts[did].accessJwt)
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
static getHeaders(jwt: string) {
|
|
464
|
-
return { authorization: `Bearer ${jwt}` }
|
|
465
|
-
}
|
|
466
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|