@atproto/ozone 0.1.73 → 0.1.74

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 (43) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/api/moderation/emitEvent.d.ts.map +1 -1
  3. package/dist/api/moderation/emitEvent.js +1 -1
  4. package/dist/api/moderation/emitEvent.js.map +1 -1
  5. package/dist/api/util.d.ts.map +1 -1
  6. package/dist/api/util.js +3 -0
  7. package/dist/api/util.js.map +1 -1
  8. package/dist/background.d.ts.map +1 -1
  9. package/dist/background.js +0 -2
  10. package/dist/background.js.map +1 -1
  11. package/dist/lexicon/lexicons.d.ts +8 -0
  12. package/dist/lexicon/lexicons.d.ts.map +1 -1
  13. package/dist/lexicon/lexicons.js +4 -0
  14. package/dist/lexicon/lexicons.js.map +1 -1
  15. package/dist/lexicon/types/tools/ozone/moderation/defs.d.ts +2 -0
  16. package/dist/lexicon/types/tools/ozone/moderation/defs.d.ts.map +1 -1
  17. package/dist/lexicon/types/tools/ozone/moderation/defs.js.map +1 -1
  18. package/dist/mod-service/index.d.ts +1 -1
  19. package/dist/mod-service/index.d.ts.map +1 -1
  20. package/dist/mod-service/index.js +5 -1
  21. package/dist/mod-service/index.js.map +1 -1
  22. package/dist/mod-service/status.d.ts.map +1 -1
  23. package/dist/mod-service/status.js +2 -0
  24. package/dist/mod-service/status.js.map +1 -1
  25. package/dist/mod-service/views.d.ts.map +1 -1
  26. package/dist/mod-service/views.js +2 -1
  27. package/dist/mod-service/views.js.map +1 -1
  28. package/package.json +6 -6
  29. package/src/api/moderation/emitEvent.ts +1 -0
  30. package/src/api/util.ts +3 -0
  31. package/src/background.ts +0 -2
  32. package/src/lexicon/lexicons.ts +5 -0
  33. package/src/lexicon/types/tools/ozone/moderation/defs.ts +2 -0
  34. package/src/mod-service/index.ts +6 -0
  35. package/src/mod-service/status.ts +2 -0
  36. package/src/mod-service/views.ts +2 -1
  37. package/tests/__snapshots__/get-record.test.ts.snap +2 -2
  38. package/tests/__snapshots__/get-records.test.ts.snap +1 -1
  39. package/tests/__snapshots__/get-repo.test.ts.snap +1 -1
  40. package/tests/__snapshots__/get-repos.test.ts.snap +1 -1
  41. package/tests/__snapshots__/moderation-events.test.ts.snap +1 -1
  42. package/tests/__snapshots__/moderation-statuses.test.ts.snap +6 -6
  43. package/tests/moderation.test.ts +31 -5
package/src/background.ts CHANGED
@@ -152,10 +152,8 @@ export class PeriodicBackgroundTask {
152
152
  // destroy it here.
153
153
 
154
154
  this.abortController.abort()
155
- console.error('ABOOOORT')
156
155
 
157
156
  await this.intervalPromise
158
157
  this.intervalPromise = undefined
159
- console.error('DONE -_-')
160
158
  }
161
159
  }
@@ -11549,6 +11549,11 @@ export const schemaDict = {
11549
11549
  type: 'string',
11550
11550
  },
11551
11551
  },
11552
+ durationInHours: {
11553
+ type: 'integer',
11554
+ description:
11555
+ 'Indicates how long the label will remain on the subject. Only applies on labels that are being added.',
11556
+ },
11552
11557
  },
11553
11558
  },
