@atproto/dev-env 0.3.38 → 0.3.39-rc.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,13 @@
1
1
  import fs from 'fs/promises'
2
2
  import { CID } from 'multiformats/cid'
3
- import AtpAgent, {
3
+ import {
4
4
  ComAtprotoModerationCreateReport,
5
5
  AppBskyFeedPost,
6
6
  AppBskyRichtextFacet,
7
7
  AppBskyFeedLike,
8
8
  AppBskyGraphFollow,
9
9
  AppBskyGraphList,
10
+ AtpAgent,
10
11
  } from '@atproto/api'
11
12
  import { AtUri } from '@atproto/syntax'
12
13
  import { BlobRef } from '@atproto/lexicon'
@@ -133,7 +134,7 @@ export class SeedClient<
133
134
  },
134
135
  ) {
135
136
  const { data: account } =
136
- await this.agent.api.com.atproto.server.createAccount(params)
137
+ await this.agent.com.atproto.server.createAccount(params)
137
138
  this.dids[shortName] = account.did
138
139
  this.accounts[account.did] = {
139
140
  ...account,
@@ -144,7 +145,7 @@ export class SeedClient<
144
145
  }
145
146
 
146
147
  async updateHandle(by: string, handle: string) {
147
- await this.agent.api.com.atproto.identity.updateHandle(
148
+ await this.agent.com.atproto.identity.updateHandle(
148
149
  { handle },
149
150
  { encoding: 'application/json', headers: this.getHeaders(by) },
150
151
  )
@@ -156,14 +157,20 @@ export class SeedClient<
156
157
  description: string,
157
158
  selfLabels?: string[],
158
159
  joinedViaStarterPack?: RecordRef,
159
- ) {
160
+ ): Promise<{
161
+ displayName: string
162
+ description: string
163
+ avatar: { cid: string; mimeType: string }
164
+ ref: RecordRef
165
+ joinedViaStarterPack?: RecordRef
166
+ }> {
160
167
  AVATAR_IMG ??= await fs.readFile(
161
168
  '../dev-env/src/seed/img/key-portrait-small.jpg',
162
169
  )
163
170
 
164
171
  let avatarBlob
165
172
  {
166
- const res = await this.agent.api.com.atproto.repo.uploadBlob(AVATAR_IMG, {
173
+ const res = await this.agent.com.atproto.repo.uploadBlob(AVATAR_IMG, {
167
174
  encoding: 'image/jpeg',
168
175
  headers: this.getHeaders(by),
169
176
  } as any)
@@ -171,7 +178,7 @@ export class SeedClient<
171
178
  }
172
179
 
173
180
  {
174
- const res = await this.agent.api.app.bsky.actor.profile.create(
181
+ const res = await this.agent.app.bsky.actor.profile.create(
175
182
  { repo: by },
176
183
  {
177
184
  displayName,
@@ -200,7 +207,7 @@ export class SeedClient<
200
207
  }
201
208
 
202
209
  async updateProfile(by: string, record: Record<string, unknown>) {
203
- const res = await this.agent.api.com.atproto.repo.putRecord(
210
+ const res = await this.agent.com.atproto.repo.putRecord(
204
211
  {
205
212
  repo: by,
206
213
  collection: 'app.bsky.actor.profile',
@@ -222,7 +229,7 @@ export class SeedClient<
222
229
  to: string,
223
230
  overrides?: Partial<AppBskyGraphFollow.Record>,
224
231
  ) {
225
- const res = await this.agent.api.app.bsky.graph.follow.create(
232
+ const res = await this.agent.app.bsky.graph.follow.create(
226
233
  { repo: from },
227
234
  {
228
235
  subject: to,
@@ -241,7 +248,7 @@ export class SeedClient<
241
248
  if (!follow) {
242
249
  throw new Error('follow does not exist')
243
250
  }
244
- await this.agent.api.app.bsky.graph.follow.delete(
251
+ await this.agent.app.bsky.graph.follow.delete(
245
252
  { repo: from, rkey: follow.uri.rkey },
246
253
  this.getHeaders(from),
247
254
  )
@@ -253,7 +260,7 @@ export class SeedClient<
253
260
  to: string,
254
261
  overrides?: Partial<AppBskyGraphFollow.Record>,
255
262
  ) {
256
- const res = await this.agent.api.app.bsky.graph.block.create(
263
+ const res = await this.agent.app.bsky.graph.block.create(
257
264
  { repo: from },
258
265
  {
259
266
  subject: to,
@@ -272,7 +279,7 @@ export class SeedClient<
272
279
  if (!block) {
273
280
  throw new Error('block does not exist')
274
281
  }
275
- await this.agent.api.app.bsky.graph.block.delete(
282
+ await this.agent.app.bsky.graph.block.delete(
276
283
  { repo: from, rkey: block.uri.rkey },
277
284
  this.getHeaders(from),
278
285
  )
@@ -304,7 +311,7 @@ export class SeedClient<
304
311
  : recordEmbed
305
312
  ? { $type: 'app.bsky.embed.record', ...recordEmbed }
306
313
  : imageEmbed
307
- const res = await this.agent.api.app.bsky.feed.post.create(
314
+ const res = await this.agent.app.bsky.feed.post.create(
308
315
  { repo: by },
309
316
  {
310
317
  text: text,
@@ -327,7 +334,7 @@ export class SeedClient<
327
334
  }
328
335
 
329
336
  async deletePost(by: string, uri: AtUri) {
330
- await this.agent.api.app.bsky.feed.post.delete(
337
+ await this.agent.app.bsky.feed.post.delete(
331
338
  {
332
339
  repo: by,
333
340
  rkey: uri.rkey,
@@ -342,7 +349,7 @@ export class SeedClient<
342
349
  encoding: string,
343
350
  ): Promise<ImageRef> {
344
351
  const file = await fs.readFile(filePath)
345
- const res = await this.agent.api.com.atproto.repo.uploadBlob(file, {
352
+ const res = await this.agent.com.atproto.repo.uploadBlob(file, {
346
353
  headers: this.getHeaders(by),
347
354
  encoding,
348
355
  } as any)
@@ -354,7 +361,7 @@ export class SeedClient<
354
361
  subject: RecordRef,
355
362
  overrides?: Partial<AppBskyFeedLike.Record>,
356
363
  ) {
357
- const res = await this.agent.api.app.bsky.feed.like.create(
364
+ const res = await this.agent.app.bsky.feed.like.create(
358
365
  { repo: by },
359
366
  {
360
367
  subject: subject.raw,
@@ -382,7 +389,7 @@ export class SeedClient<
382
389
  images,
383
390
  }
384
391
  : undefined
385
- const res = await this.agent.api.app.bsky.feed.post.create(
392
+ const res = await this.agent.app.bsky.feed.post.create(
386
393
  { repo: by },
387
394
  {
388
395
  text: text,
@@ -407,7 +414,7 @@ export class SeedClient<
407
414
  }
408
415
 
409
416
  async repost(by: string, subject: RecordRef) {
410
- const res = await this.agent.api.app.bsky.feed.repost.create(
417
+ const res = await this.agent.app.bsky.feed.repost.create(
411
418
  { repo: by },
412
419
  { subject: subject.raw, createdAt: new Date().toISOString() },
413
420
  this.getHeaders(by),
@@ -424,7 +431,7 @@ export class SeedClient<
424
431
  purpose: 'mod' | 'curate' | 'reference',
425
432
  overrides?: Partial<AppBskyGraphList.Record>,
426
433
  ) {
427
- const res = await this.agent.api.app.bsky.graph.list.create(
434
+ const res = await this.agent.app.bsky.graph.list.create(
428
435
  { repo: by },
429
436
  {
430
437
  name,
@@ -449,7 +456,7 @@ export class SeedClient<
449
456
  }
450
457
 
451
458
  async createFeedGen(by: string, feedDid: string, name: string) {
452
- const res = await this.agent.api.app.bsky.feed.generator.create(
459
+ const res = await this.agent.app.bsky.feed.generator.create(
453
460
  { repo: by },
454
461
  {
455
462
  did: feedDid,
@@ -477,7 +484,7 @@ export class SeedClient<
477
484
  for (const did of actors) {
478
485
  await this.addToList(by, did, list)
479
486
  }
480
- const res = await this.agent.api.app.bsky.graph.starterpack.create(
487
+ const res = await this.agent.app.bsky.graph.starterpack.create(
481
488
  { repo: by },
482
489
  {
483
490
  name,
@@ -499,7 +506,7 @@ export class SeedClient<
499
506
  }
500
507
 
501
508
  async addToList(by: string, subject: string, list: RecordRef) {
502
- const res = await this.agent.api.app.bsky.graph.listitem.create(
509
+ const res = await this.agent.app.bsky.graph.listitem.create(
503
510
  { repo: by },
504
511
  { subject, list: list.uriStr, createdAt: new Date().toISOString() },
505
512
  this.getHeaders(by),
@@ -517,7 +524,7 @@ export class SeedClient<
517
524
  if (!foundList) return
518
525
  const foundItem = foundList.items[subject]
519
526
  if (!foundItem) return
520
- await this.agent.api.app.bsky.graph.listitem.delete(
527
+ await this.agent.app.bsky.graph.listitem.delete(
521
528
  { repo: by, rkey: foundItem.uri.rkey },
522
529
  this.getHeaders(by),
523
530
  )
@@ -531,7 +538,7 @@ export class SeedClient<
531
538
  reportedBy: string
532
539
  }) {
533
540
  const { reasonType, subject, reason, reportedBy } = opts
534
- const result = await this.agent.api.com.atproto.moderation.createReport(
541
+ const result = await this.agent.com.atproto.moderation.createReport(
535
542
  { reasonType, subject, reason },
536
543
  {
537
544
  encoding: 'application/json',