@helyx/bot 1.3.1 → 1.5.0

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 (97) hide show
  1. package/CHANGELOG.md +100 -28
  2. package/README.md +65 -11
  3. package/dist/channel-audit-configuration.d.ts +7 -0
  4. package/dist/channel-audit-configuration.js +40 -0
  5. package/dist/channel-audit-control.d.ts +14 -0
  6. package/dist/channel-audit-control.js +61 -0
  7. package/dist/channel-audit-permissions.d.ts +56 -0
  8. package/dist/channel-audit-permissions.js +417 -0
  9. package/dist/channel-audit-routes.d.ts +4 -0
  10. package/dist/channel-audit-routes.js +42 -0
  11. package/dist/cloud-connector.d.ts +11 -4
  12. package/dist/cloud-connector.js +54 -15
  13. package/dist/cloud-control-dispatcher.d.ts +8 -3
  14. package/dist/cloud-control-dispatcher.js +84 -4
  15. package/dist/control-errors.d.ts +12 -0
  16. package/dist/control-errors.js +32 -0
  17. package/dist/control-server-schemas.d.ts +84 -0
  18. package/dist/control-server-schemas.js +101 -0
  19. package/dist/control-server.d.ts +25 -8
  20. package/dist/control-server.js +101 -152
  21. package/dist/core-retention.d.ts +26 -0
  22. package/dist/core-retention.js +49 -0
  23. package/dist/creator-guild-join-service.d.ts +25 -0
  24. package/dist/creator-guild-join-service.js +218 -0
  25. package/dist/creator-invite-service.d.ts +37 -0
  26. package/dist/creator-invite-service.js +686 -0
  27. package/dist/creator-onboarding-control.d.ts +12 -0
  28. package/dist/creator-onboarding-control.js +65 -0
  29. package/dist/creator-onboarding-platform.d.ts +20 -0
  30. package/dist/creator-onboarding-platform.js +58 -0
  31. package/dist/dashboard-action-control.d.ts +2 -2
  32. package/dist/dashboard-action-control.js +2 -3
  33. package/dist/database-bootstrap.d.ts +36 -0
  34. package/dist/database-bootstrap.js +101 -0
  35. package/dist/developer-operations-module.d.ts +1 -0
  36. package/dist/developer-operations-module.js +34 -16
  37. package/dist/discord-channel-audit.d.ts +9 -0
  38. package/dist/discord-channel-audit.js +195 -0
  39. package/dist/discord-guild-health.d.ts +2 -2
  40. package/dist/discord-owned-message-service.d.ts +1 -0
  41. package/dist/discord-owned-message-service.js +3 -0
  42. package/dist/discord-role-safety.d.ts +4 -0
  43. package/dist/discord-role-safety.js +30 -0
  44. package/dist/events.d.ts +2 -0
  45. package/dist/events.js +5 -20
  46. package/dist/guild-command-read-service.d.ts +8 -3
  47. package/dist/guild-command-read-service.js +14 -7
  48. package/dist/guild-command-release.d.ts +15 -8
  49. package/dist/guild-command-release.js +10 -3
  50. package/dist/guild-command-worker.d.ts +17 -4
  51. package/dist/guild-command-worker.js +17 -6
  52. package/dist/guilds.d.ts +24 -3
  53. package/dist/guilds.js +185 -64
  54. package/dist/hosted-server-moderation.js +10 -4
  55. package/dist/index.d.ts +1 -0
  56. package/dist/index.js +200 -82
  57. package/dist/interactions.js +16 -3
  58. package/dist/module-configuration.d.ts +1 -1
  59. package/dist/module-configuration.js +5 -2
  60. package/dist/module-logging.d.ts +8 -3
  61. package/dist/module-logging.js +13 -7
  62. package/dist/modules.d.ts +1 -0
  63. package/dist/modules.js +8 -1
  64. package/dist/mysql-runtime-persistence.d.ts +46 -0
  65. package/dist/mysql-runtime-persistence.js +91 -0
  66. package/dist/oauth-module.js +2 -2
  67. package/dist/oauth-service.d.ts +7 -0
  68. package/dist/oauth-service.js +3 -0
  69. package/dist/scheduled-task-runner.d.ts +9 -85
  70. package/dist/scheduled-task-runner.js +1 -1
  71. package/dist/shard-contracts.d.ts +222 -0
  72. package/dist/shard-contracts.js +52 -1
  73. package/dist/shard-router.d.ts +4 -1
  74. package/dist/shard-router.js +19 -0
  75. package/dist/shard-supervisor.js +43 -9
  76. package/dist/shard-worker.d.ts +5 -2
  77. package/dist/shard-worker.js +41 -5
  78. package/dist/supervisor-cloud-directory.d.ts +9 -3
  79. package/dist/supervisor-cloud-directory.js +8 -12
  80. package/dist/trivia-data-provider.d.ts +11 -0
  81. package/dist/trivia-data-provider.js +46 -26
  82. package/dist/verification-service.d.ts +2 -2
  83. package/dist/verification-service.js +6 -3
  84. package/documentation/README.md +5 -3
  85. package/documentation/examples/.env.example +15 -11
  86. package/documentation/guides/getting-started.md +29 -12
  87. package/documentation/guides/privacy-and-support.md +6 -5
  88. package/documentation/guides/self-hosting.md +16 -11
  89. package/documentation/modules/auto-moderation.md +7 -5
  90. package/documentation/modules/building-a-module.md +48 -2
  91. package/documentation/modules/moderation.md +5 -5
  92. package/documentation/modules/publishing-a-module.md +6 -4
  93. package/documentation/modules/testing-a-module.md +39 -4
  94. package/documentation/reference/environment.md +43 -9
  95. package/documentation/runbooks/backup-and-recovery.md +26 -7
  96. package/documentation/runbooks/installation-and-upgrades.md +97 -27
  97. package/package.json +20 -16
