@helyx/module-automod 1.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/CHANGELOG.md +30 -0
- package/LICENSE +725 -0
- package/README.md +80 -0
- package/dist/activity-resource.d.ts +3 -0
- package/dist/activity-resource.js +114 -0
- package/dist/case-link-provider.d.ts +3 -0
- package/dist/case-link-provider.js +13 -0
- package/dist/configuration.d.ts +22 -0
- package/dist/configuration.js +85 -0
- package/dist/constants.d.ts +30 -0
- package/dist/constants.js +37 -0
- package/dist/contracts.d.ts +30 -0
- package/dist/contracts.js +51 -0
- package/dist/domain.d.ts +61 -0
- package/dist/domain.js +274 -0
- package/dist/engine/canonicalisation.d.ts +9 -0
- package/dist/engine/canonicalisation.js +150 -0
- package/dist/engine/compile.d.ts +4 -0
- package/dist/engine/compile.js +169 -0
- package/dist/engine/confidence.d.ts +13 -0
- package/dist/engine/confidence.js +57 -0
- package/dist/engine/configuration-cache.d.ts +29 -0
- package/dist/engine/configuration-cache.js +115 -0
- package/dist/engine/contracts.d.ts +82 -0
- package/dist/engine/contracts.js +25 -0
- package/dist/engine/index.d.ts +11 -0
- package/dist/engine/index.js +11 -0
- package/dist/engine/matcher.d.ts +3 -0
- package/dist/engine/matcher.js +206 -0
- package/dist/engine/observations.d.ts +45 -0
- package/dist/engine/observations.js +105 -0
- package/dist/engine/operation-id.d.ts +18 -0
- package/dist/engine/operation-id.js +24 -0
- package/dist/engine/similar-message-window.d.ts +68 -0
- package/dist/engine/similar-message-window.js +259 -0
- package/dist/engine/term-import.d.ts +15 -0
- package/dist/engine/term-import.js +43 -0
- package/dist/enhanced-configuration.d.ts +16 -0
- package/dist/enhanced-configuration.js +91 -0
- package/dist/events.d.ts +4 -0
- package/dist/events.js +371 -0
- package/dist/health.d.ts +9 -0
- package/dist/health.js +45 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +141 -0
- package/dist/policy-provider.d.ts +3 -0
- package/dist/policy-provider.js +66 -0
- package/dist/publication-support.d.ts +14 -0
- package/dist/publication-support.js +69 -0
- package/dist/publication.d.ts +32 -0
- package/dist/publication.js +333 -0
- package/dist/receipt-statistics.d.ts +11 -0
- package/dist/receipt-statistics.js +58 -0
- package/dist/records.d.ts +299 -0
- package/dist/records.js +288 -0
- package/dist/repository-model.d.ts +54 -0
- package/dist/repository-model.js +132 -0
- package/dist/repository.d.ts +133 -0
- package/dist/repository.js +523 -0
- package/dist/resource-cursor.d.ts +5 -0
- package/dist/resource-cursor.js +45 -0
- package/dist/resource-presentation.d.ts +21 -0
- package/dist/resource-presentation.js +111 -0
- package/dist/resource-validation.d.ts +6 -0
- package/dist/resource-validation.js +80 -0
- package/dist/resources.d.ts +4 -0
- package/dist/resources.js +319 -0
- package/dist/scanner-configuration.d.ts +10 -0
- package/dist/scanner-configuration.js +146 -0
- package/dist/scanner-provider.d.ts +5 -0
- package/dist/scanner-provider.js +310 -0
- package/dist/scanner-result-validation.d.ts +3 -0
- package/dist/scanner-result-validation.js +61 -0
- package/dist/settings-preview.d.ts +6 -0
- package/dist/settings-preview.js +84 -0
- package/manifest.json +1601 -0
- package/migrations/0001_automod_standard.sql +114 -0
- package/migrations/0002_automod_enhanced_receipts.sql +40 -0
- package/package.json +61 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
export const RULE_FIELDS = [
|
|
2
|
+
"rule_id",
|
|
3
|
+
"guild_id",
|
|
4
|
+
"name",
|
|
5
|
+
"category",
|
|
6
|
+
"rule_kind",
|
|
7
|
+
"status",
|
|
8
|
+
"document_json",
|
|
9
|
+
"native_rule_id",
|
|
10
|
+
"native_fingerprint",
|
|
11
|
+
"operation_key",
|
|
12
|
+
"configuration_revision",
|
|
13
|
+
"revision",
|
|
14
|
+
"created_by_user_id",
|
|
15
|
+
"updated_by_user_id",
|
|
16
|
+
"created_at",
|
|
17
|
+
"updated_at",
|
|
18
|
+
];
|
|
19
|
+
export const RECEIPT_FIELDS = [
|
|
20
|
+
"receipt_id",
|
|
21
|
+
"guild_id",
|
|
22
|
+
"event_key",
|
|
23
|
+
"rule_id",
|
|
24
|
+
"rule_revision",
|
|
25
|
+
"configuration_revision",
|
|
26
|
+
"native_rule_id",
|
|
27
|
+
"source",
|
|
28
|
+
"detector_version",
|
|
29
|
+
"scoring_version",
|
|
30
|
+
"term_id",
|
|
31
|
+
"detection_method",
|
|
32
|
+
"confidence_class",
|
|
33
|
+
"confidence_score",
|
|
34
|
+
"effective_threshold",
|
|
35
|
+
"correlation_id",
|
|
36
|
+
"subject_user_id",
|
|
37
|
+
"channel_id",
|
|
38
|
+
"message_id",
|
|
39
|
+
"alert_system_message_id",
|
|
40
|
+
"action_type",
|
|
41
|
+
"claim_key",
|
|
42
|
+
"moderation_case_id",
|
|
43
|
+
"outcome",
|
|
44
|
+
"safe_code",
|
|
45
|
+
"occurred_at",
|
|
46
|
+
"created_at",
|
|
47
|
+
];
|
|
48
|
+
export function mapRule(row) {
|
|
49
|
+
return {
|
|
50
|
+
ruleId: requiredString(row.rule_id),
|
|
51
|
+
guildId: requiredString(row.guild_id),
|
|
52
|
+
name: requiredString(row.name),
|
|
53
|
+
category: requiredString(row.category),
|
|
54
|
+
kind: requiredString(row.rule_kind),
|
|
55
|
+
status: requiredString(row.status),
|
|
56
|
+
draft: storedDraft(requiredString(row.document_json)),
|
|
57
|
+
nativeRuleId: optionalString(row.native_rule_id),
|
|
58
|
+
nativeFingerprint: optionalString(row.native_fingerprint),
|
|
59
|
+
operationKey: requiredString(row.operation_key),
|
|
60
|
+
configurationRevision: requiredString(row.configuration_revision),
|
|
61
|
+
revision: requiredNumber(row.revision),
|
|
62
|
+
createdByUserId: optionalString(row.created_by_user_id),
|
|
63
|
+
updatedByUserId: optionalString(row.updated_by_user_id),
|
|
64
|
+
createdAt: requiredDate(row.created_at),
|
|
65
|
+
updatedAt: requiredDate(row.updated_at),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function storedDraft(value) {
|
|
69
|
+
const draft = JSON.parse(value);
|
|
70
|
+
return {
|
|
71
|
+
...draft,
|
|
72
|
+
enhancedNormalisedMatching: draft.enhancedNormalisedMatching !== false,
|
|
73
|
+
enhancedFuzzyMatching: draft.enhancedFuzzyMatching === true,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export function mapReceipt(row) {
|
|
77
|
+
return {
|
|
78
|
+
receiptId: requiredString(row.receipt_id),
|
|
79
|
+
guildId: requiredString(row.guild_id),
|
|
80
|
+
eventKey: requiredString(row.event_key),
|
|
81
|
+
ruleId: requiredString(row.rule_id),
|
|
82
|
+
ruleRevision: requiredNumber(row.rule_revision),
|
|
83
|
+
configurationRevision: requiredString(row.configuration_revision),
|
|
84
|
+
nativeRuleId: optionalString(row.native_rule_id),
|
|
85
|
+
source: requiredString(row.source),
|
|
86
|
+
detectorVersion: optionalString(row.detector_version),
|
|
87
|
+
scoringVersion: optionalString(row.scoring_version),
|
|
88
|
+
termId: optionalString(row.term_id),
|
|
89
|
+
detectionMethod: optionalString(row.detection_method),
|
|
90
|
+
confidenceClass: optionalString(row.confidence_class),
|
|
91
|
+
confidenceScore: optionalNumber(row.confidence_score),
|
|
92
|
+
effectiveThreshold: optionalNumber(row.effective_threshold),
|
|
93
|
+
correlationId: optionalString(row.correlation_id),
|
|
94
|
+
subjectUserId: optionalString(row.subject_user_id),
|
|
95
|
+
channelId: optionalString(row.channel_id),
|
|
96
|
+
messageId: optionalString(row.message_id),
|
|
97
|
+
alertSystemMessageId: optionalString(row.alert_system_message_id),
|
|
98
|
+
actionType: requiredString(row.action_type),
|
|
99
|
+
claimKey: requiredString(row.claim_key),
|
|
100
|
+
moderationCaseId: optionalString(row.moderation_case_id),
|
|
101
|
+
outcome: requiredString(row.outcome),
|
|
102
|
+
safeCode: optionalString(row.safe_code),
|
|
103
|
+
occurredAt: requiredDate(row.occurred_at),
|
|
104
|
+
createdAt: requiredDate(row.created_at),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function requiredString(value) {
|
|
108
|
+
if (typeof value !== "string")
|
|
109
|
+
throw new Error("Auto Moderation record is invalid.");
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
function optionalString(value) {
|
|
113
|
+
return typeof value === "string" ? value : null;
|
|
114
|
+
}
|
|
115
|
+
function optionalNumber(value) {
|
|
116
|
+
if (value === undefined || value === null)
|
|
117
|
+
return null;
|
|
118
|
+
if (typeof value !== "number")
|
|
119
|
+
throw new Error("Auto Moderation record is invalid.");
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
function requiredNumber(value) {
|
|
123
|
+
if (typeof value !== "number")
|
|
124
|
+
throw new Error("Auto Moderation record is invalid.");
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
function requiredDate(value) {
|
|
128
|
+
if (!(value instanceof Date))
|
|
129
|
+
throw new Error("Auto Moderation record is invalid.");
|
|
130
|
+
return value;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=repository-model.js.map
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { type AutoModerationEnhancedResultV1, type ModuleRecordService, type ModuleRecordWriteValue, type ServiceAccess } from "@helyx/sdk";
|
|
2
|
+
import type { AutoModerationRuleDraft, AutoModerationRuleStatus } from "./domain.js";
|
|
3
|
+
import { type StoredAutoModerationReceipt, type StoredAutoModerationRule } from "./repository-model.js";
|
|
4
|
+
export type { StoredAutoModerationReceipt, StoredAutoModerationRule, } from "./repository-model.js";
|
|
5
|
+
export declare class AutoModerationRepository {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(services: ServiceAccess | ModuleRecordService);
|
|
8
|
+
listRules(input: {
|
|
9
|
+
guildId: string;
|
|
10
|
+
limit: number;
|
|
11
|
+
cursor?: readonly ModuleRecordWriteValue[];
|
|
12
|
+
search?: string;
|
|
13
|
+
status?: string;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
items: StoredAutoModerationRule[];
|
|
16
|
+
nextCursor: readonly ModuleRecordWriteValue[] | null;
|
|
17
|
+
}>;
|
|
18
|
+
findRule(guildId: string, ruleId: string): Promise<StoredAutoModerationRule | null>;
|
|
19
|
+
findByNativeRuleId(guildId: string, nativeRuleId: string): Promise<StoredAutoModerationRule | null>;
|
|
20
|
+
listPublishedGuildIds(limit?: number): Promise<string[]>;
|
|
21
|
+
listAllPublishedRules(guildId: string): Promise<StoredAutoModerationRule[]>;
|
|
22
|
+
createDraft(input: {
|
|
23
|
+
guildId: string;
|
|
24
|
+
ruleId?: string;
|
|
25
|
+
draft: AutoModerationRuleDraft;
|
|
26
|
+
actorUserId: string;
|
|
27
|
+
occurredAt: Date;
|
|
28
|
+
}): Promise<StoredAutoModerationRule>;
|
|
29
|
+
updateRule(input: {
|
|
30
|
+
current: StoredAutoModerationRule;
|
|
31
|
+
draft?: AutoModerationRuleDraft;
|
|
32
|
+
status?: AutoModerationRuleStatus;
|
|
33
|
+
nativeRuleId?: string | null;
|
|
34
|
+
nativeFingerprint?: string | null;
|
|
35
|
+
configurationRevision?: string;
|
|
36
|
+
actorUserId: string | null;
|
|
37
|
+
action: string;
|
|
38
|
+
occurredAt: Date;
|
|
39
|
+
}): Promise<StoredAutoModerationRule | null>;
|
|
40
|
+
deleteDraft(input: {
|
|
41
|
+
current: StoredAutoModerationRule;
|
|
42
|
+
actorUserId: string;
|
|
43
|
+
}): Promise<{
|
|
44
|
+
deleted: boolean;
|
|
45
|
+
}>;
|
|
46
|
+
appendReceipt(input: {
|
|
47
|
+
guildId: string;
|
|
48
|
+
eventKey: string;
|
|
49
|
+
rule: StoredAutoModerationRule;
|
|
50
|
+
nativeRuleId: string;
|
|
51
|
+
subjectUserId: string;
|
|
52
|
+
channelId: string | null;
|
|
53
|
+
messageId: string | null;
|
|
54
|
+
alertSystemMessageId: string | null;
|
|
55
|
+
actionType: string;
|
|
56
|
+
claimKey: string;
|
|
57
|
+
occurredAt: Date;
|
|
58
|
+
}): Promise<{
|
|
59
|
+
created: boolean;
|
|
60
|
+
}>;
|
|
61
|
+
appendEnhancedReceipt(input: {
|
|
62
|
+
result: AutoModerationEnhancedResultV1;
|
|
63
|
+
rule: StoredAutoModerationRule;
|
|
64
|
+
claimKey: string;
|
|
65
|
+
occurredAt: Date;
|
|
66
|
+
}): Promise<{
|
|
67
|
+
created: boolean;
|
|
68
|
+
}>;
|
|
69
|
+
settleReceipt(input: {
|
|
70
|
+
guildId: string;
|
|
71
|
+
eventKey: string;
|
|
72
|
+
outcome: string;
|
|
73
|
+
moderationCaseId?: string;
|
|
74
|
+
safeCode?: string;
|
|
75
|
+
}): Promise<void>;
|
|
76
|
+
findReceiptByEventKey(input: {
|
|
77
|
+
guildId: string;
|
|
78
|
+
eventKey: string;
|
|
79
|
+
}): Promise<{
|
|
80
|
+
outcome: string;
|
|
81
|
+
moderationCaseId: string | null;
|
|
82
|
+
safeCode: string | null;
|
|
83
|
+
} | null>;
|
|
84
|
+
claimEnforcement(input: {
|
|
85
|
+
guildId: string;
|
|
86
|
+
claimKey: string;
|
|
87
|
+
rule: StoredAutoModerationRule;
|
|
88
|
+
subjectUserId: string;
|
|
89
|
+
channelId: string | null;
|
|
90
|
+
messageId: string | null;
|
|
91
|
+
actionFamily: string;
|
|
92
|
+
source: "native" | "enhanced";
|
|
93
|
+
requestFingerprint: string;
|
|
94
|
+
occurredAt: Date;
|
|
95
|
+
}): Promise<{
|
|
96
|
+
created: boolean;
|
|
97
|
+
conflict: boolean;
|
|
98
|
+
source: "native" | "enhanced";
|
|
99
|
+
outcome: string;
|
|
100
|
+
moderationCaseId: string | null;
|
|
101
|
+
repeatOrdinal: number | null;
|
|
102
|
+
selectedAction: string | null;
|
|
103
|
+
safeCode: string | null;
|
|
104
|
+
}>;
|
|
105
|
+
disassociateCaseLinks(input: {
|
|
106
|
+
guildId: string;
|
|
107
|
+
moderationCaseId: string;
|
|
108
|
+
}): Promise<{
|
|
109
|
+
detachedRecords: number;
|
|
110
|
+
}>;
|
|
111
|
+
settleClaim(input: {
|
|
112
|
+
guildId: string;
|
|
113
|
+
claimKey: string;
|
|
114
|
+
moderationCaseId?: string;
|
|
115
|
+
repeatOrdinal?: number;
|
|
116
|
+
selectedAction?: string;
|
|
117
|
+
outcome: string;
|
|
118
|
+
safeCode?: string;
|
|
119
|
+
occurredAt: Date;
|
|
120
|
+
}): Promise<void>;
|
|
121
|
+
listReceipts(input: {
|
|
122
|
+
guildId: string;
|
|
123
|
+
limit: number;
|
|
124
|
+
cursor?: readonly ModuleRecordWriteValue[];
|
|
125
|
+
ruleId?: string;
|
|
126
|
+
outcome?: string;
|
|
127
|
+
}): Promise<{
|
|
128
|
+
items: StoredAutoModerationReceipt[];
|
|
129
|
+
nextCursor: readonly ModuleRecordWriteValue[] | null;
|
|
130
|
+
}>;
|
|
131
|
+
findReceipt(guildId: string, receiptId: string): Promise<StoredAutoModerationReceipt | null>;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=repository.d.ts.map
|