@helyx/module-moderation 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.
Files changed (65) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/LICENSE +725 -0
  3. package/README.md +107 -0
  4. package/dist/action-support.d.ts +48 -0
  5. package/dist/action-support.js +201 -0
  6. package/dist/case-actions.d.ts +9 -0
  7. package/dist/case-actions.js +311 -0
  8. package/dist/case-naming.d.ts +4 -0
  9. package/dist/case-naming.js +9 -0
  10. package/dist/case-repository.d.ts +29 -0
  11. package/dist/case-repository.js +199 -0
  12. package/dist/channel-actions.d.ts +3 -0
  13. package/dist/channel-actions.js +267 -0
  14. package/dist/commands.d.ts +4 -0
  15. package/dist/commands.js +309 -0
  16. package/dist/components.d.ts +15 -0
  17. package/dist/components.js +381 -0
  18. package/dist/configuration.d.ts +16 -0
  19. package/dist/configuration.js +94 -0
  20. package/dist/constants.d.ts +53 -0
  21. package/dist/constants.js +53 -0
  22. package/dist/contracts.d.ts +109 -0
  23. package/dist/contracts.js +84 -0
  24. package/dist/domain.d.ts +29 -0
  25. package/dist/domain.js +101 -0
  26. package/dist/events.d.ts +3 -0
  27. package/dist/events.js +60 -0
  28. package/dist/health.d.ts +10 -0
  29. package/dist/health.js +56 -0
  30. package/dist/index.d.ts +9 -0
  31. package/dist/index.js +92 -0
  32. package/dist/moderation-cases-resource.d.ts +14 -0
  33. package/dist/moderation-cases-resource.js +226 -0
  34. package/dist/presentation.d.ts +8 -0
  35. package/dist/presentation.js +69 -0
  36. package/dist/privacy.d.ts +8 -0
  37. package/dist/privacy.js +38 -0
  38. package/dist/provider.d.ts +4 -0
  39. package/dist/provider.js +335 -0
  40. package/dist/receipt-repository.d.ts +9 -0
  41. package/dist/receipt-repository.js +36 -0
  42. package/dist/records.d.ts +399 -0
  43. package/dist/records.js +303 -0
  44. package/dist/repository-model.d.ts +131 -0
  45. package/dist/repository-model.js +318 -0
  46. package/dist/repository.d.ts +21 -0
  47. package/dist/repository.js +41 -0
  48. package/dist/service.d.ts +75 -0
  49. package/dist/service.js +329 -0
  50. package/dist/tasks.d.ts +49 -0
  51. package/dist/tasks.js +391 -0
  52. package/dist/thread-controls.d.ts +23 -0
  53. package/dist/thread-controls.js +376 -0
  54. package/dist/thread-deletion-recovery.d.ts +13 -0
  55. package/dist/thread-deletion-recovery.js +46 -0
  56. package/dist/thread-delivery.d.ts +11 -0
  57. package/dist/thread-delivery.js +427 -0
  58. package/dist/thread-reconciliation.d.ts +24 -0
  59. package/dist/thread-reconciliation.js +181 -0
  60. package/dist/thread-repository.d.ts +16 -0
  61. package/dist/thread-repository.js +70 -0
  62. package/manifest.json +999 -0
  63. package/migrations/0001_moderation_foundation.sql +552 -0
  64. package/migrations/0002_staff_attempt_parameters.sql +27 -0
  65. package/package.json +56 -0