package/CHANGELOG.md CHANGED
@@ -1,5 +1,102 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7034a9c: Add bounded read-only Channel audit contracts and Discord inspection for Access
8
+ Control and hosted Verification. The dashboard can explicitly load a narrow
9
+ channel/role configuration projection and inspect combined role assumptions
10
+ without enabling the module, changing Discord or saving audit results.
11
+
12
+ Cloud Connect uses two explicit negotiated read capabilities for Access Control.
13
+ Update the hosted API/gateway and self-hosted bot as a coordinated compatible
14
+ release; older connectors give an explicit unsupported response. No database
15
+ migration is required. This changeset records future package impact only;
16
+ versions and publication remain separately controlled.
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [7034a9c]
21
+ - @helyx/sdk@0.16.0
22
+ - @helyx/control-protocol@0.8.0
23
+ - @helyx/module-automod@1.1.1
24
+ - @helyx/module-moderation@1.1.1
25
+
26
+ ## 1.4.0
27
+
28
+ ### Minor Changes
29
+
30
+ - Report Discord readiness to owned-message cleanup so module startup cannot consume recovery attempts before bot login.
31
+
32
+ - Drain active guild tracking and owner observations before closing Discord and
33
+ database resources; stop scheduling new reconciliation work during shutdown.
34
+
35
+ - Prepare the coordinated Phase 8 minor release and align internal package dependencies. Existing deployment and database-support restrictions are unchanged.
36
+
37
+ Support checksum-only PostgreSQL startup inspection after a dedicated hosted
38
+ migration job, while preserving automatic migrations as the default and for
39
+ every Self-Hosted database.
40
+
41
+ Keep Server Health report links inside the current Cloud Connect installation for self-hosted bots. Hosted report links retain their existing route.
42
+
43
+ Keep hosted leave workers out of self-hosted runtimes and fence revoked
44
+ blacklist deliveries before a Discord leave. Preserve stopped delivery evidence
45
+ for review without changing independent leave requests.
46
+
47
+ Correct the generated starter's Cloud Connect command and document explicit server-command allowlists, required Discord intents, database TLS modes and the one-database Cloud Connect topology without changing runtime defaults.
48
+
49
+ Leave worker-owned server command collections intact when command writes are
50
+ disabled, including unsharded and sharded startup. Do not replace active module
51
+ commands with the internal developer root during a restart.
52
+ Keep public creator-page validation read-only rather than competing with the
53
+ invite cleanup/create/revoke lock; recheck active ownership before returning.
54
+
55
+ ### Patch Changes
56
+
57
+ - Patch Fastify to5.12.7 before publication. Keep the reviewed Phase8 minor
58
+ version and existing Discord/Undici transport compatibility unchanged.
59
+
60
+ - Updated dependencies
61
+ - @helyx/config@1.4.0
62
+ - @helyx/control-protocol@0.7.0
63
+ - @helyx/core@0.2.0
64
+ - @helyx/database-contracts@0.2.0
65
+ - @helyx/database-mysql@0.2.0
66
+ - @helyx/database@2.4.0
67
+ - @helyx/framework@0.2.0
68
+ - @helyx/module-automod@1.1.0
69
+ - @helyx/module-manifest@0.13.0
70
+ - @helyx/module-moderation@1.1.0
71
+ - @helyx/platform@1.3.0
72
+ - @helyx/sdk@0.15.0
73
+ - @helyx/status-client@0.3.0
74
+ - @helyx/verification-contracts@0.4.0
75
+
76
+ ## 1.3.3
77
+
78
+ ### Patch Changes
79
+
80
+ - Updated dependencies
81
+ - @helyx/control-protocol@0.6.0
82
+
83
+ ## 1.3.2
84
+
85
+ ### Patch Changes
86
+
87
+ - Support deferred source-message updates for modal submissions so poll draft
88
+ edits replace their previous controls instead of creating duplicate messages.
89
+ - Move the complete installed feature-module list to `/dev modules` and show
90
+ compact names and versions for modules and `/dev bot` core functions.
91
+ - Bound internal dependencies to compatible releases while preserving required
92
+ minimum API versions.
93
+ - Forward the hosted moderation control credential to shard workers only when
94
+ hosted moderation is enabled, preserving the existing worker credential boundary.
95
+ - Forward the explicit database-engine selection to shard workers while
96
+ preserving PostgreSQL as the default.
97
+ - Update the HTTP client to 6.29.0 to include the current WebSocket and retry
98
+ interceptor security fixes.
99
+
3
100
  ## 1.3.1
