@helyx/bot 1.5.0 → 1.5.2

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 CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.5.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Supply hosted shard workers with the purpose-derived Creator invite key instead
8
+ of requiring the application-wide data encryption key in those workers. Preserve
9
+ existing v1 invite ciphertext and fingerprints, and keep startup fail-closed
10
+ when the required scoped key is absent or invalid.
11
+
12
+ ## 1.5.1
13
+
14
+ ### Patch Changes
15
+
16
+ - Add the server-scoped `/diag` command with administrator access, one active
17
+ run per server, guarded repair passes and fresh checks before reporting fixes.
18
+ Preserve records and configuration outside the explicitly supported repairs.
19
+ - Require PostgreSQL adapter 2.4.1 or MySQL adapter 0.2.1 for the active,
20
+ non-blacklisted server lookup used by diagnostic admission checks.
21
+
3
22
  ## 1.5.0
4
23
 
5
24
  ### Minor Changes
@@ -1,6 +1,7 @@
1
1
  import { isCustomerSelectableModule } from "@helyx/module-manifest";
2
2
  const platformGlobalModuleIds = new Set([
3
3
  "helyx.management",
4
+ "helyx.diagnostics",
4
5
  "helyx.support",
5
6
  "helyx.oauth",
6
7
  "helyx.permissions",
@@ -0,0 +1,6 @@
1
+ /** Internal launch material, never the application-wide data encryption key. */
2
+ export declare const creatorInviteWorkerKeyName = "HELYX_INTERNAL_CREATOR_INVITE_KEY";
3
+ export declare function decodeCreatorInviteKey(encodedKey: string): Buffer;
4
+ /** Keep the existing v1 derivation: old ciphertext and fingerprints stay valid. */
5
+ export declare function deriveCreatorInviteKey(encodedDataEncryptionKey: string): Buffer;
6
+ //# sourceMappingURL=creator-invite-key.d.ts.map
@@ -0,0 +1,16 @@
1
+ import { createHmac } from "node:crypto";
2
+ /** Internal launch material, never the application-wide data encryption key. */
3
+ export const creatorInviteWorkerKeyName = "HELYX_INTERNAL_CREATOR_INVITE_KEY";
4
+ export function decodeCreatorInviteKey(encodedKey) {
5
+ const key = Buffer.from(encodedKey, "base64");
6
+ if (key.length !== 32)
7
+ throw new Error("Creator invites require a 32-byte encryption key");
8
+ return key;
9
+ }
10
+ /** Keep the existing v1 derivation: old ciphertext and fingerprints stay valid. */
11
+ export function deriveCreatorInviteKey(encodedDataEncryptionKey) {
12
+ return createHmac("sha256", decodeCreatorInviteKey(encodedDataEncryptionKey))
13
+ .update("helyx.creator-owned-invites.v1")
14
+ .digest();
15
+ }
16
+ //# sourceMappingURL=creator-invite-key.js.map
@@ -8,7 +8,9 @@ export declare class DiscordCreatorInviteService implements CreatorInviteService
8
8
  private readonly repository;
9
9
  private readonly services;
10
10
  private readonly module;
11
- constructor(client: Client, repository: CreatorInviteRepository, services: ServiceAccess, module: ModuleDefinition | undefined, encodedEncryptionKey: string);
11
+ constructor(client: Client, repository: CreatorInviteRepository, services: ServiceAccess, module: ModuleDefinition | undefined, encryption: string | {
12
+ inviteEncryptionKey: string;
13
+ });
12
14
  selectableRoles(input: Parameters<CreatorInviteService["selectableRoles"]>[0]): ReturnType<CreatorInviteService["selectableRoles"]>;
13
15
  create(input: Parameters<CreatorInviteService["create"]>[0]): Promise<CreatorOwnedInvite>;
14
16
  inspect(input: Parameters<CreatorInviteService["inspect"]>[0]): Promise<CreatorOwnedInvite>;
@@ -5,6 +5,7 @@ import { createCipheriv, createDecipheriv, createHmac, createHash, randomBytes,
5
5
  import { normalizeDiscordPermission } from "./interactions.js";
6
6
  import { canAccessModule } from "./premium-access.js";
7
7
  import { discordRestOptions } from "./discord-rest.js";
8
+ import { decodeCreatorInviteKey, deriveCreatorInviteKey, } from "./creator-invite-key.js";
8
9
  const MODULE_ID = "helyx.creator-connections";
9
10
  const snowflake = /^\d{17,20}$/u;
10
11
  const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
@@ -18,17 +19,17 @@ export class DiscordCreatorInviteService {
18
19
  #key;
19
20
  #rest = null;
20
21
  #cleanupCursor;
21
- constructor(client, repository, services, module, encodedEncryptionKey) {
22
+ constructor(client, repository, services, module, encryption) {
22
23
  this.client = client;
23
24
  this.repository = repository;
24
25
  this.services = services;
25
26
  this.module = module;
26
- const rootKey = Buffer.from(encodedEncryptionKey, "base64");
27
- if (rootKey.length !== 32)
28
- throw new Error("Creator invites require a 32-byte data encryption key");
29
- this.#key = createHmac("sha256", rootKey)
30
- .update("helyx.creator-owned-invites.v1")
31
- .digest();
27
+ // Unsharded runtimes derive locally; workers receive only this scoped key.
28
+ // Do not derive again in workers: existing v1 records use this exact key.
29
+ this.#key =
30
+ typeof encryption === "string"
31
+ ? deriveCreatorInviteKey(encryption)
32
+ : decodeCreatorInviteKey(encryption.inviteEncryptionKey);
32
33
  }
33
34
  async selectableRoles(input) {
34
35
  validateId(input.guildId);
@@ -8,6 +8,7 @@ export declare function installCreatorInvitePlatform(input: {
8
8
  services: ServiceAccess;
9
9
  modules: readonly ModuleDefinition[];
10
10
  encryptionKey: string | undefined;
11
+ inviteEncryptionKey?: string;
11
12
  oauthBroker?: {
12
13
  baseUrl: string;
13
14
  secret: string;
@@ -8,9 +8,12 @@ export async function installCreatorInvitePlatform(input) {
8
8
  const repository = new CreatorInviteRepository(input.database);
9
9
  if (!module && !(await repository.isInstalled()))
10
10
  return undefined;
11
- if (!input.encryptionKey)
11
+ const encryption = input.inviteEncryptionKey
12
+ ? { inviteEncryptionKey: input.inviteEncryptionKey }
13
+ : input.encryptionKey;
14
+ if (!encryption)
12
15
  throw new Error("Hosted Creator Connections invites require HELYX_DATA_ENCRYPTION_KEY");
13
- const service = new DiscordCreatorInviteService(input.client, repository, input.services, module, input.encryptionKey);
16
+ const service = new DiscordCreatorInviteService(input.client, repository, input.services, module, encryption);
14
17
  input.register(HELYX_SERVICE_NAMES.creatorInvites, service);
15
18
  if (input.oauthBroker) {
16
19
  const broker = input.oauthBroker;
@@ -0,0 +1,76 @@
1
+ import type { DatabasePool } from "@helyx/database";
2
+ import type { MysqlPool } from "@helyx/database-mysql";
3
+ import { type ModuleDefinition, type ModuleRecordService, type PermissionActor, type ServiceAccess } from "@helyx/sdk";
4
+ import { type Client } from "discord.js";
5
+ export interface DiagnosticIssue {
6
+ kind: "repairable" | "human" | "technical" | "incomplete";
7
+ message: string;
8
+ evidence?: Readonly<Record<string, unknown>>;
9
+ afterRepair?: string;
10
+ }
11
+ export interface DiagnosticProbe {
12
+ id: string;
13
+ moduleId?: string;
14
+ label: string;
15
+ inspect(this: void): Promise<DiagnosticIssue | null>;
16
+ repair?(round: 1 | 2, issue: DiagnosticIssue): Promise<"attempted" | "unchanged" | "stale">;
17
+ verify?(issue: DiagnosticIssue): Promise<boolean>;
18
+ }
19
+ export interface DiagnosticLease {
20
+ signal: AbortSignal;
21
+ assertOwned(): Promise<void>;
22
+ }
23
+ export type DiagnosticRunExclusive = (guildId: string, operation: (lease: DiagnosticLease) => Promise<void>) => Promise<boolean>;
24
+ export interface DiagnosticResources {
25
+ actor(userId: string): Promise<PermissionActor>;
26
+ message(channelId: string, messageId: string): Promise<"present" | "absent" | "unknown">;
27
+ channel(channelId: string, types: readonly string[], permissions: readonly string[]): Promise<DiagnosticIssue | null>;
28
+ role(roleId: string, managed: boolean): Promise<DiagnosticIssue | null>;
29
+ capabilities(): {
30
+ guildMembers: boolean;
31
+ messageContent: boolean;
32
+ };
33
+ guildCommands?(): Promise<{
34
+ definitionHash: string;
35
+ rootCount: number;
36
+ }>;
37
+ }
38
+ export interface DiagnosticModuleOptions {
39
+ modules: readonly ModuleDefinition[];
40
+ client?: Client;
41
+ resources?: (guildId: string) => DiagnosticResources;
42
+ runExclusive?: DiagnosticRunExclusive;
43
+ assertGuildAvailable?: (guildId: string) => Promise<void>;
44
+ listEnabledModules?: (guildId: string) => Promise<readonly {
45
+ moduleId: string;
46
+ }[]>;
47
+ commandStatus?: {
48
+ get(guildId: string): Promise<unknown>;
49
+ refresh(input: {
50
+ guildId: string;
51
+ actorUserId: string;
52
+ correlationId: string;
53
+ }): Promise<unknown>;
54
+ };
55
+ stageMilliseconds?: number;
56
+ maximumRunMilliseconds?: number;
57
+ }
58
+ export interface DiagnosticRecordEnvironment {
59
+ guildId: string;
60
+ actorUserId: string;
61
+ correlationId: string;
62
+ modules: readonly ModuleDefinition[];
63
+ records: ModuleRecordService;
64
+ services: ServiceAccess;
65
+ assertCanInspect(): Promise<void>;
66
+ assertCanMutate(moduleId: string): Promise<void>;
67
+ inspectMessage(channelId: string, messageId: string): Promise<"present" | "absent" | "unknown">;
68
+ now(): Date;
69
+ }
70
+ /** A core command, never a selectable module or a module-repair hook. */
71
+ export declare function createDiagnosticModule(options: DiagnosticModuleOptions): ModuleDefinition;
72
+ /** Reserve at most four sessions, leaving at least two pool slots for repairs. */
73
+ export declare function createPostgresDiagnosticLock(pool: DatabasePool): DiagnosticRunExclusive;
74
+ /** Reserve at most four sessions, leaving at least two pool slots for repairs. */
75
+ export declare function createMysqlDiagnosticLock(pool: MysqlPool): DiagnosticRunExclusive;
76
+ //# sourceMappingURL=diagnostic-command.d.ts.map