@@ -0,0 +1,303 @@
1
+ const caseFields = {
2
+ case_id: { type: "string" },
3
+ guild_id: { type: "string" },
4
+ case_number: { type: "number" },
5
+ operation_key: { type: "string" },
6
+ subject_user_id: { type: "string", optional: true },
7
+ actor_user_id: { type: "string", optional: true },
8
+ source: { type: "string" },
9
+ source_module_id: { type: "string" },
10
+ source_event_id: { type: "string", optional: true },
11
+ action: { type: "string" },
12
+ reason: { type: "string" },
13
+ private_note: { type: "string", optional: true },
14
+ evidence_channel_id: { type: "string", optional: true },
15
+ evidence_message_id: { type: "string", optional: true },
16
+ related_case_id: { type: "string", optional: true },
17
+ requested_duration_seconds: { type: "number", optional: true },
18
+ delete_message_seconds: { type: "number", optional: true },
19
+ demote_role_ids: { type: "json" },
20
+ observed_action_type: { type: "string", optional: true },
21
+ observed_timeout_duration_seconds: { type: "number", optional: true },
22
+ repeat_rule_id: { type: "string", optional: true },
23
+ repeat_rule_revision: { type: "number", optional: true },
24
+ repeat_configuration_revision: { type: "string", optional: true },
25
+ repeat_policy_fingerprint: { type: "string", optional: true },
26
+ repeat_window_starts_at: { type: "date", optional: true },
27
+ repeat_offence_ordinal: { type: "number", optional: true },
28
+ repeat_offence_count: { type: "number", optional: true },
29
+ open_violation_thread: { type: "boolean" },
30
+ state: { type: "string" },
31
+ safe_outcome: { type: "string", optional: true },
32
+ revision: { type: "number" },
33
+ disassociated_at: { type: "date", optional: true },
34
+ settled_at: { type: "date", optional: true },
35
+ retention_expires_at: { type: "date", optional: true },
36
+ retention_processed_at: { type: "date", optional: true },
37
+ created_at: { type: "date" },
38
+ updated_at: { type: "date" },
39
+ };
40
+ const caseFieldNames = Object.keys(caseFields);
41
+ export const moderationRecords = {
42
+ case_sequences: {
43
+ table: "moderation_case_sequences",
44
+ fields: {
45
+ guild_id: { type: "string" },
46
+ next_case_number: { type: "number" },
47
+ updated_at: { type: "date" },
48
+ },
49
+ uniqueKeys: [["guild_id"]],
50
+ readableFields: ["guild_id", "next_case_number", "updated_at"],
51
+ writableFields: ["guild_id", "next_case_number", "updated_at"],
52
+ incrementableFields: ["next_case_number"],
53
+ },
54
+ cases: {
55
+ table: "moderation_cases",
56
+ fields: caseFields,
57
+ uniqueKeys: [
58
+ ["case_id"],
59
+ ["guild_id", "case_id"],
60
+ ["guild_id", "case_number"],
61
+ ["guild_id", "source_module_id", "operation_key"],
62
+ ],
63
+ readableFields: caseFieldNames,
64
+ writableFields: caseFieldNames,
65
+ orderKeys: [["created_at", "case_id"]],
66
+ searchableFields: ["subject_user_id", "actor_user_id"],
67
+ groupableFields: ["source", "action", "state", "repeat_rule_id"],
68
+ },
69
+ case_operations: {
70
+ table: "moderation_case_operations",
71
+ fields: {
72
+ operation_id: { type: "string" },
73
+ guild_id: { type: "string" },
74
+ operation_key: { type: "string" },
75
+ case_id: { type: "string", optional: true },
76
+ operation_type: { type: "string" },
77
+ input_hash: { type: "string" },
78
+ outcome_code: { type: "string" },
79
+ outcome_revision: { type: "number", optional: true },
80
+ outcome_attempt_id: { type: "string", optional: true },
81
+ outcome_attempt_number: { type: "number", optional: true },
82
+ created_at: { type: "date" },
83
+ },
84
+ uniqueKeys: [["operation_id"], ["guild_id", "operation_key"]],
85
+ readableFields: [
86
+ "operation_id",
87
+ "guild_id",
88
+ "operation_key",
89
+ "case_id",
90
+ "operation_type",
91
+ "input_hash",
92
+ "outcome_code",
93
+ "outcome_revision",
94
+ "outcome_attempt_id",
95
+ "outcome_attempt_number",
96
+ "created_at",
97
+ ],
98
+ writableFields: [
99
+ "operation_id",
100
+ "guild_id",
101
+ "operation_key",
102
+ "case_id",
103
+ "operation_type",
104
+ "input_hash",
105
+ "outcome_code",
106
+ "outcome_revision",
107
+ "outcome_attempt_id",
108
+ "outcome_attempt_number",
109
+ "created_at",
110
+ ],
111
+ orderKeys: [["created_at", "operation_id"]],
112
+ groupableFields: ["operation_type", "outcome_code"],
113
+ },
114
+ action_attempts: {
115
+ table: "moderation_action_attempts",
116
+ fields: {
117
+ attempt_id: { type: "string" },
118
+ guild_id: { type: "string" },
119
+ case_id: { type: "string" },
120
+ operation_key: { type: "string" },
121
+ actor_user_id: { type: "string", optional: true },
122
+ attempt_number: { type: "number" },
123
+ action: { type: "string" },
124
+ reason: { type: "string" },
125
+ outcome: { type: "string" },
126
+ safe_code: { type: "string", optional: true },
127
+ removed_role_ids: { type: "json" },
128
+ requested_duration_seconds: { type: "number", optional: true },
129
+ requested_demote_role_ids: { type: "json", optional: true },
130
+ created_at: { type: "date" },
131
+ updated_at: { type: "date" },
132
+ },
133
+ uniqueKeys: [
134
+ ["attempt_id"],
135
+ ["attempt_id", "attempt_number"],
136
+ ["case_id", "attempt_number"],
137
+ ["case_id", "operation_key"],
138
+ ],
139
+ readableFields: [
140
+ "attempt_id",
141
+ "guild_id",
142
+ "case_id",
143
+ "operation_key",
144
+ "actor_user_id",
145
+ "attempt_number",
146
+ "action",
147
+ "reason",
148
+ "outcome",
149
+ "safe_code",
150
+ "removed_role_ids",
151
+ "requested_duration_seconds",
152
+ "requested_demote_role_ids",
153
+ "created_at",
154
+ "updated_at",
155
+ ],
156
+ writableFields: [
157
+ "attempt_id",
158
+ "guild_id",
159
+ "case_id",
160
+ "operation_key",
161
+ "actor_user_id",
162
+ "attempt_number",
163
+ "action",
164
+ "reason",
165
+ "outcome",
166
+ "safe_code",
167
+ "removed_role_ids",
168
+ "requested_duration_seconds",
169
+ "requested_demote_role_ids",
170
+ "created_at",
171
+ "updated_at",
172
+ ],
173
+ orderKeys: [["created_at", "attempt_id"]],
174
+ groupableFields: ["action", "outcome"],
175
+ },
176
+ dm_receipts: {
177
+ table: "moderation_dm_receipts",
178
+ fields: {
179
+ receipt_id: { type: "string" },
180
+ guild_id: { type: "string" },
181
+ case_id: { type: "string" },
182
+ template_revision: { type: "number" },
183
+ delivery_state: { type: "string" },
184
+ safe_code: { type: "string", optional: true },
185
+ message_id: { type: "string", optional: true },
186
+ attempted_at: { type: "date", optional: true },
187
+ created_at: { type: "date" },
188
+ updated_at: { type: "date" },
189
+ },
190
+ uniqueKeys: [["receipt_id"], ["guild_id", "case_id"]],
191
+ readableFields: [
192
+ "receipt_id",
193
+ "guild_id",
194
+ "case_id",
195
+ "template_revision",
196
+ "delivery_state",
197
+ "safe_code",
198
+ "message_id",
199
+ "attempted_at",
200
+ "created_at",
201
+ "updated_at",
202
+ ],
203
+ writableFields: [
204
+ "receipt_id",
205
+ "guild_id",
206
+ "case_id",
207
+ "template_revision",
208
+ "delivery_state",
209
+ "safe_code",
210
+ "message_id",
211
+ "attempted_at",
212
+ "created_at",
213
+ "updated_at",
214
+ ],
215
+ orderKeys: [["created_at", "receipt_id"]],
216
+ groupableFields: ["delivery_state"],
217
+ },
218
+ thread_deliveries: {
219
+ table: "moderation_thread_deliveries",
220
+ fields: {
221
+ delivery_id: { type: "string" },
222
+ guild_id: { type: "string" },
223
+ case_id: { type: "string" },
224
+ case_revision: { type: "number" },
225
+ operation_key: { type: "string" },
226
+ parent_channel_id: { type: "string", optional: true },
227
+ access_role_id: { type: "string", optional: true },
228
+ thread_id: { type: "string", optional: true },
229
+ control_token: { type: "string", optional: true },
230
+ control_message_id: { type: "string", optional: true },
231
+ member_state: { type: "string" },
232
+ evidence_state: { type: "string" },
233
+ opening_state: { type: "string" },
234
+ notification_state: { type: "string" },
235
+ close_state: { type: "string" },
236
+ resolution_state: { type: "string" },
237
+ attempt_count: { type: "number" },
238
+ fence_token: { type: "number" },
239
+ safe_code: { type: "string", optional: true },
240
+ retry_at: { type: "date", optional: true },
241
+ created_at: { type: "date" },
242
+ updated_at: { type: "date" },
243
+ },
244
+ uniqueKeys: [
245
+ ["delivery_id"],
246
+ ["guild_id", "case_id"],
247
+ ["guild_id", "operation_key"],
248
+ ["control_token"],
249
+ ],
250
+ readableFields: [
251
+ "delivery_id",
252
+ "guild_id",
253
+ "case_id",
254
+ "case_revision",
255
+ "operation_key",
256
+ "parent_channel_id",
257
+ "access_role_id",
258
+ "thread_id",
259
+ "control_token",
260
+ "control_message_id",
261
+ "member_state",
262
+ "evidence_state",
263
+ "opening_state",
264
+ "notification_state",
265
+ "close_state",
266
+ "resolution_state",
267
+ "attempt_count",
268
+ "fence_token",
269
+ "safe_code",
270
+ "retry_at",
271
+ "created_at",
272
+ "updated_at",
273
+ ],
274
+ writableFields: [
275
+ "delivery_id",
276
+ "guild_id",
277
+ "case_id",
278
+ "case_revision",
279
+ "operation_key",
280
+ "parent_channel_id",
281
+ "access_role_id",
282
+ "thread_id",
283
+ "control_token",
284
+ "control_message_id",
285
+ "member_state",
286
+ "evidence_state",
287
+ "opening_state",
288
+ "notification_state",
289
+ "close_state",
290
+ "resolution_state",
291
+ "attempt_count",
292
+ "fence_token",
293
+ "safe_code",
294
+ "retry_at",
295
+ "created_at",
296
+ "updated_at",
297
+ ],
298
+ orderKeys: [["updated_at", "delivery_id"]],
299
+ searchableFields: ["thread_id", "control_token"],
300
+ groupableFields: ["resolution_state", "close_state"],
301
+ },
302
+ };
303
+ //# sourceMappingURL=records.js.map
@@ -0,0 +1,131 @@
1
+ import type { ModuleRecordValue, ModuleRecordWriteValue } from "@helyx/sdk";
2
+ import type { ModerationAttemptOutcome, ModerationCaseAction, ModerationCaseSource, ModerationCaseState, ModerationDeliveryState } from "./contracts.js";
3
+ export interface StoredModerationCase {
4
+ caseId: string;
5
+ guildId: string;
6
+ caseNumber: number;
7
+ operationKey: string;
8
+ subjectUserId: string | null;
9
+ actorUserId: string | null;
10
+ source: ModerationCaseSource;
11
+ sourceModuleId: string;
12
+ sourceEventId: string | null;
13
+ action: ModerationCaseAction;
14
+ reason: string;
15
+ privateNote: string | null;
16
+ evidenceChannelId: string | null;
17
+ evidenceMessageId: string | null;
18
+ relatedCaseId: string | null;
19
+ requestedDurationSeconds: number | null;
20
+ deleteMessageSeconds: number | null;
21
+ demoteRoleIds: readonly string[];
22
+ observedActionType: string | null;
23
+ observedTimeoutDurationSeconds: number | null;
24
+ repeatRuleId: string | null;
25
+ repeatRuleRevision: number | null;
26
+ repeatConfigurationRevision: string | null;
27
+ repeatPolicyFingerprint: string | null;
28
+ repeatWindowStartsAt: Date | null;
29
+ repeatOffenceOrdinal: 1 | 2 | 3 | null;
30
+ repeatOffenceCount: number | null;
31
+ openViolationThread: boolean;
32
+ state: ModerationCaseState;
33
+ safeOutcome: string | null;
34
+ revision: number;
35
+ disassociatedAt: Date | null;
36
+ settledAt: Date | null;
37
+ retentionExpiresAt: Date | null;
38
+ retentionProcessedAt: Date | null;
39
+ createdAt: Date;
40
+ updatedAt: Date;
41
+ }
42
+ export interface StoredModerationAttempt {
43
+ attemptId: string;
44
+ guildId: string;
45
+ caseId: string;
46
+ operationKey: string;
47
+ actorUserId: string | null;
48
+ attemptNumber: number;
49
+ action: ModerationCaseAction;
50
+ reason: string;
51
+ outcome: ModerationAttemptOutcome;
52
+ safeCode: string | null;
53
+ removedRoleIds: readonly string[];
54
+ requestedDurationSeconds?: number | null;
55
+ demoteRoleIds?: readonly string[];
56
+ createdAt: Date;
57
+ updatedAt: Date;
58
+ }
59
+ export interface StoredModerationDmReceipt {
60
+ receiptId: string;
61
+ guildId: string;
62
+ caseId: string;
63
+ templateRevision: number;
64
+ deliveryState: ModerationDeliveryState;
65
+ safeCode: string | null;
66
+ messageId: string | null;
67
+ attemptedAt: Date | null;
68
+ createdAt: Date;
69
+ updatedAt: Date;
70
+ }
71
+ export interface StoredModerationThreadDelivery {
72
+ deliveryId: string;
73
+ guildId: string;
74
+ caseId: string;
75
+ caseRevision: number;
76
+ operationKey: string;
77
+ parentChannelId: string | null;
78
+ accessRoleId: string | null;
79
+ threadId: string | null;
80
+ controlToken: string | null;
81
+ controlMessageId: string | null;
82
+ memberState: ModerationDeliveryState;
83
+ evidenceState: ModerationDeliveryState;
84
+ openingState: ModerationDeliveryState;
85
+ notificationState: ModerationDeliveryState;
86
+ closeState: ModerationDeliveryState;
87
+ resolutionState: "awaiting_staff" | "resolved" | "closed";
88
+ attemptCount: number;
89
+ fenceToken: number;
90
+ safeCode: string | null;
91
+ retryAt: Date | null;
92
+ createdAt: Date;
93
+ updatedAt: Date;
94
+ }
95
+ export declare const CASE_FIELDS: readonly ["case_id", "guild_id", "case_number", "operation_key", "subject_user_id", "actor_user_id", "source", "source_module_id", "source_event_id", "action", "reason", "private_note", "evidence_channel_id", "evidence_message_id", "related_case_id", "requested_duration_seconds", "delete_message_seconds", "demote_role_ids", "observed_action_type", "observed_timeout_duration_seconds", "repeat_rule_id", "repeat_rule_revision", "repeat_configuration_revision", "repeat_policy_fingerprint", "repeat_window_starts_at", "repeat_offence_ordinal", "repeat_offence_count", "open_violation_thread", "state", "safe_outcome", "revision", "disassociated_at", "settled_at", "retention_expires_at", "retention_processed_at", "created_at", "updated_at"];
96
+ export declare const ATTEMPT_FIELDS: readonly ["attempt_id", "guild_id", "case_id", "operation_key", "actor_user_id", "attempt_number", "action", "reason", "outcome", "safe_code", "removed_role_ids", "requested_duration_seconds", "requested_demote_role_ids", "created_at", "updated_at"];
97
+ export declare const DM_RECEIPT_FIELDS: readonly ["receipt_id", "guild_id", "case_id", "template_revision", "delivery_state", "safe_code", "message_id", "attempted_at", "created_at", "updated_at"];
98
+ export declare const THREAD_FIELDS: readonly ["delivery_id", "guild_id", "case_id", "case_revision", "operation_key", "parent_channel_id", "access_role_id", "thread_id", "control_token", "control_message_id", "member_state", "evidence_state", "opening_state", "notification_state", "close_state", "resolution_state", "attempt_count", "fence_token", "safe_code", "retry_at", "created_at", "updated_at"];
99
+ export declare function mapCase(row: Readonly<Record<string, ModuleRecordValue>>): StoredModerationCase;
100
+ export declare function mapAttempt(row: Readonly<Record<string, ModuleRecordValue>>): StoredModerationAttempt;
101
+ export declare function mapDmReceipt(row: Readonly<Record<string, ModuleRecordValue>>): StoredModerationDmReceipt;
102
+ export declare function mapThreadDelivery(row: Readonly<Record<string, ModuleRecordValue>>): StoredModerationThreadDelivery;
103
+ export declare function dmReceiptWrite(input: StoredModerationDmReceipt): {
104
+ values: Record<string, ModuleRecordWriteValue>;
105
+ clear: string[];
106
+ };
107
+ export declare function threadDeliveryWrite(input: StoredModerationThreadDelivery): {
108
+ values: Record<string, ModuleRecordWriteValue>;
109
+ clear: string[];
110
+ };
111
+ export declare const THREAD_PROPERTY_FIELDS: {
112
+ readonly caseRevision: "case_revision";
113
+ readonly operationKey: "operation_key";
114
+ readonly parentChannelId: "parent_channel_id";
115
+ readonly accessRoleId: "access_role_id";
116
+ readonly threadId: "thread_id";
117
+ readonly controlToken: "control_token";
118
+ readonly controlMessageId: "control_message_id";
119
+ readonly memberState: "member_state";
120
+ readonly evidenceState: "evidence_state";
121
+ readonly openingState: "opening_state";
122
+ readonly notificationState: "notification_state";
123
+ readonly closeState: "close_state";
124
+ readonly resolutionState: "resolution_state";
125
+ readonly attemptCount: "attempt_count";
126
+ readonly fenceToken: "fence_token";
127
+ readonly safeCode: "safe_code";
128
+ readonly retryAt: "retry_at";
129
+ readonly updatedAt: "updated_at";
130
+ };
131
+ //# sourceMappingURL=repository-model.d.ts.map