4
101
 
5
102
  ### Patch Changes
@@ -435,34 +532,9 @@
435
532
 
436
533
  ### Patch Changes
437
534
 
438
- - Reuse active Verification links when available, report their expiry, and allow members to replace them while atomically invalidating the old request.---
439
- "@helyx/bot": patch
440
- "@helyx/database": patch
441
- "@helyx/sdk": patch
442
- "@helyx/verification-contracts": patch
443
- ---
444
-
445
- Reuse active Verification links when available, report their expiry, and allow members to replace them while atomically invalidating the old request.
446
-
447
- - Accept compatible internal Helyx releases within explicit minor-safe pre-1.0 or major-safe stable ranges, preventing dependency-only patch cascades.---
448
- "@helyx/bot": patch
449
- "@helyx/cli": patch
450
- "@helyx/core": patch
451
- "@helyx/framework": patch
452
- "@helyx/platform": patch
453
- "@helyx/sdk": patch
454
- "@helyx/module-account-gate": patch
455
- "@helyx/module-feedback": patch
456
- "@helyx/module-giveaways": patch
457
- "@helyx/module-levels": patch
458
- "@helyx/module-logging": patch
459
- "@helyx/module-polls": patch
460
- "@helyx/module-reactionroles": patch
461
- "@helyx/module-suggestions": patch
462
- "@helyx/module-welcome": patch
463
- ---
464
-
465
- Accept compatible internal Helyx releases within explicit minor-safe pre-1.0 or major-safe stable ranges, preventing dependency-only patch cascades.
535
+ - Reuse active Verification links when available, report their expiry, and allow members to replace them while atomically invalidating the old request.
536
+
537
+ - Accept compatible internal Helyx releases within explicit minor-safe pre-1.0 or major-safe stable ranges, preventing dependency-only patch cascades.
466
538
 
