@atcute/bluesky-moderation 2.0.4 → 3.0.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.
- package/README.md +126 -128
- package/dist/_test-util/mock.d.ts +58 -0
- package/dist/_test-util/mock.d.ts.map +1 -0
- package/dist/_test-util/mock.js +109 -0
- package/dist/_test-util/mock.js.map +1 -0
- package/dist/_test-util/moderation-behavior.d.ts +57 -0
- package/dist/_test-util/moderation-behavior.d.ts.map +1 -0
- package/dist/_test-util/moderation-behavior.js +158 -0
- package/dist/_test-util/moderation-behavior.js.map +1 -0
- package/dist/behaviors.d.ts +21 -18
- package/dist/behaviors.d.ts.map +1 -1
- package/dist/behaviors.js +18 -21
- package/dist/behaviors.js.map +1 -1
- package/dist/decision.d.ts +21 -20
- package/dist/decision.d.ts.map +1 -1
- package/dist/decision.js +14 -16
- package/dist/decision.js.map +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/internal/keyword-filter.d.ts +1 -1
- package/dist/internal/keyword-filter.d.ts.map +1 -1
- package/dist/keyword-filter.d.ts +6 -5
- package/dist/keyword-filter.d.ts.map +1 -1
- package/dist/keyword-filter.js +8 -7
- package/dist/keyword-filter.js.map +1 -1
- package/dist/label.d.ts +29 -25
- package/dist/label.d.ts.map +1 -1
- package/dist/label.js +24 -28
- package/dist/label.js.map +1 -1
- package/dist/subjects/feed-generator.d.ts +2 -2
- package/dist/subjects/feed-generator.d.ts.map +1 -1
- package/dist/subjects/list.d.ts +2 -2
- package/dist/subjects/list.d.ts.map +1 -1
- package/dist/subjects/notification.d.ts +2 -2
- package/dist/subjects/notification.d.ts.map +1 -1
- package/dist/subjects/post.d.ts +2 -2
- package/dist/subjects/post.d.ts.map +1 -1
- package/dist/subjects/post.js.map +1 -1
- package/dist/subjects/profile.d.ts +2 -2
- package/dist/subjects/profile.d.ts.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/ui.d.ts +2 -2
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +4 -4
- package/dist/ui.js.map +1 -1
- package/lib/_test-util/mock.ts +214 -0
- package/lib/_test-util/moderation-behavior.ts +259 -0
- package/lib/behaviors.ts +21 -18
- package/lib/decision.ts +26 -26
- package/lib/index.ts +11 -11
- package/lib/internal/keyword-filter.ts +1 -1
- package/lib/keyword-filter.ts +9 -6
- package/lib/label.ts +32 -28
- package/lib/subjects/feed-generator.ts +4 -4
- package/lib/subjects/list.ts +4 -4
- package/lib/subjects/notification.ts +4 -4
- package/lib/subjects/post.ts +6 -7
- package/lib/subjects/profile.ts +3 -3
- package/lib/types.ts +2 -2
- package/lib/ui.ts +7 -7
- package/package.json +17 -13
package/README.md
CHANGED
|
@@ -1,167 +1,165 @@
|
|
|
1
1
|
# @atcute/bluesky-moderation
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
interpret Bluesky content moderation labels and user preferences.
|
|
4
4
|
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
```sh
|
|
6
|
+
npm install @atcute/bluesky-moderation
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
evaluates posts, profiles, lists, and other content against moderation labels, mutes, blocks, and
|
|
10
|
+
keyword filters to determine how they should be displayed.
|
|
11
|
+
|
|
12
|
+
## usage
|
|
8
13
|
|
|
14
|
+
### basic flow
|
|
15
|
+
|
|
16
|
+
1. fetch user preferences and labeler definitions
|
|
17
|
+
2. run moderation functions on content
|
|
18
|
+
3. get display restrictions for your UI context
|
|
19
|
+
|
|
20
|
+
```ts
|
|
9
21
|
import {
|
|
10
22
|
DisplayContext,
|
|
11
23
|
getDisplayRestrictions,
|
|
12
24
|
interpretLabelerDefinitions,
|
|
13
|
-
interpretMutedWordPreferences,
|
|
14
|
-
LabelPreference,
|
|
15
25
|
moderatePost,
|
|
16
26
|
type ModerationPreferences,
|
|
17
27
|
} from '@atcute/bluesky-moderation';
|
|
18
28
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const labelerDids = new Set<At.Did>([
|
|
23
|
-
// Bluesky moderation service
|
|
24
|
-
'did:plc:ar7c4by46qjdydhdevvrndac',
|
|
25
|
-
]);
|
|
26
|
-
|
|
27
|
-
const modPrefs: ModerationPreferences = {
|
|
28
|
-
adultContentEnabled: false,
|
|
29
|
-
globalLabelPrefs: {},
|
|
30
|
-
prefsByLabelers: {
|
|
31
|
-
'did:plc:ar7c4by46qjdydhdevvrndac': {
|
|
32
|
-
labelPrefs: {},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
keywordFilters: [],
|
|
36
|
-
hiddenPosts: [],
|
|
37
|
-
temporaryMutes: [],
|
|
38
|
-
};
|
|
29
|
+
// 1. set up preferences (see "loading preferences" below)
|
|
30
|
+
const prefs: ModerationPreferences = { ... };
|
|
31
|
+
const labelDefs = interpretLabelerDefinitions(labelers);
|
|
39
32
|
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
// 2. moderate content
|
|
34
|
+
const decision = moderatePost(post, {
|
|
35
|
+
viewerDid: 'did:plc:...',
|
|
36
|
+
prefs,
|
|
37
|
+
labelDefs,
|
|
38
|
+
});
|
|
42
39
|
|
|
43
|
-
|
|
40
|
+
// 3. get display restrictions for your context
|
|
41
|
+
const ui = getDisplayRestrictions(decision, DisplayContext.ContentList);
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
if (ui.filters.length > 0) {
|
|
44
|
+
// don't show this post in feeds
|
|
45
|
+
}
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
case 'app.bsky.actor.defs#adultContentPref': {
|
|
51
|
-
modPrefs.adultContentEnabled = pref.enabled;
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
case 'app.bsky.actor.defs#labelersPref': {
|
|
55
|
-
for (const labeler of pref.labelers) {
|
|
56
|
-
prefsByLabelers[labeler.did] ??= { labelPrefs: {} };
|
|
57
|
-
labelerDids.add(labeler.did);
|
|
58
|
-
}
|
|
47
|
+
if (ui.blurs.length > 0) {
|
|
48
|
+
// hide behind a content warning
|
|
59
49
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
case 'app.bsky.actor.defs#contentLabelPref': {
|
|
63
|
-
labelPrefs.push(pref);
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
case 'app.bsky.actor.defs#mutedWordsPref': {
|
|
67
|
-
modPrefs.keywordFilters = interpretMutedWordPreferences(pref);
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
case 'app.bsky.actor.defs#hiddenPostsPref': {
|
|
71
|
-
modPrefs.hiddenPosts = pref.items as At.CanonicalResourceUri[];
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
50
|
+
if (ui.noOverride) {
|
|
51
|
+
// don't allow user to reveal
|
|
75
52
|
}
|
|
53
|
+
}
|
|
76
54
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
case 'ignore': {
|
|
82
|
-
pref = LabelPreference.Ignore;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
case 'warn': {
|
|
86
|
-
pref = LabelPreference.Warn;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
case 'hide': {
|
|
90
|
-
pref = LabelPreference.Hide;
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
55
|
+
if (ui.alerts.length > 0 || ui.informs.length > 0) {
|
|
56
|
+
// show warning badges
|
|
57
|
+
}
|
|
58
|
+
```
|
|
94
59
|
|
|
95
|
-
|
|
96
|
-
globalLabelPrefs[label] = pref;
|
|
97
|
-
} else if (labelerDid in prefsByLabelers) {
|
|
98
|
-
const labelerPref = prefsByLabelers[labelerDid]!;
|
|
60
|
+
### display contexts
|
|
99
61
|
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
62
|
+
use different contexts depending on where content appears:
|
|
104
63
|
|
|
105
|
-
|
|
106
|
-
|
|
64
|
+
```ts
|
|
65
|
+
// content in feeds/lists
|
|
66
|
+
getDisplayRestrictions(decision, DisplayContext.ContentList);
|
|
107
67
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
params: {
|
|
111
|
-
dids: [...labelerDids],
|
|
112
|
-
detailed: true,
|
|
113
|
-
},
|
|
114
|
-
});
|
|
68
|
+
// content in expanded view
|
|
69
|
+
getDisplayRestrictions(decision, DisplayContext.ContentView);
|
|
115
70
|
|
|
116
|
-
|
|
117
|
-
|
|
71
|
+
// images/videos in content
|
|
72
|
+
getDisplayRestrictions(decision, DisplayContext.ContentMedia);
|
|
118
73
|
|
|
119
|
-
//
|
|
120
|
-
|
|
74
|
+
// profile in lists
|
|
75
|
+
getDisplayRestrictions(decision, DisplayContext.ProfileList);
|
|
121
76
|
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
declare const post: AppBskyFeedDefs.PostView;
|
|
77
|
+
// profile in expanded view
|
|
78
|
+
getDisplayRestrictions(decision, DisplayContext.ProfileView);
|
|
125
79
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
prefs: modPrefs,
|
|
130
|
-
});
|
|
80
|
+
// profile avatar/banner
|
|
81
|
+
getDisplayRestrictions(decision, DisplayContext.ProfileMedia);
|
|
82
|
+
```
|
|
131
83
|
|
|
132
|
-
|
|
133
|
-
{
|
|
134
|
-
const ui = getDisplayRestrictions(mod, DisplayContext.ContentList);
|
|
84
|
+
### loading preferences
|
|
135
85
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
86
|
+
```ts
|
|
87
|
+
import {
|
|
88
|
+
interpretLabelerDefinitions,
|
|
89
|
+
interpretMutedWordPreferences,
|
|
90
|
+
LabelPreference,
|
|
91
|
+
type ModerationPreferences,
|
|
92
|
+
} from '@atcute/bluesky-moderation';
|
|
139
93
|
|
|
140
|
-
|
|
141
|
-
|
|
94
|
+
// fetch user preferences
|
|
95
|
+
const { data } = await rpc.get('app.bsky.actor.getPreferences', {});
|
|
96
|
+
|
|
97
|
+
const prefs: ModerationPreferences = {
|
|
98
|
+
adultContentEnabled: false,
|
|
99
|
+
globalLabelPrefs: {},
|
|
100
|
+
prefsByLabelers: {},
|
|
101
|
+
keywordFilters: [],
|
|
102
|
+
hiddenPosts: [],
|
|
103
|
+
temporaryMutes: [],
|
|
104
|
+
};
|
|
142
105
|
|
|
143
|
-
|
|
144
|
-
|
|
106
|
+
for (const pref of data.preferences) {
|
|
107
|
+
switch (pref.$type) {
|
|
108
|
+
case 'app.bsky.actor.defs#adultContentPref':
|
|
109
|
+
prefs.adultContentEnabled = pref.enabled;
|
|
110
|
+
break;
|
|
111
|
+
|
|
112
|
+
case 'app.bsky.actor.defs#contentLabelPref':
|
|
113
|
+
// map visibility to LabelPreference
|
|
114
|
+
const labelPref =
|
|
115
|
+
pref.visibility === 'hide'
|
|
116
|
+
? LabelPreference.Hide
|
|
117
|
+
: pref.visibility === 'warn'
|
|
118
|
+
? LabelPreference.Warn
|
|
119
|
+
: LabelPreference.Ignore;
|
|
120
|
+
|
|
121
|
+
if (pref.labelerDid) {
|
|
122
|
+
prefs.prefsByLabelers[pref.labelerDid] ??= { labelPrefs: {} };
|
|
123
|
+
prefs.prefsByLabelers[pref.labelerDid].labelPrefs[pref.label] = labelPref;
|
|
124
|
+
} else {
|
|
125
|
+
prefs.globalLabelPrefs[pref.label] = labelPref;
|
|
145
126
|
}
|
|
146
|
-
|
|
127
|
+
break;
|
|
147
128
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
129
|
+
case 'app.bsky.actor.defs#mutedWordsPref':
|
|
130
|
+
prefs.keywordFilters = interpretMutedWordPreferences(pref);
|
|
131
|
+
break;
|
|
132
|
+
|
|
133
|
+
case 'app.bsky.actor.defs#hiddenPostsPref':
|
|
134
|
+
prefs.hiddenPosts = pref.items;
|
|
135
|
+
break;
|
|
151
136
|
}
|
|
137
|
+
}
|
|
152
138
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
139
|
+
// fetch labeler definitions
|
|
140
|
+
const { data: labelerData } = await rpc.get('app.bsky.labeler.getServices', {
|
|
141
|
+
params: { dids: [...labelerDids], detailed: true },
|
|
142
|
+
});
|
|
156
143
|
|
|
157
|
-
|
|
158
|
-
|
|
144
|
+
const labelDefs = interpretLabelerDefinitions(
|
|
145
|
+
labelerData.views.filter((v) => v.$type === 'app.bsky.labeler.defs#labelerViewDetailed'),
|
|
146
|
+
);
|
|
147
|
+
```
|
|
159
148
|
|
|
160
|
-
|
|
161
|
-
{
|
|
162
|
-
const ui = getDisplayRestrictions(mod, DisplayContext.ProfileMedia);
|
|
149
|
+
### moderating different content types
|
|
163
150
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
151
|
+
```ts
|
|
152
|
+
import {
|
|
153
|
+
moderateFeedGenerator,
|
|
154
|
+
moderateList,
|
|
155
|
+
moderateNotification,
|
|
156
|
+
moderatePost,
|
|
157
|
+
moderateProfile,
|
|
158
|
+
} from '@atcute/bluesky-moderation';
|
|
159
|
+
|
|
160
|
+
const postDecision = moderatePost(post, opts);
|
|
161
|
+
const profileDecision = moderateProfile(profile, opts);
|
|
162
|
+
const listDecision = moderateList(list, opts);
|
|
163
|
+
const feedDecision = moderateFeedGenerator(feed, opts);
|
|
164
|
+
const notifDecision = moderateNotification(notification, opts);
|
|
167
165
|
```
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ComAtprotoLabelDefs } from '@atcute/atproto';
|
|
2
|
+
import type { AppBskyActorDefs, AppBskyEmbedRecord, AppBskyFeedDefs, AppBskyFeedPost, AppBskyGraphDefs, AppBskyNotificationListNotifications } from '@atcute/bluesky';
|
|
3
|
+
import type { $type, Did, GenericUri, Handle, ResourceUri } from '@atcute/lexicons';
|
|
4
|
+
export declare const post: ({ text, facets, reply, embed, }: {
|
|
5
|
+
text: string;
|
|
6
|
+
facets?: AppBskyFeedPost.Main['facets'];
|
|
7
|
+
reply?: AppBskyFeedPost.ReplyRef;
|
|
8
|
+
embed?: AppBskyFeedPost.Main['embed'];
|
|
9
|
+
}) => AppBskyFeedPost.Main;
|
|
10
|
+
export declare const postView: ({ record, author, embed, replyCount, repostCount, likeCount, viewer, labels, }: {
|
|
11
|
+
record: AppBskyFeedPost.Main;
|
|
12
|
+
author: AppBskyActorDefs.ProfileViewBasic;
|
|
13
|
+
embed?: AppBskyFeedDefs.PostView['embed'];
|
|
14
|
+
replyCount?: number;
|
|
15
|
+
repostCount?: number;
|
|
16
|
+
likeCount?: number;
|
|
17
|
+
viewer?: AppBskyFeedDefs.ViewerState;
|
|
18
|
+
labels?: ComAtprotoLabelDefs.Label[];
|
|
19
|
+
}) => $type.enforce<AppBskyFeedDefs.PostView>;
|
|
20
|
+
export declare const embedRecordView: ({ record, author, labels, }: {
|
|
21
|
+
record: AppBskyFeedPost.Main;
|
|
22
|
+
author: AppBskyActorDefs.ProfileViewBasic;
|
|
23
|
+
labels?: ComAtprotoLabelDefs.Label[];
|
|
24
|
+
}) => $type.enforce<AppBskyEmbedRecord.View>;
|
|
25
|
+
export declare const profileView: ({ handle, displayName, viewer, labels, }: {
|
|
26
|
+
handle: Handle;
|
|
27
|
+
displayName?: string;
|
|
28
|
+
viewer?: AppBskyActorDefs.ViewerState;
|
|
29
|
+
labels?: ComAtprotoLabelDefs.Label[];
|
|
30
|
+
}) => $type.omit<AppBskyActorDefs.ProfileView | AppBskyActorDefs.ProfileViewBasic>;
|
|
31
|
+
export declare const actorViewerState: ({ muted, mutedByList, blockedBy, blocking, blockingByList, following, followedBy, }: {
|
|
32
|
+
muted?: boolean;
|
|
33
|
+
mutedByList?: AppBskyGraphDefs.ListViewBasic;
|
|
34
|
+
blockedBy?: boolean;
|
|
35
|
+
blocking?: ResourceUri;
|
|
36
|
+
blockingByList?: AppBskyGraphDefs.ListViewBasic;
|
|
37
|
+
following?: ResourceUri;
|
|
38
|
+
followedBy?: ResourceUri;
|
|
39
|
+
}) => AppBskyActorDefs.ViewerState;
|
|
40
|
+
export declare const listViewBasic: ({ name }: {
|
|
41
|
+
name: string;
|
|
42
|
+
}) => AppBskyGraphDefs.ListViewBasic;
|
|
43
|
+
export declare const replyNotification: ({ author, record, labels, }: {
|
|
44
|
+
record: AppBskyFeedPost.Main;
|
|
45
|
+
author: AppBskyActorDefs.ProfileView;
|
|
46
|
+
labels?: ComAtprotoLabelDefs.Label[];
|
|
47
|
+
}) => AppBskyNotificationListNotifications.Notification;
|
|
48
|
+
export declare const followNotification: ({ author, subjectDid, labels, }: {
|
|
49
|
+
author: AppBskyActorDefs.ProfileView;
|
|
50
|
+
subjectDid: string;
|
|
51
|
+
labels?: ComAtprotoLabelDefs.Label[];
|
|
52
|
+
}) => AppBskyNotificationListNotifications.Notification;
|
|
53
|
+
export declare const label: ({ val, uri, src, }: {
|
|
54
|
+
val: string;
|
|
55
|
+
uri: GenericUri;
|
|
56
|
+
src?: Did;
|
|
57
|
+
}) => ComAtprotoLabelDefs.Label;
|
|
58
|
+
//# sourceMappingURL=mock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../lib/_test-util/mock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,KAAK,EACX,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,oCAAoC,EACpC,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAIpF,eAAO,MAAM,IAAI,oCAKd;IACF,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC;IACjC,KAAK,CAAC,EAAE,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SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,cAAc,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC;IAChD,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,UAAU,CAAC,EAAE,WAAW,CAAC;CACzB,KAAG,gBAAgB,CAAC,WAUpB,CAAC;AAEF,eAAO,MAAM,aAAa,aAAc;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,KAAG,gBAAgB,CAAC,aAQ3E,CAAC;AAEF,eAAO,MAAM,iBAAiB,gCAI3B;IACF,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC;IAC7B,MAAM,EAAE,gBAAgB,CAAC,WAAW,CAAC;IACrC,MAAM,CAAC,EAAE,mBAAmB,CAAC,KAAK,EAAE,CAAC;CACrC,KAAG,oCAAoC,CAAC,YAYxC,CAAC;AAEF,eAAO,MAAM,kBAAkB,oCAI5B;IACF,MAAM,EAAE,gBAAgB,CAAC,WAAW,CAAC;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,mBAAmB,CAAC,KAAK,EAAE,CAAC;CACrC,KAAG,oCAAoC,CAAC,YAexC,CAAC;AAEF,eAAO,MAAM,KAAK,uBAIf;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,UAAU,CAAC;IAChB,GAAG,CAAC,EAAE,GAAG,CAAC;CACV,KAAG,mBAAmB,CAAC,KAOvB,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const FAKE_CID = 'bafyreiclp443lavogvhj3d2ob2cxbfuscni2k5jk7bebjzg7khl3esabwq';
|
|
2
|
+
export const post = ({ text, facets, reply, embed, }) => {
|
|
3
|
+
return {
|
|
4
|
+
$type: 'app.bsky.feed.post',
|
|
5
|
+
text,
|
|
6
|
+
facets,
|
|
7
|
+
reply,
|
|
8
|
+
embed,
|
|
9
|
+
langs: ['en'],
|
|
10
|
+
createdAt: new Date().toISOString(),
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export const postView = ({ record, author, embed, replyCount, repostCount, likeCount, viewer, labels, }) => {
|
|
14
|
+
return {
|
|
15
|
+
$type: 'app.bsky.feed.defs#postView',
|
|
16
|
+
uri: `at://${author.did}/app.bsky.feed.post/fake`,
|
|
17
|
+
cid: FAKE_CID,
|
|
18
|
+
author,
|
|
19
|
+
record,
|
|
20
|
+
embed,
|
|
21
|
+
replyCount,
|
|
22
|
+
repostCount,
|
|
23
|
+
likeCount,
|
|
24
|
+
indexedAt: new Date().toISOString(),
|
|
25
|
+
viewer,
|
|
26
|
+
labels,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export const embedRecordView = ({ record, author, labels, }) => {
|
|
30
|
+
return {
|
|
31
|
+
$type: 'app.bsky.embed.record#view',
|
|
32
|
+
record: {
|
|
33
|
+
$type: 'app.bsky.embed.record#viewRecord',
|
|
34
|
+
uri: `at://${author.did}/app.bsky.feed.post/fake`,
|
|
35
|
+
cid: FAKE_CID,
|
|
36
|
+
author,
|
|
37
|
+
value: record,
|
|
38
|
+
labels,
|
|
39
|
+
indexedAt: new Date().toISOString(),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export const profileView = ({ handle, displayName, viewer, labels, }) => {
|
|
44
|
+
return {
|
|
45
|
+
did: `did:web:${handle}`,
|
|
46
|
+
handle,
|
|
47
|
+
displayName,
|
|
48
|
+
viewer,
|
|
49
|
+
labels,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export const actorViewerState = ({ muted, mutedByList, blockedBy, blocking, blockingByList, following, followedBy, }) => {
|
|
53
|
+
return {
|
|
54
|
+
muted,
|
|
55
|
+
mutedByList,
|
|
56
|
+
blockedBy,
|
|
57
|
+
blocking,
|
|
58
|
+
blockingByList,
|
|
59
|
+
following,
|
|
60
|
+
followedBy,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
export const listViewBasic = ({ name }) => {
|
|
64
|
+
return {
|
|
65
|
+
uri: 'at://did:plc:fake/app.bsky.graph.list/fake',
|
|
66
|
+
cid: FAKE_CID,
|
|
67
|
+
name,
|
|
68
|
+
purpose: 'app.bsky.graph.defs#modlist',
|
|
69
|
+
indexedAt: new Date().toISOString(),
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export const replyNotification = ({ author, record, labels, }) => {
|
|
73
|
+
return {
|
|
74
|
+
uri: `at://${author.did}/app.bsky.feed.post/fake`,
|
|
75
|
+
cid: FAKE_CID,
|
|
76
|
+
author,
|
|
77
|
+
reason: 'reply',
|
|
78
|
+
reasonSubject: `at://${author.did}/app.bsky.feed.post/fake-parent`,
|
|
79
|
+
record,
|
|
80
|
+
isRead: false,
|
|
81
|
+
indexedAt: new Date().toISOString(),
|
|
82
|
+
labels,
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
export const followNotification = ({ author, subjectDid, labels, }) => {
|
|
86
|
+
return {
|
|
87
|
+
uri: `at://${author.did}/app.bsky.graph.follow/fake`,
|
|
88
|
+
cid: FAKE_CID,
|
|
89
|
+
author,
|
|
90
|
+
reason: 'follow',
|
|
91
|
+
record: {
|
|
92
|
+
$type: 'app.bsky.graph.follow',
|
|
93
|
+
createdAt: new Date().toISOString(),
|
|
94
|
+
subject: subjectDid,
|
|
95
|
+
},
|
|
96
|
+
isRead: false,
|
|
97
|
+
indexedAt: new Date().toISOString(),
|
|
98
|
+
labels,
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
export const label = ({ val, uri, src, }) => {
|
|
102
|
+
return {
|
|
103
|
+
src: src || 'did:plc:fake-labeler',
|
|
104
|
+
uri,
|
|
105
|
+
val,
|
|
106
|
+
cts: new Date().toISOString(),
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=mock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../../lib/_test-util/mock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AM,CAAC,GAAG,6BAA6B;QACpD,GAAG,EAAE,QAAQ;QACb,MAAM;QACN,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE;YACP,KAAK,EAAE,uBAAuB;YAC9B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,OAAO,EAAE,UAAU;SACnB;QACD,MAAM,EAAE,KAAK;QACb,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,MAAM;KACN,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EACrB,GAAG,EACH,GAAG,EACH,GAAG,GAKH,EAA6B,EAAE;IAC/B,OAAO;QACN,GAAG,EAAE,GAAG,IAAI,sBAAsB;QAClC,GAAG;QACH,GAAG;QACH,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KAC7B,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { LabelPreference, type ModerationOptions } from '../index.ts';
|
|
2
|
+
export type ModerationTestSuiteResultFlag = 'filter' | 'blur' | 'alert' | 'inform' | 'noOverride';
|
|
3
|
+
export interface ModerationTestSuiteScenario {
|
|
4
|
+
cfg: string;
|
|
5
|
+
subject: 'post' | 'profile' | 'userlist' | 'feedgen';
|
|
6
|
+
author: string;
|
|
7
|
+
quoteAuthor?: string;
|
|
8
|
+
labels: {
|
|
9
|
+
post?: string[];
|
|
10
|
+
profile?: string[];
|
|
11
|
+
account?: string[];
|
|
12
|
+
quotedPost?: string[];
|
|
13
|
+
quotedAccount?: string[];
|
|
14
|
+
};
|
|
15
|
+
behaviors: {
|
|
16
|
+
profileList?: ModerationTestSuiteResultFlag[];
|
|
17
|
+
profileView?: ModerationTestSuiteResultFlag[];
|
|
18
|
+
profileMedia?: ModerationTestSuiteResultFlag[];
|
|
19
|
+
contentList?: ModerationTestSuiteResultFlag[];
|
|
20
|
+
contentView?: ModerationTestSuiteResultFlag[];
|
|
21
|
+
contentMedia?: ModerationTestSuiteResultFlag[];
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export type SuiteUsers = Record<string, {
|
|
25
|
+
blocking: boolean;
|
|
26
|
+
blockingByList: boolean;
|
|
27
|
+
blockedBy: boolean;
|
|
28
|
+
muted: boolean;
|
|
29
|
+
mutedByList: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
export type SuiteConfigurations = Record<string, {
|
|
32
|
+
authed?: boolean;
|
|
33
|
+
adultContentEnabled?: boolean;
|
|
34
|
+
settings?: Record<string, LabelPreference>;
|
|
35
|
+
}>;
|
|
36
|
+
export type SuiteScenarios = Record<string, ModerationTestSuiteScenario>;
|
|
37
|
+
declare module 'vitest' {
|
|
38
|
+
interface Assertion<T = any> {
|
|
39
|
+
toBeModerationResult(expected?: ModerationTestSuiteResultFlag[], context?: string, stringifiedResult?: string, ignoreCause?: boolean): void;
|
|
40
|
+
}
|
|
41
|
+
interface AsymmetricMatchers {
|
|
42
|
+
toBeModerationResult(expected?: ModerationTestSuiteResultFlag[], context?: string, stringifiedResult?: string, ignoreCause?: boolean): any;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export declare class ModerationBehaviorSuiteRunner {
|
|
46
|
+
users: SuiteUsers;
|
|
47
|
+
configurations: SuiteConfigurations;
|
|
48
|
+
scenarios: SuiteScenarios;
|
|
49
|
+
constructor(users: SuiteUsers, configurations: SuiteConfigurations, scenarios: SuiteScenarios);
|
|
50
|
+
postScenario(scenario: ModerationTestSuiteScenario): import("@atcute/bluesky/types/app/feed/defs").PostView & {
|
|
51
|
+
$type: "app.bsky.feed.defs#postView";
|
|
52
|
+
};
|
|
53
|
+
profileScenario(scenario: ModerationTestSuiteScenario): import("@atcute/lexicons").$type.omit<import("@atcute/bluesky/types/app/actor/defs").ProfileView | import("@atcute/bluesky/types/app/actor/defs").ProfileViewBasic>;
|
|
54
|
+
profileView(name: string, scenarioLabels: ModerationTestSuiteScenario['labels']): import("@atcute/lexicons").$type.omit<import("@atcute/bluesky/types/app/actor/defs").ProfileView | import("@atcute/bluesky/types/app/actor/defs").ProfileViewBasic>;
|
|
55
|
+
moderationOptions(scenario: ModerationTestSuiteScenario): ModerationOptions;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=moderation-behavior.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moderation-behavior.d.ts","sourceRoot":"","sources":["../../lib/_test-util/moderation-behavior.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAA4B,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIhG,MAAM,MAAM,6BAA6B,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,YAAY,CAAC;AAElG,MAAM,WAAW,2BAA2B;IAC3C,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE;QACP,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;QACtB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;KACzB,CAAC;IACF,SAAS,EAAE;QACV,WAAW,CAAC,EAAE,6BAA6B,EAAE,CAAC;QAC9C,WAAW,CAAC,EAAE,6BAA6B,EAAE,CAAC;QAC9C,YAAY,CAAC,EAAE,6BAA6B,EAAE,CAAC;QAC/C,WAAW,CAAC,EAAE,6BAA6B,EAAE,CAAC;QAC9C,WAAW,CAAC,EAAE,6BAA6B,EAAE,CAAC;QAC9C,YAAY,CAAC,EAAE,6BAA6B,EAAE,CAAC;KAC/C,CAAC;CACF;AA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