@atproto/dev-env 0.3.8 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
package/src/mock/index.ts CHANGED
@@ -350,328 +350,6 @@ export async function generateMockSetup(env: TestNetwork) {
350
350
  },
351
351
  )
352
352
 
353
- // create the dev-env moderator
354
- {
355
- const res = await clients.loggedout.api.com.atproto.server.createAccount({
356
- email: 'mod-authority@test.com',
357
- handle: 'mod-authority.test',
358
- password: 'hunter2',
359
- })
360
- const agent = env.pds.getClient()
361
- agent.api.setHeader('Authorization', `Bearer ${res.data.accessJwt}`)
362
- await agent.api.app.bsky.actor.profile.create(
363
- { repo: res.data.did },
364
- {
365
- displayName: 'Dev-env Moderation',
366
- description: `The pretend version of mod.bsky.app`,
367
- },
368
- )
369
-
370
- await agent.api.app.bsky.labeler.service.create(
371
- { repo: res.data.did, rkey: 'self' },
372
- {
373
- policies: {
374
- labelValues: [
375
- '!hide',
376
- '!warn',
377
- 'porn',
378
- 'sexual',
379
- 'nudity',
380
- 'sexual-figurative',
381
- 'graphic-media',
382
- 'self-harm',
383
- 'sensitive',
384
- 'extremist',
385
- 'intolerant',
386
- 'threat',
387
- 'rude',
388
- 'illicit',
389
- 'security',
390
- 'unsafe-link',
391
- 'impersonation',
392
- 'misinformation',
393
- 'scam',
394
- 'engagement-farming',
395
- 'spam',
396
- 'rumor',
397
- 'misleading',
398
- 'inauthentic',
399
- ],
400
- labelValueDefinitions: [
401
- {
402
- identifier: 'spam',
403
- blurs: 'content',
404
- severity: 'inform',
405
- defaultSetting: 'hide',
406
- adultOnly: false,
407
- locales: [
408
- {
409
- lang: 'en',
410
- name: 'Spam',
411
- description:
412
- 'Unwanted, repeated, or unrelated actions that bother users.',
413
- },
414
- ],
415
- },
416
- {
417
- identifier: 'impersonation',
418
- blurs: 'none',
419
- severity: 'inform',
420
- defaultSetting: 'hide',
421
- adultOnly: false,
422
- locales: [
423
- {
424
- lang: 'en',
425
- name: 'Impersonation',
426
- description:
427
- 'Pretending to be someone else without permission.',
428
- },
429
- ],
430
- },
431
- {
432
- identifier: 'scam',
433
- blurs: 'content',
434
- severity: 'alert',
435
- defaultSetting: 'hide',
436
- adultOnly: false,
437
- locales: [
438
- {
439
- lang: 'en',
440
- name: 'Scam',
441
- description: 'Scams, phishing & fraud.',
442
- },
443
- ],
444
- },
445
- {
446
- identifier: 'intolerant',
447
- blurs: 'content',
448
- severity: 'alert',
449
- defaultSetting: 'warn',
450
- adultOnly: false,
451
- locales: [
452
- {
453
- lang: 'en',
454
- name: 'Intolerance',
455
- description: 'Discrimination against protected groups.',
456
- },
457
- ],
458
- },
459
- {
460
- identifier: 'self-harm',
461
- blurs: 'content',
462
- severity: 'alert',
463
- defaultSetting: 'warn',
464
- adultOnly: false,
465
- locales: [
466
- {
467
- lang: 'en',
468
- name: 'Self-Harm',
469
- description:
470
- 'Promotes self-harm, including graphic images, glorifying discussions, or triggering stories.',
471
- },
472
- ],
473
- },
474
- {
475
- identifier: 'security',
476
- blurs: 'content',
477
- severity: 'alert',
478
- defaultSetting: 'hide',
479
- adultOnly: false,
480
- locales: [
481
- {
482
- lang: 'en',
483
- name: 'Security Concerns',
484
- description:
485
- 'May be unsafe and could harm your device, steal your info, or get your account hacked.',
486
- },
487
- ],
488
- },
489
- {
490
- identifier: 'misleading',
491
- blurs: 'content',
492
- severity: 'alert',
493
- defaultSetting: 'warn',
494
- adultOnly: false,
495
- locales: [
496
- {
497
- lang: 'en',
498
- name: 'Misleading',
499
- description:
500
- 'Altered images/videos, deceptive links, or false statements.',
501
- },
502
- ],
503
- },
504
- {
505
- identifier: 'threat',
506
- blurs: 'content',
507
- severity: 'inform',
508
- defaultSetting: 'hide',
509
- adultOnly: false,
510
- locales: [
511
- {
512
- lang: 'en',
513
- name: 'Threats',
514
- description:
515
- 'Promotes violence or harm towards others, including threats, incitement, or advocacy of harm.',
516
- },
517
- ],
518
- },
519
- {
520
- identifier: 'unsafe-link',
521
- blurs: 'content',
522
- severity: 'alert',
523
- defaultSetting: 'hide',
524
- adultOnly: false,
525
- locales: [
526
- {
527
- lang: 'en',
528
- name: 'Unsafe link',
529
- description:
530
- 'Links to harmful sites with malware, phishing, or violating content that risk security and privacy.',
531
- },
532
- ],
533
- },
534
- {
535
- identifier: 'illicit',
536
- blurs: 'content',
537
- severity: 'alert',
538
- defaultSetting: 'hide',
539
- adultOnly: false,
540
- locales: [
541
- {
542
- lang: 'en',
543
- name: 'Illicit',
544
- description:
545
- 'Promoting or selling potentially illicit goods, services, or activities.',
546
- },
547
- ],
548
- },
549
- {
550
- identifier: 'misinformation',
551
- blurs: 'content',
552
- severity: 'inform',
553
- defaultSetting: 'warn',
554
- adultOnly: false,
555
- locales: [
556
- {
557
- lang: 'en',
558
- name: 'Misinformation',
559
- description:
560
- 'Spreading false or misleading info, including unverified claims and harmful conspiracy theories.',
561
- },
562
- ],
563
- },
564
- {
565
- identifier: 'rumor',
566
- blurs: 'content',
567
- severity: 'inform',
568
- defaultSetting: 'warn',
569
- adultOnly: false,
570
- locales: [
571
- {
572
- lang: 'en',
573
- name: 'Rumor',
574
- description:
575
- 'Approach with caution, as these claims lack evidence from credible sources.',
576
- },
577
- ],
578
- },
579
- {
580
- identifier: 'rude',
581
- blurs: 'content',
582
- severity: 'inform',
583
- defaultSetting: 'hide',
584
- adultOnly: false,
585
- locales: [
586
- {
587
- lang: 'en',
588
- name: 'Rude',
589
- description:
590
- 'Rude or impolite, including crude language and disrespectful comments, without constructive purpose.',
591
- },
592
- ],
593
- },
594
- {
595
- identifier: 'extremist',
596
- blurs: 'content',
597
- severity: 'alert',
598
- defaultSetting: 'hide',
599
- adultOnly: false,
600
- locales: [
601
- {
602
- lang: 'en',
603
- name: 'Extremist',
604
- description:
605
- 'Radical views advocating violence, hate, or discrimination against individuals or groups.',
606
- },
607
- ],
608
- },
609
- {
610
- identifier: 'sensitive',
611
- blurs: 'content',
612
- severity: 'alert',
613
- defaultSetting: 'warn',
614
- adultOnly: false,
615
- locales: [
616
- {
617
- lang: 'en',
618
- name: 'Sensitive',
619
- description:
620
- 'May be upsetting, covering topics like substance abuse or mental health issues, cautioning sensitive viewers.',
621
- },
622
- ],
623
- },
624
- {
625
- identifier: 'engagement-farming',
626
- blurs: 'content',
627
- severity: 'alert',
628
- defaultSetting: 'hide',
629
- adultOnly: false,
630
- locales: [
631
- {
632
- lang: 'en',
633
- name: 'Engagement Farming',
634
- description:
635
- 'Insincere content or bulk actions aimed at gaining followers, including frequent follows, posts, and likes.',
636
- },
637
- ],
638
- },
639
- {
640
- identifier: 'inauthentic',
641
- blurs: 'content',
642
- severity: 'alert',
643
- defaultSetting: 'hide',
644
- adultOnly: false,
645
- locales: [
646
- {
647
- lang: 'en',
648
- name: 'Inauthentic Account',
649
- description: 'Bot or a person pretending to be someone else.',
650
- },
651
- ],
652
- },
653
- {
654
- identifier: 'sexual-figurative',
655
- blurs: 'media',
656
- severity: 'none',
657
- defaultSetting: 'show',
658
- adultOnly: true,
659
- locales: [
660
- {
661
- lang: 'en',
662
- name: 'Sexually Suggestive (Cartoon)',
663
- description:
664
- 'Art with explicit or suggestive sexual themes, including provocative imagery or partial nudity.',
665
- },
666
- ],
667
- },
668
- ],
669
- },
670
- createdAt: date.next().value,
671
- },
672
- )
673
- }
674
-
675
353
  // create a labeler account