11554
11559
  modEventAcknowledge: {
@@ -347,6 +347,8 @@ export interface ModEventLabel {
347
347
  comment?: string
348
348
  createLabelVals: string[]
349
349
  negateLabelVals: string[]
350
+ /** Indicates how long the label will remain on the subject. Only applies on labels that are being added. */
351
+ durationInHours?: number
350
352
  [k: string]: unknown
351
353
  }
352
354
 
@@ -1159,13 +1159,19 @@ export class ModerationService {
1159
1159
  uri: string,
1160
1160
  cid: string | null,
1161
1161
  labels: { create?: string[]; negate?: string[] },
1162
+ durationInHours?: number,
1162
1163
  ): Promise<Label[]> {
1164
+ const exp =
1165
+ durationInHours !== undefined
1166
+ ? addHoursToDate(durationInHours).toISOString()
1167
+ : undefined
1163
1168
  const { create = [], negate = [] } = labels
1164
1169
  const toCreate = create.map((val) => ({
1165
1170
  src: this.cfg.service.did,
1166
1171
  uri,
1167
1172
  cid: cid ?? undefined,
1168
1173
  val,
1174
+ exp,
1169
1175
  cts: new Date().toISOString(),
1170
1176
  }))
1171
1177
  const toNegate = negate.map((val) => ({
@@ -77,6 +77,8 @@ const getSubjectStatusForModerationEvent = ({
77
77
  }
78
78
  case 'tools.ozone.moderation.defs#modEventTakedown':
79
79
  return {
80
+ // If we are doing a takedown, safe to move the item out of appealed state
81
+ ...(currentStatus?.appealed ? { appealed: false } : {}),
80
82
  takendown: true,
81
83
  lastReviewedBy: createdBy,
82
84
  reviewState: REVIEWCLOSED,
@@ -113,6 +113,7 @@ export class ModerationViews {
113
113
  [
114
114
  'tools.ozone.moderation.defs#modEventMuteReporter',
115
115
  'tools.ozone.moderation.defs#modEventTakedown',
116
+ 'tools.ozone.moderation.defs#modEventLabel',
116
117
  'tools.ozone.moderation.defs#modEventMute',
117
118
  ].includes(event.action)
118
119
  ) {
@@ -628,7 +629,7 @@ export class ModerationViews {
628
629
 
629
630
  recordsStats: {
630
631
  // Explicitly typing to allow for easy manipulation (e.g. to strip from tests snapshots)
631
- $type: 'tools.ozone.moderation.defs#recordStats',
632
+ $type: 'tools.ozone.moderation.defs#recordsStats',
632
633
 
633
634
  // account_record_events_stats
634
635
  totalReports: status.totalReports ?? undefined,
@@ -41,7 +41,7 @@ Object {
41
41
  "lastReviewedAt": "1970-01-01T00:00:00.000Z",
42
42
  "lastReviewedBy": "user(1)",
43
43
  "recordsStats": Object {
44
- "$type": "tools.ozone.moderation.defs#recordStats",
44
+ "$type": "tools.ozone.moderation.defs#recordsStats",
45
45
  "appealedCount": 0,
46
46
  "escalatedCount": 0,
47
47
  "pendingCount": 0,
@@ -161,7 +161,7 @@ Object {
161
161
  "lastReviewedAt": "1970-01-01T00:00:00.000Z",
162
162
  "lastReviewedBy": "user(1)",
163
163
  "recordsStats": Object {
164
- "$type": "tools.ozone.moderation.defs#recordStats",
164
+ "$type": "tools.ozone.moderation.defs#recordsStats",
165
165
  "appealedCount": 0,
166
166
  "escalatedCount": 0,
167
167
  "pendingCount": 0,
@@ -44,7 +44,7 @@ Object {
44
44
  "lastReviewedAt": "1970-01-01T00:00:00.000Z",
45
45
  "lastReviewedBy": "user(1)",
46
46
  "recordsStats": Object {
47
- "$type": "tools.ozone.moderation.defs#recordStats",
47
+ "$type": "tools.ozone.moderation.defs#recordsStats",
48
48
  "appealedCount": 0,
49
49
  "escalatedCount": 0,
50
50
  "pendingCount": 0,
@@ -40,7 +40,7 @@ Object {
40
40
  "lastReviewedAt": "1970-01-01T00:00:00.000Z",
41
41
  "lastReviewedBy": "user(1)",
42
42
  "recordsStats": Object {
43
- "$type": "tools.ozone.moderation.defs#recordStats",
43
+ "$type": "tools.ozone.moderation.defs#recordsStats",
44
44
  },
45
45
  "reviewState": "tools.ozone.moderation.defs#reviewClosed",
46
46
  "subject": Object {
@@ -43,7 +43,7 @@ Object {
43
43
  "lastReviewedAt": "1970-01-01T00:00:00.000Z",
44
44
  "lastReviewedBy": "user(1)",
45
45
  "recordsStats": Object {
46
- "$type": "tools.ozone.moderation.defs#recordStats",
46
+ "$type": "tools.ozone.moderation.defs#recordsStats",
47
47
  },
48
48
  "reviewState": "tools.ozone.moderation.defs#reviewClosed",
49
49
  "subject": Object {
@@ -36,7 +36,7 @@ Object {
36
36
  "lastReviewedAt": "1970-01-01T00:00:00.000Z",
37
37
  "lastReviewedBy": "user(1)",
38
38
  "recordsStats": Object {
39
- "$type": "tools.ozone.moderation.defs#recordStats",
39
+ "$type": "tools.ozone.moderation.defs#recordsStats",
40
40
  "appealedCount": 0,
41
41
  "escalatedCount": 0,
42
42
  "pendingCount": 2,
@@ -19,7 +19,7 @@ Array [
19
19
  "id": 7,
20
20
  "lastReportedAt": "1970-01-01T00:00:00.000Z",
21
21
  "recordsStats": Object {
22
- "$type": "tools.ozone.moderation.defs#recordStats",
22
+ "$type": "tools.ozone.moderation.defs#recordsStats",
23
23
  "appealedCount": 0,
24
24
  "escalatedCount": 0,
25
25
  "pendingCount": 1,
@@ -62,7 +62,7 @@ Array [
62
62
  "id": 5,
63
63
  "lastReportedAt": "1970-01-01T00:00:00.000Z",
64
64
  "recordsStats": Object {
65
- "$type": "tools.ozone.moderation.defs#recordStats",
65
+ "$type": "tools.ozone.moderation.defs#recordsStats",
66
66
  "appealedCount": 0,
67
67
  "escalatedCount": 0,
68
68
  "pendingCount": 1,
@@ -109,7 +109,7 @@ Array [
109
109
  "id": 7,
110
110
  "lastReportedAt": "1970-01-01T00:00:00.000Z",
111
111
  "recordsStats": Object {
112
- "$type": "tools.ozone.moderation.defs#recordStats",
112
+ "$type": "tools.ozone.moderation.defs#recordsStats",
113
113
  "appealedCount": 0,
114
114
  "escalatedCount": 0,
115
115
  "pendingCount": 1,
@@ -152,7 +152,7 @@ Array [
152
152
  "id": 5,
153
153
  "lastReportedAt": "1970-01-01T00:00:00.000Z",
154
154
  "recordsStats": Object {
155
- "$type": "tools.ozone.moderation.defs#recordStats",
155
+ "$type": "tools.ozone.moderation.defs#recordsStats",
156
156
  "appealedCount": 0,
157
157
  "escalatedCount": 0,
158
158
  "pendingCount": 1,
@@ -194,7 +194,7 @@ Array [
194
194
  "id": 3,
195
195
  "lastReportedAt": "1970-01-01T00:00:00.000Z",
196
196
  "recordsStats": Object {
197
- "$type": "tools.ozone.moderation.defs#recordStats",
197
+ "$type": "tools.ozone.moderation.defs#recordsStats",
198
198
  "appealedCount": 0,
199
199
  "escalatedCount": 0,
200
200
  "pendingCount": 1,
@@ -236,7 +236,7 @@ Array [
236
236
  "id": 1,
237
237
  "lastReportedAt": "1970-01-01T00:00:00.000Z",
238
238
  "recordsStats": Object {
239
- "$type": "tools.ozone.moderation.defs#recordStats",
239
+ "$type": "tools.ozone.moderation.defs#recordsStats",
240
240
  "appealedCount": 0,
241
241
  "escalatedCount": 0,
242
242
  "pendingCount": 1,
@@ -24,6 +24,7 @@ import { EventReverser } from '../src'
24
24
  import { ImageInvalidator } from '../src/image-invalidator'
25
25
  import { TAKEDOWN_LABEL } from '../src/mod-service'
26
26
  import { ids } from '../src/lexicon/lexicons'
27
+ import { HOUR } from '@atproto/common'
27
28
 
28
29
  describe('moderation', () => {
29
30
  let network: TestNetwork
@@ -514,6 +515,24 @@ describe('moderation', () => {
514
515
  await expect(getRepoLabels(sc.dids.bob)).resolves.toEqual(['kittens'])
515
516
  })
516
517
 
518
+ it('creates expiring label', async () => {
519
+ await emitLabelEvent({
520
+ createLabelVals: ['temp'],
521
+ negateLabelVals: [],
522
+ subject: {
523
+ $type: 'com.atproto.admin.defs#repoRef',
524
+ did: sc.dids.bob,
525
+ },
526
+ durationInHours: 24,
527
+ })
528
+ const repo = await getRepo(sc.dids.bob)
529
+ // Losely check that the expiry date is set to above 23 hours from now
530
+ expect(
531
+ `${repo?.labels?.[0].exp}` >
532
+ new Date(Date.now() + 23 * HOUR).toISOString(),
533
+ ).toBeTruthy()
534
+ })
535
+
517
536
  it('does not allow triage moderators to label.', async () => {
518
537
  const attemptLabel = modClient.emitEvent(
519
538
  {
@@ -708,14 +727,16 @@ describe('moderation', () => {
708
727
  subject: ToolsOzoneModerationEmitEvent.InputSchema['subject']
709
728
  createLabelVals: ModEventLabel['createLabelVals']
710
729
  negateLabelVals: ModEventLabel['negateLabelVals']
730
+ durationInHours?: ModEventLabel['durationInHours']
711
731
  },
712
732
  ) {
713
- const { createLabelVals, negateLabelVals } = opts
733
+ const { createLabelVals, negateLabelVals, durationInHours } = opts
714
734
  const result = await modClient.emitEvent({
715
735
  event: {
716
736
  $type: 'tools.ozone.moderation.defs#modEventLabel',
717
737
  createLabelVals,
718
738
  negateLabelVals,
739
+ durationInHours,
719
740
  },
720
741
  createdBy: 'did:example:admin',
721
742
  reason: 'Y',
@@ -740,7 +761,7 @@ describe('moderation', () => {
740
761
  }
741
762
 
742
763
  async function getRecordLabels(uri: string) {
743
- const result = await agent.api.tools.ozone.moderation.getRecord(
764
+ const result = await agent.tools.ozone.moderation.getRecord(
744
765
  { uri },
745
766
  {
746
767
  headers: await network.ozone.modHeaders(
@@ -752,8 +773,8 @@ describe('moderation', () => {
752
773
  return labels.map((l) => l.val)
753
774
  }
754
775
 
755
- async function getRepoLabels(did: string) {
756
- const result = await agent.api.tools.ozone.moderation.getRepo(
776
+ async function getRepo(did: string) {
777
+ const result = await agent.tools.ozone.moderation.getRepo(
757
778
  { did },
758
779
  {
759
780
  headers: await network.ozone.modHeaders(
@@ -761,7 +782,12 @@ describe('moderation', () => {
761
782
  ),
762
783
  },
763
784
  )
764
- const labels = result.data.labels ?? []
785
+ return result.data
786
+ }
787
+
788
+ async function getRepoLabels(did: string) {
789
+ const result = await getRepo(did)
790
+ const labels = result.labels ?? []
765
791
  return labels.map((l) => l.val)
766
792
  }
767
793
  })