467
539
  ## 0.4.23
468
540
 
package/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Helyx bot
2
2
 
3
- The Helyx Discord runtime validates its environment, verifies and migrates PostgreSQL, validates explicitly configured module packages, applies their migrations, composes platform services, synchronises guild installations and commands, logs in with the non-privileged Guilds intent, and shuts down Discord, modules, and PostgreSQL safely.
3
+ The Helyx Discord runtime validates its environment and explicitly configured
4
+ module packages, loads the selected database adapter, prepares core and module
5
+ migrations, composes platform services, synchronises installations and commands,
6
+ and connects to Discord. Shutdown closes modules, Discord and database resources.
7
+ Hosted services use PostgreSQL; Self-Hosted bots support PostgreSQL or a
8
+ capability-compatible MySQL database with matching module support.
4
9
 
5
10
  Version-matched public guides, operator runbooks, environment reference
6
11
  material, and module-authoring instructions ship at `documentation/README.md`
@@ -21,7 +26,14 @@ for production and self-hosted deployments during migration. Use
21
26
  that mode startup publishes only platform globals and migrated customer
22
27
  commands come from each guild's command profile and enabled module state.
23
28
 
24
- The built-in global `/helyx` and `/permissions` commands are core infrastructure. `/helyx` gives server owners, administrators and members with Manage Server permission an ephemeral module-management flow. It lists installed feature packages, enables or disables them, stages schema-defined settings, uses native Discord channel and role selectors, validates the complete configuration, and saves through the same versioned configuration and audit services as the dashboard. Dependency rules prevent a required module being disabled or a dependent module being enabled out of order.
29
+ The built-in global `/helyx` and `/permissions` commands are core infrastructure.
30
+ `/helyx modules` gives server owners, administrators and members with Manage
31
+ Server permission an ephemeral module-management flow. It lists installed
32
+ feature packages, enables or disables them, stages schema-defined settings,
33
+ uses native Discord channel and role selectors, validates the complete
34
+ configuration, and saves through the same versioned configuration and audit
35
+ services as the dashboard. Dependency rules prevent a required module being
36
+ disabled or a dependent module being enabled out of order.
25
37
 
26
38
  `/permissions` uses an owner/administrator-protected select and modal flow with native Discord selectors to manage inherited module policies and command overrides. Feature packages require an explicit allowlist: hosted distributions carry a reviewed `hosted-modules.json` catalogue, generated self-host projects use `HELYX_MODULE_CATALOGUE_PATH`, and `HELYX_MODULE_PACKAGES` remains an intentional comma-separated override. The sources are merged and de-duplicated. A core distribution has no catalogue and runs core-only when both self-host selectors are empty.
27
39
 
@@ -32,7 +44,19 @@ to `/helyx` or the dashboard. In platform-only mode, migrated commands are
32
44
  included in a guild only when its command profile selects them. Package
33
45
  upgrades preserve each server's existing enabled or disabled state.
34
46
 
35
- Gateway intents are derived from installed event contributions. The bot always requests Guilds, adds non-privileged reaction access only for reaction modules, and adds the privileged Server Members intent only when an installed module handles member joins. Deployments containing such a module must enable the matching intent in the Discord Developer Portal before startup.
47
+ Gateway intents are derived from installed contributions and explicit runtime
48
+ settings. The bot always requests Guilds and adds the reaction, message, voice
49
+ and Auto Moderation intents required by the loaded modules. Server Members is
50
+ requested when member events/capabilities require it or
51
+ `HELYX_GUILD_MEMBERS_ENABLED=true`; enable the matching privileged intent in the
52
+ Discord Developer Portal before login. Set that flag when a selected workflow
53
+ requires Helyx to advertise the Guild Members capability as available.
54
+
55
+ Message Content requires `HELYX_MESSAGE_CONTENT_ENABLED=true` as well as the
56
+ Developer Portal intent and a loaded contribution that needs it. Self-Hosted
57
+ Enhanced Auto Moderation uses this local capability; Hosted Enhanced scanning
58
+ uses the separately operated Ecko adapter. Match intents to the selected
59
+ features rather than enabling every privileged intent.
36
60
 