676
354
  {
677
355
  const res = await clients.loggedout.api.com.atproto.server.createAccount({
package/src/network.ts CHANGED
@@ -7,10 +7,10 @@ import { TestServerParams } from './types'
7
7
  import { TestPlc } from './plc'
8
8
  import { TestPds } from './pds'
9
9
  import { TestBsky } from './bsky'
10
- import { TestOzone, createOzoneDid } from './ozone'
10
+ import { TestOzone } from './ozone'
11
+ import { OzoneServiceProfile } from './ozone-service-profile'
11
12
  import { mockNetworkUtilities } from './util'
12
13
  import { TestNetworkNoAppView } from './network-no-appview'
13
- import { Secp256k1Keypair } from '@atproto/crypto'
14
14
  import { EXAMPLE_LABELER } from './const'
15
15
 
16
16
  const ADMIN_USERNAME = 'admin'
@@ -42,8 +42,16 @@ export class TestNetwork extends TestNetworkNoAppView {
42
42
  const pdsPort = params.pds?.port ?? (await getPort())
43
43
  const ozonePort = params.ozone?.port ?? (await getPort())
44
44
 
45
- const ozoneKey = await Secp256k1Keypair.create({ exportable: true })
46
- const ozoneDid = await createOzoneDid(plc.url, ozoneKey)
45
+ const thirdPartyPdsProps = {
46
+ didPlcUrl: plc.url,
47
+ ...params.pds,
48
+ inviteRequired: false,
49
+ port: await getPort(),
50
+ }
51
+ const thirdPartyPds = await TestPds.create(thirdPartyPdsProps)
52
+ const ozoneServiceProfile = new OzoneServiceProfile(thirdPartyPds)
53
+ const { did: ozoneDid, key: ozoneKey } =
54
+ await ozoneServiceProfile.createDidAndKey()
47
55
 
48
56
  const bsky = await TestBsky.create({
49
57
  port: bskyPort,
@@ -58,22 +66,25 @@ export class TestNetwork extends TestNetworkNoAppView {
58
66
  ...params.bsky,
59
67
  })
60
68
 
61
- const pds = await TestPds.create({
69
+ const modServiceUrl = `http://localhost:${ozonePort}`
70
+ const pdsProps = {
62
71
  port: pdsPort,
63
72
  didPlcUrl: plc.url,
64
73
  bskyAppViewUrl: bsky.url,
65
74
  bskyAppViewDid: bsky.ctx.cfg.serverDid,
66
- modServiceUrl: `http://localhost:${ozonePort}`,
75
+ modServiceUrl,
67
76
  modServiceDid: ozoneDid,
68
77
  ...params.pds,
69
- })
78
+ }
79
+
80
+ const pds = await TestPds.create(pdsProps)
70
81
 
71
82
  const ozone = await TestOzone.create({
72
83
  port: ozonePort,
73
84
  plcUrl: plc.url,
74
85
  signingKey: ozoneKey,
75
86
  serverDid: ozoneDid,
76
- dbPostgresSchema: `ozone_${dbPostgresSchema}`,
87
+ dbPostgresSchema: `ozone_${dbPostgresSchema || 'db'}`,
77
88
  dbPostgresUrl,
78
89
  appviewUrl: bsky.url,
79
90
  appviewDid: bsky.ctx.cfg.serverDid,
@@ -83,7 +94,29 @@ export class TestNetwork extends TestNetworkNoAppView {
83
94
  ...params.ozone,
84
95
  })
85
96
 
97
+ let inviteCode: string | undefined
98
+ if (pdsProps.inviteRequired) {
99
+ const { data: invite } = await pds
100
+ .getClient()
101
+ .api.com.atproto.server.createInviteCode(
102
+ { useCount: 1 },
103
+ {
104
+ encoding: 'application/json',
105
+ headers: pds.adminAuthHeaders(),
106
+ },
107
+ )
108
+ inviteCode = invite.code
109
+ }
110
+ await ozoneServiceProfile.createServiceDetails(pds, modServiceUrl, {
111
+ inviteCode,
112
+ })
113
+
114
+ ozone.addAdminDid(ozoneDid)
115
+
86
116
  mockNetworkUtilities(pds, bsky)
117
+ await pds.processAll()
118
+ await bsky.sub.background.processAll()
119
+ await thirdPartyPds.close()
87
120
 
88
121
  return new TestNetwork(plc, pds, bsky, ozone)
89
122
  }