@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,70 @@
1
+ import { MODERATION_MODULE_ID } from "./constants.js";
2
+ import { THREAD_FIELDS, THREAD_PROPERTY_FIELDS, mapThreadDelivery, threadDeliveryWrite, } from "./repository-model.js";
3
+ export class ModerationThreadRepository {
4
+ records;
5
+ constructor(records) {
6
+ this.records = records;
7
+ }
8
+ async findThreadDelivery(guildId, caseId) {
9
+ const row = await this.records.findOne({
10
+ moduleId: MODERATION_MODULE_ID,
11
+ collection: "thread_deliveries",
12
+ select: THREAD_FIELDS,
13
+ where: { guild_id: guildId, case_id: caseId },
14
+ });
15
+ return row ? mapThreadDelivery(row) : null;
16
+ }
17
+ async findThreadDeliveryByControlToken(controlToken) {
18
+ const row = await this.records.findOne({
19
+ moduleId: MODERATION_MODULE_ID,
20
+ collection: "thread_deliveries",
21
+ select: THREAD_FIELDS,
22
+ where: { control_token: controlToken },
23
+ });
24
+ return row ? mapThreadDelivery(row) : null;
25
+ }
26
+ async upsertThreadDelivery(input) {
27
+ const write = threadDeliveryWrite(input);
28
+ await this.records.upsert({
29
+ moduleId: MODERATION_MODULE_ID,
30
+ collection: "thread_deliveries",
31
+ values: write.values,
32
+ uniqueBy: ["guild_id", "case_id"],
33
+ update: THREAD_FIELDS.filter((field) => !["delivery_id", "guild_id", "case_id", "created_at"].includes(field) && Object.hasOwn(write.values, field)),
34
+ clear: write.clear,
35
+ });
36
+ }
37
+ async createThreadDelivery(input) {
38
+ const write = threadDeliveryWrite(input);
39
+ const result = await this.records.appendUnique({
40
+ moduleId: MODERATION_MODULE_ID,
41
+ collection: "thread_deliveries",
42
+ values: write.values,
43
+ uniqueBy: ["guild_id", "case_id"],
44
+ });
45
+ if (result.created)
46
+ return input;
47
+ const existing = await this.findThreadDelivery(input.guildId, input.caseId);
48
+ if (!existing)
49
+ throw new Error("thread_delivery_missing");
50
+ return existing;
51
+ }
52
+ async updateThreadDelivery(input) {
53
+ const values = {};
54
+ for (const [property, value] of Object.entries(input.values)) {
55
+ const field = THREAD_PROPERTY_FIELDS[property];
56
+ if (!field)
57
+ throw new Error("Unsupported thread delivery update.");
58
+ values[field] = value;
59
+ }
60
+ const result = await this.records.updateOne({
61
+ moduleId: MODERATION_MODULE_ID,
62
+ collection: "thread_deliveries",
63
+ where: { delivery_id: input.deliveryId },
64
+ expected: { field: "fence_token", value: input.expectedFenceToken },
65
+ values: { ...values, fence_token: input.expectedFenceToken + 1 },
66
+ });
67
+ return result.updated;
68
+ }
69
+ }
70
+ //# sourceMappingURL=thread-repository.js.map