37
61
  Moderation integrations use closed, versioned service contracts for native
38
62
  Discord Auto Moderation rules, member and message enforcement, restricted
@@ -51,7 +75,16 @@ results before they cross the control boundary.
51
75
 
52
76
  When `HELYX_BOT_CONTROL_SECRET` is configured, the bot also starts a private authenticated HTTP control server on `HELYX_BOT_CONTROL_PORT`. The dashboard API uses this service to obtain real Discord roles and channels and to apply validated module, configuration and permission changes. `/health` is unauthenticated. Ordinary `/v1` routes require the shared bearer secret; the narrow `/v1/ecko/*` routes instead require their dedicated rotating HMAC transport key. Keep this endpoint on a private service network and do not assign it a public domain.
53
77
 
54
- Optional Helyx Cloud Connect is a separate outbound management path for self-hosted deployments. It is disabled unless `HELYX_CLOUD_CONNECT_ENABLED=true` and requires a separate local `HELYX_DATA_ENCRYPTION_KEY`. Preserve that key across every restart and deployment. If it is lost or changed, revoke the old installation in the dashboard and use a new one-use code with `/helyx-cloud connect`; the connector stops retrying until that recovery is completed. The owner-only `/helyx-cloud` command supports connection-code enrolment, status, credential rotation, disconnection and bounded support consent. The bot never sends its Discord token, database URL or connector private key to Helyx Cloud, and local Discord operation continues when Cloud is unavailable.
78
+ Optional Helyx Cloud Connect is a separate outbound management path for
79
+ self-hosted deployments. It is disabled unless
80
+ `HELYX_CLOUD_CONNECT_ENABLED=true` and requires a stable local
81
+ `HELYX_DATA_ENCRYPTION_KEY`. Generated starters enable the connector but remain
82
+ unpaired until an authorised owner supplies a one-use code with
83
+ `/helyx cloud connect`. The `/helyx cloud` command group also supports status,
84
+ credential rotation, disconnection and bounded support consent. If the key is
85
+ lost or changed, revoke the old installation and enrol a new identity. The bot
86
+ never sends its Discord token, database URL or connector private key to Helyx
87
+ Cloud, and local Discord operation continues when Cloud is unavailable.
55
88
 
56
89
  Production Status reporting is opt-in and disabled by default. Set
57
90
  `HELYX_STATUS_ENABLED=true` only with the reviewed `HELYX_STATUS_URL`, the
@@ -65,11 +98,11 @@ Giveaways and Invite Tracking also require the existing
65
98
  checkpoints and stable invite-member fingerprints without exposing the key to
66
99
  a module. Keep it stable across deployments.
67
100
 
68
- Trivia uses questions already imported into PostgreSQL. Multiple Choice and
69
- Guess both run entirely from the saved question catalogue, and the bot runtime
70
- does not call an external trivia provider.
101
+ Trivia uses the module's migrated question catalogue in the selected database.
102
+ Multiple Choice, Guess and True or False run locally; gameplay does not call an
103
+ external trivia provider.
71
104
 
72
- The always-available guild-only `/bug` command can be used by any guild member.
105
+ The always-available guild-only `/helyx bug` command can be used by any guild member.
73
106
  Hosted deployments submit through the dedicated `HELYX_SUPPORT_SERVICE_SECRET`;
74
107
  paired self-hosted deployments use their authenticated Cloud Connect session
75
108
  and may receive a one-time link for claiming, tracking and replying to the
@@ -157,8 +190,29 @@ self-hosting is outside the first release.
157
190
  Changing the total shard count redistributes guild ownership. Treat it as a
158
191
  generation change: drain the old generation before admitting the new one and
159
192
  never run both as active owners. Shard-capable code does not authorize hosted
160
- activation. Phase 10 production activation, replica scaling, or any Railway
161
- variable change requires separate owner authorization; do not provision a new
193
+ activation. New hosted shard activation, replica scaling, or provider
194
+ configuration changes require separate owner authorization; preserve an existing
195
+ reviewed topology rather than resetting it to the new-install default. Do not provision a new
162
196
  Redis or coordinator service for sharding.
163
197
 
164
- For packaged operation use `helyx start`. `helyx migrate` applies core database migrations without Discord, and read-only `helyx doctor` verifies environment, PostgreSQL migration history, and configured package metadata.
198
+ ## Packaged operation and database checks
199
+
200
+ Generated starters install `@helyx/cli` and expose `npm run setup`,
201
+ `npm run doctor`, `npm start`, `npm run update:check` and `npm run update`.
202
+ Follow their README for Node.js, Docker or managed-host commands; the bot
203
+ package itself does not provide the `helyx` executable. Compiled npm packages
204
+ do not require a source build before normal startup.
205
+
206
+ `helyx start` applies pending core and selected-module migrations by default.
207
+ `helyx migrate` deliberately applies only core migrations without Discord.
208
+ Read-only `helyx doctor` validates environment, database connectivity, existing
209
+ core migration history and configured package metadata; it inspects module
210
+ migration history when core migrations are current. Pending migrations are
211
+ reported without applying them. Startup performs database capability probes
212
+ and the complete runtime/Discord checks that doctor does not perform.
213
+
214
+ `DATABASE_ENGINE` defaults to `postgresql`; `mysql` selects the optional adapter
215
+ and currently requires `HELYX_SHARD_MODE=off`. Changing the setting does not
216
+ convert existing data between engines. Hosted PostgreSQL deployments may use
217
+ `HELYX_DATABASE_STARTUP_MODE=inspect` after their separate approved migration
218
+ job; Self-Hosted startup keeps automatic `apply` mode.
@@ -0,0 +1,7 @@
1
+ import type { ChannelAuditConfiguration, ChannelAuditModuleId } from "@helyx/sdk";
2
+ /** Deliberate allowlist: never return provider state, answers or the saved settings object. */
3
+ export declare function channelAuditConfiguration(moduleId: ChannelAuditModuleId, configuration: {
4
+ version: number;
5
+ value: Record<string, unknown>;
6
+ } | null): ChannelAuditConfiguration;
7
+ //# sourceMappingURL=channel-audit-configuration.d.ts.map
@@ -0,0 +1,40 @@
1
+ import { CHANNEL_AUDIT_LIMITS, channelAuditConfigurationSchema, } from "@helyx/control-protocol/channel-audit";
2
+ /** Deliberate allowlist: never return provider state, answers or the saved settings object. */
3
+ export function channelAuditConfiguration(moduleId, configuration) {
4
+ const value = configuration?.value ?? {};
5
+ const mappedFields = [];
6
+ const id = (field) => {
7
+ const candidate = value[field];
8
+ if (typeof candidate !== "string" || !/^\d{17,20}$/u.test(candidate))
9
+ return null;
10
+ mappedFields.push(field);
11
+ return candidate;
12
+ };
13
+ const entryChannelId = id(moduleId === "helyx.account-gate"
14
+ ? "gateChannelId"
15
+ : "verificationChannelId");
16
+ const afterRoleId = id("verifiedRoleId");
17
+ const reviewChannelId = moduleId === "helyx.account-gate" ? id("reviewChannelId") : null;
18
+ const configuredRoles = moduleId === "helyx.account-gate" && Array.isArray(value.temporaryRoleIds)
19
+ ? [
20
+ ...new Set(value.temporaryRoleIds.filter((role) => typeof role === "string" && /^\d{17,20}$/u.test(role))),
21
+ ]
22
+ : [];
23
+ if (configuredRoles.length)
24
+ mappedFields.push("temporaryRoleIds");
25
+ const suggested = moduleId === "helyx.verification" ? id("roleToRemoveId") : null;
26
+ const beforeRoleIds = suggested
27
+ ? [suggested]
28
+ : configuredRoles.slice(0, CHANNEL_AUDIT_LIMITS.beforeRoles);
29
+ return channelAuditConfigurationSchema.parse({
30
+ moduleId,
31
+ version: configuration?.version ?? null,
32
+ entryChannelId,
33
+ beforeRoleIds,
34
+ afterRoleId,
35
+ reviewChannelId,
36
+ mappedFields,
37
+ truncated: configuredRoles.length > CHANNEL_AUDIT_LIMITS.beforeRoles,
38
+ });
39
+ }
40
+ //# sourceMappingURL=channel-audit-configuration.js.map
@@ -0,0 +1,14 @@
1
+ import { type ChannelAuditControl, type GuildAccessPolicy, type ModuleConfigurationService, type ModuleDefinition, type PermissionPolicyService, type ServiceAccess } from "@helyx/sdk";
2
+ import type { BotControlGuildResourceDirectory, BotControlRepositories } from "./control-server.js";
3
+ /** Read-only component: no action, transaction, settings-save or Discord mutation helpers. */
4
+ export declare function createChannelAuditControl(input: {
5
+ modules: ReadonlyMap<string, ModuleDefinition>;
6
+ resources: Pick<BotControlGuildResourceDirectory, "resolveActor">;
7
+ configurations: ModuleConfigurationService;
8
+ permissions: PermissionPolicyService;
9
+ services: ServiceAccess;
10
+ listModules: BotControlRepositories["installations"]["listModules"];
11
+ readGuildPolicy(guildId: string): Promise<GuildAccessPolicy>;
12
+ requireAccessible(guildId: string, moduleId: string): Promise<void>;
13
+ }): Required<ChannelAuditControl>;
14
+ //# sourceMappingURL=channel-audit-control.d.ts.map
@@ -0,0 +1,61 @@
1
+ import { canAccessGuildDashboard, canUseCommand } from "@helyx/core";
2
+ import { HELYX_SERVICE_NAMES, } from "@helyx/sdk";
3
+ import { channelAuditInputSchema, channelAuditModuleIdSchema, channelAuditReportSchema, } from "@helyx/control-protocol/channel-audit";
4
+ import { BotControlForbiddenError, BotControlNotFoundError, BotControlTransportError, } from "./control-errors.js";
5
+ import { safeVersion } from "./control-permissions.js";
6
+ import { channelAuditConfiguration } from "./channel-audit-configuration.js";
7
+ /** Read-only component: no action, transaction, settings-save or Discord mutation helpers. */
8
+ export function createChannelAuditControl(input) {
9
+ const authorize = async (context) => {
10
+ channelAuditModuleIdSchema.parse(context.moduleId);
11
+ const module = input.modules.get(context.moduleId);
12
+ if (!module)
13
+ throw new BotControlNotFoundError("Module is not installed");
14
+ if (!module.manifest.dashboard)
15
+ throw new BotControlNotFoundError("Module is not dashboard configurable");
16
+ const [actor, guildAccess, resolvedPolicy, installed] = await Promise.all([
17
+ input.resources.resolveActor(context.guildId, context.actorUserId),
18
+ input.readGuildPolicy(context.guildId),
19
+ input.permissions.getPolicy(context.guildId, context.moduleId),
20
+ input.listModules(context.guildId),
21
+ ]);
22
+ if (!canAccessGuildDashboard(actor, guildAccess) ||
23
+ !canUseCommand(actor, resolvedPolicy.policy, guildAccess))
24
+ throw new BotControlForbiddenError("You no longer have permission to inspect this module's channel setup");
25
+ if (!installed.some((item) => item.moduleId === context.moduleId))
26
+ throw new BotControlNotFoundError("This module is not installed for this server");
27
+ await input.requireAccessible(context.guildId, context.moduleId);
28
+ };
29
+ return {
30
+ readChannelAuditConfiguration: async (context) => {
31
+ await authorize(context);
32
+ const configuration = await input.configurations.get(context.guildId, context.moduleId);
33
+ return channelAuditConfiguration(context.moduleId, configuration
34
+ ? {
35
+ version: safeVersion(configuration.version),
36
+ value: configuration.value,
37
+ }
38
+ : null);
39
+ },
40
+ checkChannelAudit: async (context) => {
41
+ const assumptions = channelAuditInputSchema.parse(context.assumptions);
42
+ await authorize(context);
43
+ if (!input.services.has(HELYX_SERVICE_NAMES.discordResources))
44
+ throw new BotControlTransportError(503, "Channel audit is not supported by this bot's Discord inspection service");
45
+ const inspection = input.services.get(HELYX_SERVICE_NAMES.discordResources);
46
+ if (!inspection.inspectChannelAudit)
47
+ throw new BotControlTransportError(503, "This bot version does not support Channel audit. Update the bot before trying again.");
48
+ const report = channelAuditReportSchema.parse(await inspection.inspectChannelAudit({
49
+ guildId: context.guildId,
50
+ moduleId: context.moduleId,
51
+ assumptions,
52
+ }));
53
+ if (report.guildId !== context.guildId ||
54
+ report.moduleId !== context.moduleId ||
55
+ JSON.stringify(report.assumptions) !== JSON.stringify(assumptions))
56
+ throw new BotControlTransportError(502, "Channel audit returned a different server or module context");
57
+ return report;
58
+ },
59
+ };
60
+ }
61
+ //# sourceMappingURL=channel-audit-control.js.map
@@ -0,0 +1,56 @@
1
+ import type { ChannelAuditInput, ChannelAuditModuleId, ChannelAuditReport } from "@helyx/sdk";
2
+ export declare const AUDIT_PERMISSIONS: {
3
+ readonly Administrator: bigint;
4
+ readonly ManageGuild: bigint;
5
+ readonly ViewChannel: bigint;
6
+ readonly SendMessages: bigint;
7
+ readonly ReadMessageHistory: bigint;
8
+ readonly Connect: bigint;
9
+ readonly Speak: bigint;
10
+ readonly ManageRoles: bigint;
11
+ readonly ManageChannels: bigint;
12
+ readonly KickMembers: bigint;
13
+ readonly BanMembers: bigint;
14
+ readonly RequestToSpeak: bigint;
15
+ readonly SendMessagesInThreads: bigint;
16
+ };
17
+ export interface AuditRoleSnapshot {
18
+ id: string;
19
+ permissions: bigint;
20
+ managed: boolean;
21
+ assignable: boolean | null;
22
+ assignmentReason?: string;
23
+ assignmentPolicyReason?: string;
24
+ }
25
+ export interface AuditChannelSnapshot {
26
+ id: string;
27
+ name: string;
28
+ type: number;
29
+ obfuscated: boolean;
30
+ overwrites: Array<{
31
+ id: string;
32
+ type: number;
33
+ allow: bigint;
34
+ deny: bigint;
35
+ }>;
36
+ botPermissions: bigint | null;
37
+ }
38
+ export interface AuditGuildSnapshot {
39
+ guildId: string;
40
+ roles: AuditRoleSnapshot[];
41
+ rolesComplete: boolean;
42
+ channels: AuditChannelSnapshot[];
43
+ fetchedChannels: number;
44
+ totalChannelsKnown: boolean;
45
+ fetchLimitations: string[];
46
+ invalidSelectedChannels?: Array<{
47
+ id: string;
48
+ reason: "not_found" | "wrong_guild";
49
+ }>;
50
+ }
51
+ /** Discord's role union, everyone overwrite, then aggregate role deny/allow. */
52
+ export declare function effectiveAuditPermissions(guildId: string, roles: readonly AuditRoleSnapshot[], selectedRoleIds: readonly string[], channel: AuditChannelSnapshot): bigint | null;
53
+ /** Raw bit presence is insufficient: view/connect prerequisites gate actions. */
54
+ export declare function auditActions(permissions: bigint | null, type: number): string[];
55
+ export declare function buildChannelAuditReport(snapshot: AuditGuildSnapshot, moduleId: ChannelAuditModuleId, assumptions: ChannelAuditInput, observedAt: string): ChannelAuditReport;
56
+ //# sourceMappingURL=channel-audit-permissions.d.ts.map